MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / MaybeInsertAValue

Method MaybeInsertAValue

docs/test-csharp-snippets/Module.cs:33–45  ·  view source on GitHub ↗

=== Snippet 3: Fallible database operations ===

(ProcedureContext ctx, uint a, string b)

Source from the content-addressed store, hash-verified

31
32 // === Snippet 3: Fallible database operations ===
33 [SpacetimeDB.Procedure]
34 public static void MaybeInsertAValue(ProcedureContext ctx, uint a, string b)
35 {
36 ctx.WithTx(txCtx =>
37 {
38 if (a < 10)
39 {
40 throw new Exception("a is less than 10!");
41 }
42 txCtx.Db.MyTable.Insert(new MyTable { A = a, B = b });
43 return 0;
44 });
45 }
46
47 // === Snippet 4: Reading values out of the database ===
48 [SpacetimeDB.Table(Accessor = "Player")]

Callers

nothing calls this directly

Calls 2

WithTxMethod · 0.45
InsertMethod · 0.45

Tested by

no test coverage detected