byronwasti / movine

A migration manager written in Rust that attempts to be smart yet minimal
MIT License
109 stars 9 forks source link

Library usage with sqlx::postgres::PgConnection #22

Open onx2 opened 3 years ago

onx2 commented 3 years ago

I was wondering if it was possible to use this in a bin file with sqlx's postgres PgConnection? I'm getting and error with my current implementation.

I'm trying to create a script that will create my database, run movine init and movine fix, then seed the database with mock data.

fn main() -> Result<()> {
    dotenv().ok();
    let database_url = dotenv::var("DATABASE_URL").expect("Missing database_url.");

    let pg_conn = block_on(init_database(&database_url))?;
    // this is what is returned
    // sqlx::postgres::PgConnection::connect(&database_url).await?

    let mut movine = Movine::new(&mut pg_conn);
    movine.init()?;
    movine.fix()?;
    // Seed DB

    Ok(())
}
the trait bound `PgConnection: DbAdaptor` is not satisfied
required because of the requirements on the impl of `DbAdaptor` for `&mut PgConnection`
required by `Movine::<T>::new`rustcE0277
let pg_conn: PgConnection
Go to PgConnection

BTW this is an awesome crate, great work 😃 It has been so easy using it so far!

byronwasti commented 3 years ago

Right now Movine won't work with sqlx until the adapter trait is applied to it. It will look very similar to the current Postgres connection except with sqlx as the connection provider (https://github.com/byronwasti/movine/blob/master/src/adaptor/postgres.rs)

I'm a bit swamped, but happy to review a PR if you want to add it. It might be necessary to add feature gates for it if the types conflict (which is something I need to add regardless).

Glad you've enjoyed the crate so far!