#sqlx #macro #sql-query #replace #compiling #db #sqlx-macros

sqlx_macro_ex

Macros replace sqlx-macros without compiling time

2 unstable releases

0.2.0 Aug 18, 2024
0.1.0 Aug 29, 2023

#1883 in Database interfaces

Download history 111/week @ 2024-08-14 21/week @ 2024-08-21 12/week @ 2024-08-28 8/week @ 2024-09-11 6/week @ 2024-09-18 16/week @ 2024-09-25 22/week @ 2024-10-02 2/week @ 2024-10-09

61 downloads per month

MIT license

4KB

Sql Macro Ex

Just for no compling time check.

Example


#[derive(Debug, FromRow)]
struct User {
    uid: i32,
    name: String,
}

async fn insert_user(db: &DB, user: &User) -> sqlx::Result<()> {
    sqlx_macro_ex::query!(
        r#"
        insert into user(uid, name)
        values(?, ?)
        "#,
        &user.uid,
        &user.name,
    ).execute(mdb).await?;
    Ok(())
}

async fn get_user_with_uid(db: &DB, uid: i32) -> sqlx::Result<User> {
    sqlx_macro_ex::query_as!(
        User,
        r#"
        select * from user
        where uid = ?
        "#,
        uid
    ).fetch_one(db).await
}

async fn get_user_names__in_range(db: &DB, uid: i32) -> sqlx::Result<Vec<String>> {
    sqlx_macro_ex::query_scalar!(
        String,
        r#"
        select name from user
        where uid < ?
        "#,
        uid
    ).fetch_all(db).await
}

No runtime deps