sqlx_query

Crates.iosqlx_query
lib.rssqlx_query
version0.2.1
sourcesrc
created_at2023-11-03 15:12:30.050176
updated_at2023-11-03 16:22:56.803145
descriptionExpands to either sqlx function `query` or macro `query!` call depending on `sqlx_compiletime_checks` has been enabled during the build.
homepagehttps://github.com/Wandalen/wTools/tree/master/module/move/sqlx_query
repositoryhttps://github.com/Wandalen/wTools/tree/master/module/move/sqlx_query
max_upload_size
id1024162
size9,272
Wandalen (Wandalen)

documentation

https://docs.rs/sqlx_query

README

Module :: sqlx_query

experimental rust-status docs.rs Open in Gitpod discord

The tool to make CLI ( commands user interface ). It is able to aggregate external binary applications, as well as functions, which are written in your language.

Sample

use sqlx_query::*;

let user : User = query_as!( User, "SELECT * FROM users LIMIT 1" )
    .fetch_one( executor )
    .await?;

query!( "DELETE FROM users WHERE id = $1", user.id )
    .execute( executor )
    .await?;
}

// Expands to

let user : User =
  {
    #[ cfg( feature = "sqlx_compiletime_checks" ) ]
    let q = ::sqlx::query_as::< _, User >( "SELECT * FROM users LIMIT 1" );
    #[ cfg( not( feature = "sqlx_compiletime_checks" ) ) ]
    let q = ::sqlx::query_as!( User, "SELECT * FROM users LIMIT 1" );
    q
  }
    .fetch_one( executor )
    .await?;
{
  #[ cfg( feature = "sqlx_compiletime_checks" ) ]
  let q = ::sqlx::query( "DELETE FROM users WHERE id = $1" ).bind( user.id );
  #[ cfg( not( feature = "sqlx_compiletime_checks" ) ) ]
  let q = ::sqlx::query!( "DELETE FROM users WHERE id = $1", user.id );
  q
}
    .execute( executor )
    .await?;

To add to your project

cargo add sqlx_query

Try out from the repository

git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/sqlx_query_trivial
cargo run
Commit count: 0

cargo fmt