-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SeaORM] migration guide for SeaQuery users #72
Comments
Ideas? @tyt2y3 |
I think the change in type system from SeaQuery to SeaORM is worth mentioning. In SeaQuery, the type system is lower-level: #[derive(Iden)]
enum Cake {
Table,
Id,
Name,
}
Query::select().column(Cake::Name).from(Cake::Table).and_where(Expr::col(Cake::Id).eq(1)) In SeaORM, Entity (hence table name) is a separate type from columns: #[derive(DeriveEntity, ..)]
#[sea_orm(table_name = "cake")]
pub struct Entity;
#[derive(DeriveActiveModel, ..)]
pub struct Model {
pub id: i32,
pub name: String,
}
Cake::find().filter(cake::Column::Id.eq(1)) Resulting in more concise code and a nicer experience. |
Related discussion on Discord https://discord.com/channels/873880840487206962/900758302294704188/1045647323075710998 (Just a note to self) |
Quoting from discord for posterity and people without an account:
Some notes:
struct UsersAndGroups {
user: User,
groups: Vec<Group>,
} Finally, it would be nice if the entity generation would warn about column types that are not compatible with other DBs (I'm thinking of e.g. |
SeaQL/sea-orm#1349 tracking issue created
I think we should simply add
I also wanted it (and tried many things) back then, and finally I believed that it cannot be done. rust-lang/rust#8995 might be relevant
This is due to how the aggregator currently works. It works by iterating through the rows without using a hashmap to resolve the association. If we change the implementation and uses a hashmap, we can drop this constraint. However it is currently blocked by SeaQL/sea-orm#1254
This PR already made it possible SeaQL/sea-orm#1238 . At least it is very easy to write a wrapper function to construct the
SeaQL/sea-orm#1311 this might instead do what you want?
Well received |
The actual reason we didn't add these is that it conflicts with |
Thanks for the reply!
I'm not necessarily in favor of switching to a hashmap (it sounds like it would probably be slower?) but it should at least be documented that it introduces an implicit order_by. Although it's true that a hashmap would make things easier on the API. Maybe expose both ways? e.g. add a
This looks great :) |
One small note on SeaQL/sea-orm#1238: It's nice that it's possible, but it requires another round-trip to the DB, where the query could be done all at once. |
Proposed by SeaQL/sea-orm#1227 (comment)
Content
I think there are two types of use cases.
Mapping query result into struct
This serve as a way to execute any SeaQuery statement. And the query result of select statement can be mapped into a struct in Rust.
Basically, as mentioned in this cookbook article: https://www.sea-ql.org/sea-orm-cookbook/003-run-sea-query-statement-on-sea-orm.html
Full SeaORM with access to alter the SeaQuery statement
Setup SeaORM entity with
sea-orm-cli
or defining it manually.Then, You can get a mutable reference of the SeaQuery select statement from sea_orm::Select by QuerySelect::query method. With that you can construct complex query.
The text was updated successfully, but these errors were encountered: