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