supabase-community / postgrest-csharp

A C# Client library for Postgrest
https://supabase-community.github.io/postgrest-csharp/api/Postgrest.html
MIT License
114 stars 22 forks source link

Non-updatable Attribute #90

Closed kaushalkumar86 closed 2 months ago

kaushalkumar86 commented 2 months ago

Can you please add a Non-updatable attribute?

I have this in my code:-

[Column("created_at")] public DateTime CreatedAt { get; set; }

In Supabase database, its set as timestamp and set to now().

While doing an insert from c#, if I do not set CreatedAt or set its value to default, its set as the epoch value in database. I have to set CreatedAt value to DateTime.Now from user device (which I do not want). I want it to have server's now() time to be set automatically, which is not working if I use attribute Column. If the attribute is set to PrimaryKey (because PrimaryKey has public bool ShouldInsert { get; }, its working but further updates are not happening. Can make an Attribute which is not primarykey, but system(server) updated?

acupofjose commented 2 months ago

Could you try doing:

[Column("created_at")] public DateTime CreatedAt { internal get; set; }

The postgrest-csharp attributes themselves are just boxing the JSON.NET attributes... if that doesn't work I'll see about adding an additional attribute. Maybe [RemoteOnly] or [ReadOnly]?

kaushalkumar86 commented 2 months ago

Could you try doing:

[Column("created_at")] public DateTime CreatedAt { internal get; set; }

The postgrest-csharp attributes themselves are just boxing the JSON.NET attributes... if that doesn't work I'll see about adding an additional attribute. Maybe [RemoteOnly] or [ReadOnly]?

Its working, thanks