shuttle
shuttle copied to clipboard
feature: support SeaORM
ORMs offer a layer of abstraction which makes creating business logic a joy in web apps. Shuttle currently has native sqlx
support but doesn't support any ORMs.
This feature would add SeaORM support and all the wiring required for it to work out of the box with the existing databases.
Love this issue :) I've made a tiny contribution to sea-orm
recently and have explored the codebase a bit (currently I have a standing issue on sea-query
to address on after working on #238). I'm overall quite new with Rust ORMs and haven't used Shuttle a lot but happy to be kept informed on the design discussion in case I can contribute later on.
I just add lines here:
use sea_orm::{
entity::prelude::*, ActiveValue, ConnectOptions, ConnectionTrait, Database, DatabaseConnection,
SqlxPostgresConnector, SqlxPostgresPoolConnection,
};
...
#[shuttle_service::main]
async fn poem(
#[shared::Postgres] pool: PgPool,
) -> shuttle_service::ShuttlePoem<impl poem::Endpoint> {
let conn = SqlxPostgresConnector::from_sqlx_postgres_pool(pool); // pg conn
...
let app = Route::new()
.at("i", get(index))
.with(AddData::new(conn));
...
Sea-ORM conn already works in handler fn with param "state: Data<&DatabaseConnection>", tested locally. Any ideas.
Nice @gzeronet. Actually what you wrote here reminds me that SeaORM updated their tutorial recently so maybe we could use this SeaORM example that integrates with rocket
and see how we could turn this example into a shuttle service? This way it's a dummy app that is limited in scope and might be re-usable for testing purposes. Just throwing some ideas around.
But I also wonder what the scope of Christos's original comment is? 😄
add SeaORM support and all the wiring required for it to work out of the box
This makes me believe we should be able to create a shuttle-seaorm
crate once #273 lands, right? The crate will setup "all the wiring" based on the tutorial from @nahuakang's link.
Closing in favour of #1559