Rust library that provides derive macros for automatic CRUD operations and comprehensive audit trails for MySQL entities. Track who changed what, when, and why with actor, session, and change set metadata.
Go to file
Michael Netshipise 6ed2401be1 fix: use Value-based binding in UpdateForm for proper Option<T> handling
When UpdateForm wraps fields that are already Option<T>, it creates
nested Options (Option<Option<T>>). The old bind_form_values method
bound these directly as &Option<T>, which caused MySQL "malform packet"
errors for Uuid -> BINARY(16) conversions.

Now both bind_form_values and bind_all_values use update_stmt_with_values()
which properly converts values through the Value enum:
- Some(None) -> Value::Null
- Some(Some(v)) -> Value::T(v)

This preserves the three-state semantics:
- None: don't include field in UPDATE
- Some(None): SET column = NULL
- Some(Some(v)): SET column = value

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 18:13:07 +02:00
.claude/skills Update docs, MCP server, and skills for v0.3.0 features 2026-01-28 16:44:57 +02:00
mcp Use workspace version, add clap CLI to MCP server 2026-01-28 17:19:14 +02:00
scripts Import entity-changes project 2026-01-28 15:19:38 +02:00
sqlx-record-ctl Use workspace version, add clap CLI to MCP server 2026-01-28 17:19:14 +02:00
sqlx-record-derive fix: use Value-based binding in UpdateForm for proper Option<T> handling 2026-01-30 18:13:07 +02:00
src fix: use Value-based binding in UpdateForm for proper Option<T> handling 2026-01-30 18:13:07 +02:00
.gitignore Update docs, MCP server, and skills for v0.3.0 features 2026-01-28 16:44:57 +02:00
CLAUDE.md Release v0.3.0 with soft deletes, timestamps, batch ops, pagination, transactions 2026-01-28 16:36:24 +02:00
Cargo.toml fix: use Value-based binding in UpdateForm for proper Option<T> handling 2026-01-30 18:13:07 +02:00
Makefile Import entity-changes project 2026-01-28 15:19:38 +02:00
README.md Rename to sqlx-record with multi-database support 2026-01-28 15:31:24 +02:00

README.md

sqlx-record

Entity CRUD and change tracking for SQL databases with SQLx.

A Rust library that provides derive macros for automatic CRUD operations and comprehensive audit trails for SQL entities. Track who changed what, when, and why with actor, session, and change set metadata.

Features

  • #[derive(Entity)] generates complete CRUD operations
  • Type-safe query building with composable filters
  • Change tracking with WHO, WHAT, WHEN, and WHERE metadata
  • Version fields for optimistic locking
  • Diff detection between model states
  • CLI tool for managing audit tables
  • Supports MySQL, PostgreSQL, and SQLite

Installation

Add to your Cargo.toml:

[dependencies]
sqlx-record = { version = "0.1", features = ["mysql", "derive"] }
# or for PostgreSQL:
# sqlx-record = { version = "0.1", features = ["postgres", "derive"] }
# or for SQLite:
# sqlx-record = { version = "0.1", features = ["sqlite", "derive"] }

Usage

use sqlx_record::prelude::*;
use sqlx::FromRow;

#[derive(Entity, FromRow)]
#[table_name = "users"]
struct User {
    #[primary_key]
    id: Uuid,
    name: String,
    email: String,
    #[version]
    version: u32,
}

// Insert
let id = user.insert(&pool).await?;

// Query with filters
let users = User::find(&pool, filters![("active", true)], None).await?;

// Update with diff tracking
let mut form = User::update_form().with_name("New Name".into());
let diff = form.db_diff(&id, &pool).await?;
user.update(&pool, form).await?;

License

MIT