Perform a raw sql query using sqlx query_as!() #1399
-
I am enjoying using loco rs. Any help with the following would be greatly appreciated. use sea_orm::DbConn;
use serde::{Deserialize, Serialize};
use loco_rs::model::ModelResult;
use loco_rs::prelude::*;
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
struct MyRow {
id: i32,
name: String,
}
pub async fn get_sqlx_data(c: &DbConn) -> ModelResult<Vec<MyData>> {
let db: DatabaseConnection = c.into();
let results = sqlx::query_as!(
MyRow,
r#"
select id, name from my_table
"#
)
.fetch_all(c)
.await
.map_err(|e| ModelError::Any(e.into()))?;
Ok(results)
} This line here seems to be the issue: let db: DatabaseConnection = c.into(); I get the following: rustc: the trait bound `&sea_orm::DatabaseConnection: Into<sea_orm::DatabaseConnection>` is not satisfied required for `&sea_orm::DatabaseConnection` to implement `Into<sea_orm::DatabaseConnection>` It looks like seaorm 1.1 has this new functionality:
found here: But I am unable to upgrade seaorm due to a dependency conflict: error: failed to select a version for `sea-orm`.
the package `libsqlite3-sys` links to the native library `sqlite3`, but it conflicts with a previous package which links to `sqlite3` as well:
package `libsqlite3-sys v0.30.1`
... which satisfies dependency `libsqlite3-sys = "^0.30.1"` of package `sqlx-sqlite v0.8.3`
... which satisfies dependency `sqlx-sqlite = "=0.8.3"` of package `sqlx v0.8.3`
... which satisfies dependency `sqlx = "^0.8.3"` of package `locoapi v0.1.0 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Why are you using |
Beta Was this translation helpful? Give feedback.
-
If anyone else stumbles across this, I found a workaround. It looks like Seaorm passes around a reference to the underlying pool, so I can just grab that, here is a minimal example: let db: &DatabaseConnection = db;
let pool: PgPool = db.get_postgres_connection_pool().clone(); |
Beta Was this translation helpful? Give feedback.
If anyone else stumbles across this, I found a workaround. It looks like Seaorm passes around a reference to the underlying pool, so I can just grab that, here is a minimal example: