Skip to main content

Crate sqlw

Crate sqlw 

Source
Expand description

Compile-time SQL query building for Rust.

This crate provides a compile-time SQL macro with schema-safe field references and automatic parameter binding.

§Quick Start

use sqlw::{schema, query_qmark as query};

// Define your table schema
schema!(User "users" {
    ID: i64 "id",
    NAME: String "name",
    EMAIL: String "email",
});

// Build queries with schema-safe field references
let user_id = 42;
let query = query!(
    SELECT User::NAME, User::EMAIL
    FROM User::TABLE
    WHERE User::ID = {user_id}
);

query.sql();   // "SELECT name, email FROM users WHERE id = ?"
query.args();  // [Int(42)]

§Modules

  • backend - Query execution trait and row-mapping types
  • schema! - Table schema definitions
  • value - SQL value types and conversions

sqlw-backend (local, git)

Re-exports§

pub use backend::*;
pub use schema::*;
pub use value::*;

Modules§

backend
Query execution traits and row-mapping types.
schema
Table schema definitions.
value
SQL value types and conversions.

Macros§

query_numbered
Compiles a SQL query with $1, $2 placeholders.
query_qmark
Compiles a SQL query with ? placeholders.
schema
Defines a table schema with typed field constants and a value struct.

Structs§

Query
A compiled SQL query with bound parameters.

Derive Macros§

FromRow
Derives FromRow for a struct.
IntoValue
Derives [From<T> for Value] for newtypes and enums.
TryFromValueRef
Derives [TryFrom<ValueRef>] for a single-field tuple struct (newtype).