diff --git a/apps/docs/docs/ref/csharp/initializing.mdx b/apps/docs/docs/ref/csharp/initializing.mdx index ca29a5605a3..e9fbcca0a71 100644 --- a/apps/docs/docs/ref/csharp/initializing.mdx +++ b/apps/docs/docs/ref/csharp/initializing.mdx @@ -13,6 +13,10 @@ custom_edit_url: https://github.com/supabase/supabase/edit/master/web/spec/supab Initializing a new client is pretty straightforward. Find your project url and public key from the admin panel and pass it into your client initialization function. +`supabase-csharp` is heavily dependent on Models deriving from `BaseModel`. To interact with the API, one must have the associated model (see example) specified. + +Leverage `Table`, `PrimaryKey`, and `Column` attributes to specify names of classes/properties that are different from their C# Versions. + @@ -29,7 +33,7 @@ admin panel and pass it into your client initialization function. var options = new Supabase.SupabaseOptions { - AutoConnectRealtime = true + AutoConnectRealtime = true }; var supabase = new Supabase.Client(url, key, options); @@ -61,6 +65,57 @@ admin panel and pass it into your client initialization function. ``` + + + ```csharp + // Given the following Model representing the Supabase Database (Message.cs) + [Table("messages")] + public class Message : BaseModel + { + [PrimaryKey("id")] + public int Id { get; set; } + + [Column("username")] + public string UserName { get; set; } + + [Column("channel_id")] + public int ChannelId { get; set; } + + public override bool Equals(object obj) + { + return obj is Message message && + Id == message.Id; + } + + public override int GetHashCode() + { + return HashCode.Combine(Id); + } + } + + void Initialize() + { + // Get All Messages + var response = await client.Table().Get(); + List models = response.Models; + + // Insert + var newMessage = new Message { UserName = "acupofjose", ChannelId = 1 }; + await client.Table().Insert(); + + // Update + var model = response.Models.First(); + model.UserName = "elrhomariyounes"; + await model.Update(); + + // Delete + await response.Models.Last().Delete(); + + // etc. + } + ``` + + diff --git a/spec/supabase_csharp_v0.yml b/spec/supabase_csharp_v0.yml index 4a9209afe6b..9f2c963685b 100644 --- a/spec/supabase_csharp_v0.yml +++ b/spec/supabase_csharp_v0.yml @@ -285,6 +285,7 @@ functions: notes: | - **LINQ expressions do not currently support parsing embedded resource columns. For these cases, `string` will need to be used.** - **When using string Column Names to select, they must match names in database, not names specified on model properties.** + - Additional information on modeling + querying Joins and Inner Joins can be found [in the `postgrest-csharp README`](https://github.com/supabase-community/postgrest-csharp/blob/master/README.md#foreign-keys-join-tables-and-relationships) - By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed in Project API Settings. It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use `range()` queries to paginate through your data. - `From()` can be combined with [Modifiers](/docs/reference/csharp/using-modifiers) - `From()` can be combined with [Filters](/docs/reference/csharp/using-filters) @@ -295,6 +296,23 @@ functions: isSpotlight: true code: | ```c# + // Given the following Model (City.cs) + [Table("cities")] + class City : BaseModel + { + [PrimaryKey("id")] + public int Id { get; set; } + + [Column("name")] + public string Name { get; set; } + + [Column("country_id")] + public int CountryId { get; set; } + + //... etc. + } + + // A result can be fetched like so. var result = await supabase.From().Get(); var cities = result.Models ``` @@ -303,6 +321,23 @@ functions: description: You can select specific fields from your tables. code: | ```c# + // Given the following Model (Movie.cs) + [Table("movies")] + class Movie : BaseModel + { + [PrimaryKey("id")] + public int Id { get; set; } + + [Column("name")] + public string Name { get; set; } + + [Column("created_at")] + public DateTime CreatedAt { get; set; } + + //... etc. + } + + // A result can be fetched like so. var result = await supabase .From() .Select(x => new object[] {x.Name, x.CreatedAt})