sqlx_macro_ex

Crates.iosqlx_macro_ex
lib.rssqlx_macro_ex
version0.2.0
sourcesrc
created_at2023-08-29 17:40:24.814488
updated_at2024-08-18 16:59:23.379807
descriptionMacros replace sqlx-macros without compiling time
homepage
repositoryhttps://github.com/dryBranch/sqlx_macro_ex
max_upload_size
id958322
size4,376
(dryBranch)

documentation

README

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
}
Commit count: 0

cargo fmt