π οΈ Kitx - A Fast CRUD Toolkit Based on Rust's Sqlx
π English | δΈζ
A lightweight CRUD toolkit built on top of sqlx::QueryBuilder
Use it just like you'd use Sqlx β flexible, simple, and without extra overhead!
Supports: SQLite, MySQL/MariaDB, and PostgreSQL
π Key Features
-
Native Sqlx Usage Style
Core queries are built with a thin wrapper aroundsqlx::QueryBuilder, ensuring type safety and protection against SQL injection. Easily compose raw SQL fragments for complex query scenarios. -
Simplified Entity Model Macros
Depends only on theFieldAccesstrait (besidessqlx). No heavy derive macros needed β minimal configuration and boilerplate. Comes with utility functions to parse entity models. -
Reduced Field Binding Effort
Eliminates repetitive.bind(x).bind(y)...calls. Many operations require no manual binding of field values! -
Built-in Common Operations
Provides ready-to-use methods for Insert, Update, Upsert, Delete, Select, including regular pagination and cursor-based pagination β covering most real-world use cases.
π Why Choose Kitx? See It in Action!
/// Fetch all records β So easy?
async
/// Not an ORM, but still very convenient.
/// Note: Foreign key relationships must be handled manually.
async
/// Nested subquery example
async
π¦ Getting Started
1. Add Dependency
[]
= "0.0.15"
Or, if you're targeting a specific database (recommended for better compile-time performance):
# For PostgreSQL
= { = "0.0.15", = ["postgres"] }
# For MySQL
= { = "0.0.15", = ["mysql"] }
# For SQLite
= { = "0.0.15", = ["sqlite"] }
All three databases are supported by default, but enabling only the required feature improves compilation speed.
2. Usage Guide
use ;
async
For more examples, check the integration tests under each database-specific module.
π‘ Note:
Kitx works by breaking down SQL statements into keyword-based segments (e.g.,
"SELECT {} FROM {} WHERE {}") and using entity model data to auto-fill placeholders. When automatic filling isn't sufficient, you can fall back to manual construction via closures (fn(QueryBuilder)), allowing aliases, joins, nested conditions, etc.
Methods named
oneormanythat operate directly on entity models do not support custom SQL fragments. These require a strict naming convention: the database table name (snake_case) must correspond to the struct name (camelCase).
All methods are thoroughly unit-tested to ensure reliability.
β Simple. Safe. Expressive.
Build powerful database interactions β without leaving the comfort of Sqlx.