I'm new to sea-query and sea-schema. I've extracted the schema from an sqlite database like this:
let url = "sqlite://test.db";
let connection = SqlitePool::connect(&url).await.unwrap();
let schema_discovery = SchemaDiscovery::new(connection);
let schema = schema_discovery.discover().await?;
Now I'd like to query the connection using sea-query. This is what I've tried:
let result = Query::select()
.from(&schema.tables[0])
.build(SqliteQueryBuilder);
Except that this gives me the error the trait bound '&TableDef: Iden' is not satisfied
. I understand that it means that I'm missing the implementation of these traits, but since this struct is part of the library, I imagine there might be a correct way of accomplishing this goal.
What am I supposed to pass to the Query builder, considering that I have no prior knowledge of the database? Saying that I have no prior knowledge means that I cannot create Enums with all tables and columns (that's why I'm discoving the schema in the first place).
I also tried looking at their documentation, but couldn't find an answer.
I was able to figure this out thanks to some code I found online. It seems that if you want to convert a string to a value that can be used inside a sea_query query, you should first convert it into an Alias:
Every string you want to use inside a query should be an Alias, and that goes for the columns you want to select too.
The complete code to get all the data from a specific table (considering "choice" as the index of the table I want in the schema) looks like this: