mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-01-06 01:40:12 -06:00
Minor: add a record API subscription example for dotnet and clean up other dotnet examples.
This commit is contained in:
@@ -2,7 +2,7 @@ using TrailBase;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
public partial class Examples {
|
||||
public static async Task<RecordId> Create(Client client) {
|
||||
return await client.Records("simple_strict_table").Create(JsonNode.Parse("""{"text_not_null": "test"}"""));
|
||||
}
|
||||
public static async Task<RecordId> Create(Client client) =>
|
||||
await client.Records("simple_strict_table").Create(
|
||||
new JsonObject { ["text_not_null"] = "test" });
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using TrailBase;
|
||||
|
||||
public partial class Examples {
|
||||
public static async Task Delete(Client client, RecordId id) {
|
||||
public static async Task Delete(Client client, RecordId id) =>
|
||||
await client.Records("simple_strict_table").Delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,12 @@ public class ExamplesTest : IClassFixture<ExamplesTestFixture> {
|
||||
public async Task BasicTest() {
|
||||
var client = await Connect();
|
||||
|
||||
var tableStream = await Examples.SubscribeAll(client);
|
||||
|
||||
var id = await Examples.Create(client);
|
||||
|
||||
var recordStream = await Examples.Subscribe(client, id);
|
||||
|
||||
Console.WriteLine($"ID: {id}");
|
||||
|
||||
{
|
||||
@@ -41,5 +45,20 @@ public class ExamplesTest : IClassFixture<ExamplesTestFixture> {
|
||||
}
|
||||
|
||||
await Examples.Delete(client, id);
|
||||
|
||||
List<Event> events = [];
|
||||
await foreach (Event ev in recordStream) {
|
||||
events.Add(ev);
|
||||
}
|
||||
Assert.Equal(2, events.Count);
|
||||
|
||||
List<Event> tableEvents = [];
|
||||
await foreach (Event ev in tableStream) {
|
||||
tableEvents.Add(ev);
|
||||
|
||||
if (tableEvents.Count >= 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using TrailBase;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
public partial class Examples {
|
||||
public static async Task<JsonNode?> Read(Client client, RecordId id) {
|
||||
return await client.Records("simple_strict_table").Read<JsonNode>(id);
|
||||
}
|
||||
public static async Task<JsonNode?> Read(Client client, RecordId id) =>
|
||||
await client.Records("simple_strict_table").Read<JsonNode>(id);
|
||||
}
|
||||
|
||||
9
docs/examples/record_api_dotnet/Subscribe.cs
Normal file
9
docs/examples/record_api_dotnet/Subscribe.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using TrailBase;
|
||||
|
||||
public partial class Examples {
|
||||
public static async Task<IAsyncEnumerable<Event>> Subscribe(Client client, RecordId id) =>
|
||||
await client.Records("simple_strict_table").Subscribe(id);
|
||||
|
||||
public static async Task<IAsyncEnumerable<Event>> SubscribeAll(Client client) =>
|
||||
await client.Records("simple_strict_table").SubscribeAll();
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using TrailBase;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
public partial class Examples {
|
||||
public static async Task Update(Client client, RecordId id) {
|
||||
await client.Records("simple_strict_table").Update(id, JsonNode.Parse("""{"text_not_null": "updated"}"""));
|
||||
}
|
||||
public static async Task Update(Client client, RecordId id) =>
|
||||
await client.Records("simple_strict_table").Update(
|
||||
id, new JsonObject { ["text_not_null"] = "updated" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user