Macro sqlm_postgres::sql

source ·
sql!() { /* proc-macro */ }
Expand description

Creates a parameterized, compile-time checked database query that accepts parameters similar to the format! macro.

The compile-time checks require a database connection, expecting a DATABASE_URL env to be set accordingly.

The returned type can either be a struct (that implements FromRow), a literal (string, integer, …), or a Vec or Option of the former.

A connection is automatically established, but also be explicitly set via Sql::run_with.

§Examples

let name: String = sql!("SELECT name FROM users WHERE id = {id}", id = 1i64).await?;