SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.94k stars 483 forks source link

ltree #510

Closed cemoktra closed 2 years ago

cemoktra commented 2 years ago

We just played around with ltrees. sea-orm-cli currently generates an empty enum. Maybe for the special ltree case it shoud generate something like

#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "ltree")]
pub enum Ltree {
    Value(String)
}

Currently this ends up in error: Missing macro attribute, eitherstring_valueornum_valueshould be specified, so there would need to be a way to extract the string out of the Value variant.

billy1624 commented 2 years ago

Hey @cemoktra, I guess you need to implement ActiveEnum manually instead of deriving DeriveActiveEnum. https://www.sea-ql.org/SeaORM/docs/generate-entity/enumeration#manual-implementation

cemoktra commented 2 years ago

Ok also possible, and what about mapping ltree to TEXT?

cemoktra commented 2 years ago

But I think I'll provide some changes for ltree

billy1624 commented 2 years ago

I'm not sure how ltree works.

But for ActiveEnum,

cemoktra commented 2 years ago

I started with the basic work on sqlx: https://github.com/launchbadge/sqlx/pull/1696

billy1624 commented 2 years ago

Thanks!! @cemoktra Let me know if you need any help on it!

cemoktra commented 2 years ago

Yeah maybe. Currently sea-query does not depend on sqlx itself, but in order to use my new type it will

cemoktra commented 2 years ago

Do you have any opinion on how to integrate this into seaql?

billy1624 commented 2 years ago

I think we can treat ltree as a simple string? Then, we don't need any additional SQLx dependency. https://github.com/launchbadge/sqlx/pull/1696#discussion_r804343242

cemoktra commented 2 years ago

Currently i get thread 'test::test' panicked at 'not implemented', sea-orm/src/driver/sqlx_postgres.rs:8:1 when trying to filter for an LTree with .eq, also .contains wants a String instead of PgLTree

.filter(test::Column::Ltree.eq(ltree))

Just doing a query works

cemoktra commented 2 years ago

Same for insert

cemoktra commented 2 years ago

Ok found the missing piece, sorry

tyt2y3 commented 2 years ago

This is sad but I think our general response to "support a particular Postgres feature" will be "we will gladly accept PR" for now