When using sea-query to build SQL queries, extracting the columns from a row is a bit awkward:
let query = Query::select()
.from(Users::Table)
.column(Users::Name)
.to_string(SqliteQueryBuilder);
let names = sqlx::query(&query)
.map(|row| row.get::<String, _>(&*Users::Name.to_string()))
.fetch_all(&pool);
I'm mainly focusing on the &*Users::Name.to_string() part, which essentially resolves to "name". Here, Users is an enum that derives sea_query::Iden. I opened an issue to make the values implement Into<&'static str> when possible, but that only partly solves the problem.
I'd like to be able to write: row.get::<String, _>(Users::Name). The argument to get must implement ColumnIndex but it's a sealed trait that is only implemented for usize and &str. Could we instead implement it for any AsRef<str>? With both proposals, the interface would become much nicer. I suspect that it would also help with any other query builders/ORM that have newtypes around their column names.
When using
sea-query
to build SQL queries, extracting the columns from a row is a bit awkward:I'm mainly focusing on the
&*Users::Name.to_string()
part, which essentially resolves to"name"
. Here,Users
is an enum that derivessea_query::Iden
. I opened an issue to make the values implementInto<&'static str>
when possible, but that only partly solves the problem.I'd like to be able to write:
row.get::<String, _>(Users::Name)
. The argument toget
must implementColumnIndex
but it's a sealed trait that is only implemented forusize
and&str
. Could we instead implement it for anyAsRef<str>
? With both proposals, the interface would become much nicer. I suspect that it would also help with any other query builders/ORM that have newtypes around their column names.