serde_sql 0.1.0

Stream serde structs into SQLite INSERT statements using a reusable buffer.
Documentation
  • Coverage
  • 83.33%
    5 out of 6 items documented0 out of 2 items with examples
  • Size
  • Source code size: 20.35 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.73 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 31s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • JakkuSakura/serde_sql
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JakkuSakura

serde_sql

serde_sql streams serde::Serialize structs directly into SQLite INSERT statements without allocating intermediate field structures. You provide a String buffer and value; the crate appends the literal value list (v1, v2, …) so you can embed it in any SQL template.

Features

  • Zero-copy output: serialise straight into an existing String.
  • Handles Option, numbers, booleans, and strings with proper escaping.
  • Nested structures (maps/arrays) are emitted as JSON text literals.

Quick start

[dependencies]
serde_sql = { path = ".", version = "0.1.0" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
use serde::Serialize;
use serde_sql::serialize_insert;

#[derive(Serialize)]
struct User {
    id: u64,
    name: String,
    active: bool,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sql = String::new();
    sql.push_str("INSERT INTO users VALUES ");
    serialize_insert(
        &mut sql,
        &User {
            id: 1,
            name: "Alice".into(),
            active: true,
        },
    )?;

    assert_eq!(sql, "INSERT INTO users VALUES (1, 'Alice', 1)");
    Ok(())
}

Example

cargo run --example basic

Testing

cargo test

Documentation

  • API docs can be generated locally via cargo doc --open.
  • Additional usage notes live under docs/usage.md.