Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple create operation doesn't work with sqlite: cannot store TEXT value in INTEGER column ads.paid" #7

Open
sasacocic opened this issue Oct 27, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sasacocic
Copy link

I have the following code that breaks with this error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Database(SqliteError { code: 3091, message: "cannot store TEXT value in INTEGER column ads.paid" })', packages/backend/src/main.rs:74:36

specifically: cannot store TEXT value in INTEGER column ads.paid"

    let pool = SqlitePool::connect("sqlite:sqlite.db").await.unwrap();
    let mut conn = pool.acquire().await.unwrap();

    sqlx::query!(
        r#"
        CREATE TABLE IF NOT EXISTS ads (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            company TEXT NOT NULL,
            position TEXT NOT NULL,
            remote TEXT NOT NULL,
            apply_link TEXT NOT NULL,
            description TEXT NOT NULL,
            paid INTEGER NOT NULL
        ) STRICT;
    "#
    )
    .execute(&mut conn)
    .await
    .unwrap();

    let a = Ad {
        id: 12,
        company: "netflix".to_string(),
        apply_link: "lskfjd".to_string(),
        description: "des".to_string(),
        position: "des".to_string(),
        remote: "des".to_string(),
        paid: 1,
    };

    let output = a.create(&pool).await.unwrap();

it seems like numeric types are being stored as strings, which in this case breaks it.

@treydempsey treydempsey self-assigned this Apr 7, 2023
@treydempsey treydempsey added the bug Something isn't working label Apr 7, 2023
@treydempsey
Copy link
Owner

After adding a pool.close() to the end of the code I was able to get it working using the axum-support branch. I've reworked the proc_macro code generation portion, making the futures it returns Send. This allows it to work with Axum, but I also squashed a few bugs in the process. I'll comment here once that code is merged to main. I'll also try and work this up in to a unit test. Thanks for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants