admin管理员组文章数量:1400007
I'm still very new to Rust & Sea Orm, but that's what the current project I'm working in is.
I'm working on a database focused on users (that's updatable by more than just the Rust/SeaOrm app).
The problem is, there's a lot of dynamically generated tables.
For example, there could be a "California_Users" table, a "Nevada_Users" table, etc. And although near identical, they're not going to be exactly identical (partially due to how regulations may be different in both places).
So, I have at my disposal, a String: Table
and a String: Column
and a String: PK
and a DatabaseConnection: db_connection
being passed into my function.
Using these, I need to do the equivalent of
SELECT FROM &TABLE WHERE &COLUMN = '&PK'
on the db_connection
.
However, I tried doing
fn get_value(String: Table, String: Column, String: PK) -> String {
let result: &Table::Model = &Column::find()
.filter(&Table::Column::&Column.contains(&PK))
.all(db_connection)
.await?;
return result;
}
Obviously, this doesn't work, not just because of naming collisions, but more importantly because &Table doesn't contain a model: it's just a string, and similar with &Column and &PK, but I want to select the right object using the name, not having to know it ahead of time, because I'm just straight up not going to know it ahead of time. And I'm having similar issues throughout. How do I do this?
本文标签: sqlSelecting a dynamically supplied table name using Sea Orm in RustStack Overflow
版权声明:本文标题:sql - Selecting a dynamically supplied table name using Sea Orm in Rust - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744107776a2591145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论