activa / iridium

Iridium - Lightweight .NET ORM for mobile, desktop and server applications
MIT License
22 stars 8 forks source link

Some additional attributes #12

Open TheMouster opened 6 years ago

TheMouster commented 6 years ago

I'm thinking of adding a couple of additional attributes to the project. [Column.DefaultValue(value = "getUTCdate()")], and [Trim] (Originally available in Vici.CoolStorage)

What are your thoughts on this? Are there any reasons for not doing them?

activa commented 6 years ago

The [Trim] attribute is useful, but what would the [DefaultValue] do exactly? Is this server-side or client-side? If it's server-side, it would require a read-back of the record after it's been created

TheMouster commented 6 years ago

DefaultValue is for setting default constraints on fields e.g. it's not unusual to have a date/time field in tables named WhenCreated with a default value of getUTCdate() (SQL Server specific in this case). So the specification would be [Column.Default(value = "SQL Value Here")] eg. for a Boolean column that has a default value of true - [Column.Default(value = 1)] for an "enumeration" [Column.Default(value = 5)] where 5 represents some state or similar value. Could be a foreign-key out to a table that represents an enumeration in code.

Hope that makes it clear.

TheMouster commented 6 years ago

FYI: The value of the defaults would be specific SQL strings so they would not be database agnostic.

activa commented 6 years ago

Why not set the default value on the server once the table is created? For Sqlite I could see the value of this, but not for server-based databases.

TheMouster commented 6 years ago

I'm looking at it from the automatic database generation part of Iridium where if the table is not present it automatically creates it. Which is great, but I found that Iridium was not capable of doing this part. I had a couple of choices, use Fluent.Migrations or similar or add an attribute that allowed Iridium to do this as part of it's design.

Why do you not think this would be useful for server based databases, other than the fact that you can set them up outside of Iridium, which you can also do with SQLite. That said, I think I see your point. Iridium has the automatic table creation for dealing with a blank SQLite database, but is not designed to do the same for a server-base database.