SeaQL / sea-query

🔱 A dynamic SQL query builder for MySQL, Postgres and SQLite
https://www.sea-ql.org
Other
1.2k stars 194 forks source link

Supporting a new type in SeaQuery #714

Open tyt2y3 opened 1 year ago

tyt2y3 commented 1 year ago

Not exactly an issue, but a guide on how to support a new type in SeaQuery.

  1. It usually starts from ColumnType where we'd add the type, so that it can be used in schema statements
  2. If the type has a native representation (like UUID), we can add a variant to the enum Value (and ArrayType) and implement all necessary traits (ValueType)
  3. we should also determine the JSON serialisation (most likely string) which is implemented in sea_value_to_json_value
  4. Feature guards i.e. #[cfg(feature = "with-uuid")] are needed
  5. We shouldn't depend on sqlx directly in the sea-query crate, so if a type is only defined in sqlx, we have to copy the struct and put it inside sea-query
  6. In sea-query-binder & sea-query-postgres, we then perform the type conversion and binding
  7. Finally, in sea-orm, we should implement TryGetable for the right backend

Reference:

(ipnetwork) https://github.com/SeaQL/sea-query/pull/309 https://github.com/SeaQL/sea-query/pull/364 https://github.com/SeaQL/sea-query/pull/503

(time) https://github.com/SeaQL/sea-query/pull/267 https://github.com/SeaQL/sea-orm/pull/602

EstebanBorai commented 6 days ago

Hey @tyt2y3 does this still valid? Perhaps this should be documented on a contributors section?