-
exp: I want to gen a sql like INSERT INTO users (uid, username, email, birthdate, is_active) VALUES (UUID(), 'xxxx', 'xxxx.xx@xxx.com', '2020-12-20', true); the What should I do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Builtin functions can be expressed using But if you have a SeaORM entity and want to use it normally through an ActiveModel, I only know how to sneak an expression into an UPDATE: users::Entity::update_many()
.col_expr(users::Column::Uid, Expr::cust("UUID()"))
.filter(...)
.exec(&conn)
.await?; Insert APIs seem to only accept whole ActiveModels, where fields are ActiveValues, which can only store Rust values and not arbitrary SQL expressions. If your use case only involves the
|
Beta Was this translation helpful? Give feedback.
Builtin functions can be expressed using
sea_query::Expr::cust("UUID()")
.But if you have a SeaORM entity and want to use it normally through an ActiveModel, I only know how to sneak an expression into an UPDATE:
Insert APIs seem to only accept whole ActiveModels, where fields are ActiveValues, which can only store Rust values and not arbitrary SQL expressions.
If your use case only involves the
UUID()
function, there are a few obvious workarounds:DEFAULT
in the DB and keep this column NotSet when you insert the ActiveModel.