https://linen.dev logo
sqlx wants DATABASE_URL where do I get it and set ...
# help
s
I'm trying to use sqlx in an axum shuttle app:
Copy code
rust
    let con = pool.acquire().await?; // pool is the PgPool Shuttle injects.
    // event is a struct that for now only contains one property: title
    let event_id = sqlx::query_as!(
        sqlx::types::Uuid,
        "INSERT INTO events (title) VALUES(?) RETURNING id",
        event.title
    )
        .fetch_one(con)
        .await?;
I get following error during compilation: >
DATABASE_URL
must be set to use query macros The question is where do I get that variable and where do I set it in a shuttle app?
e
you need to enable the feature offline in sqlx and execute:
cargo sqlx prepare
commit the new file generated and you can proceed with the build
a
Just as an addon if you aren't already: you can plug in the shuttle_shared_db lib and just use that as the connection and pass it into an initialised AppState struct If you don't want to do that, something that I did was set a variable as an
PgPool::connect("foobar").await
(where PgPool is
sqlx::PgPool
) or whatever and then pass that variable in when you need a db connection
s
I'm doing that already, without success
Thanks, I'll try that