A safe, extensible ORM and Query Builder for Rust – For feature requests and longer questions also see https://github.com/diesel-rs/diesel/discussions/categories/q-a
This is what I currently have:
fn load<M>(&self, id: M::Id, connection: &PgConnection) ->QueryResult<M>
where
M: Identifiable,
Find<dyn FindDsl<M::Id, Output = M>, M::Id>: LoadQuery<PgConnection, M>,
{
M::table().find(id).get_result(connection)
It doesn't compile:
error[E0275]: overflow evaluating the requirement `_: Sized`
--> src/bin/server/database.rs:179:16
|
179 | I::table().find(id).get_result(conn)
| ^^^^
|
= help: consider adding a `#![recursion_limit="4096"]` attribute to your crate (`server`)
= note: required because of the requirements on the impl of `FilterDsl<_>` for `<<I as HasTable>::Table as AsQuery>::Query`
error: aborting due to previous error; 6 warnings emitted
534.12
into a pgnumeric, but it doesn't work
Hello everyone. I got a question on raw queries. Haven’t found much on diesel’s documentation.
const QUERY: &str = r#"SELECT "id", "user_id", "name", "location", ST_Distance(...) as "distance" FROM profile WHERE ST_Distance(...) <= 1000 ORDER BY "distance" ASC"#;
let profiles = diesel::sql_query(QUERY).load::<ProfileNearby>(_connection);
I’m wondering how can I use my custom structs with diesel and raw queries. If I use load::<Profile> everything is ok and it builds fine, the only problem is that result doesn’t have distance column as it is not specified on a struct and doesn’t exists on table. Do you know how I can bind a custom struct to query results ?
eq
methods seems only to work on boolean ? How can I check if an integer is equal to another integer ?
sql_query
requires always a custom struct that implements QueryableByName
. Instead of using sql_query
you could define your version function via sql_function!
and use the typed query builder (so diesel::select(version())
which allows you to select directly into a String
.sql_query
.
QueryableByName
. That seems so be what's in the example, at least.