Skip to content

example compile error #4

Description

hello, I use this crate, and it says :

error: set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache
  --> examples/sqlx_orm.rs:9:1
   |
9  | / model! {
10 | |     state: App,
11 | |     table: joey_test,
12 | |
...  |
20 | |     },
21 | | }
   | |_^
   |
   = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `model` (in Nightly builds, run with -Z macro-backtrace for more info)
use sqlx::PgPool;
use sqlx_models_orm::{model, Db};

#[derive(Clone)]
pub struct App {
    db: Db,
}

model! {
    state: App,
    table: joey_test,

    struct JoeyTest {
        #[sqlx_model_hints(int4, default)]
        id: i32,
        #[sqlx_model_hints(varchar)]
        name: String,
        #[sqlx_model_hints(int4)]
        age: Option<i32>,
    },
}

#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    let pool = PgPool::connect("postgresql://root@localhost/joey").await?;
    let app = App { db: Db { pool, transaction: None } };

    let new_record = app.joey_test().insert(InsertJoeyTest { name: "Alice".to_string(), age: Some(30) }).save().await?;

    println!("Inserted record with ID: {}", new_record.attrs.id);
    Ok(())
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions