shuttle icon indicating copy to clipboard operation
shuttle copied to clipboard

feature: support SeaORM

Open christos-h opened this issue 2 years ago • 4 comments

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.

christos-h avatar May 18 '22 09:05 christos-h

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.

nahuakang avatar Jul 15 '22 14:07 nahuakang

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.

gzeronet avatar Aug 03 '22 06:08 gzeronet

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

nahuakang avatar Aug 03 '22 07:08 nahuakang

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.

chesedo avatar Aug 03 '22 08:08 chesedo

Closing in favour of #1559

jonaro00 avatar Jan 25 '24 15:01 jonaro00