kitx-0.0.8 has been yanked.
KitX - Lightweight SQL Builder for Rust
A minimalistic SQL builder library based on sqlx, supporting SQLite, MySQL/MariaDB, and PostgreSQL. It offers efficient database operations with soft delete capabilities and global filters, enabling developers to interact with databases more effectively.
Features
Core Functionality
-
Efficient CRUD Operations
insert_one,insert_many,update_one,update_many,delete_one,delete_manywith transaction support -
Advanced Queries
fetch_all,fetch_by_key,fetch_one,fetch_paginated,fetch_by_cursor,exists,count -
Soft Delete Management
restore_one,restore_manywith global configuration -
Flexible Query Building
Supports JOINs, CASE WHEN, aggregations, and custom SQL extensions
Key Advantages
- 🚀 No ORM Overhead - Direct SQL interaction with builder pattern
- 🔧 Field Access API - Utilizes field_access for field operations
- 🌍 Global Filters - Apply tenant ID or soft delete filters across all queries
- 📦 Extensible - Easily add custom operations and query modifiers
Quick Start
1. Add Dependency
# Default SQL Builder, completely decoupled from any external libraries.
= "0.0.8"
# For SQLite only
= { = "0.0.8", = ["sqlite"] }
# For MySQL/MariaDB only
= { = "0.0.8", = ["mysql"] }
# For PostgreSQL only
= { = "0.0.8", = ["postgres"] }
2. Basic Usage
use ;
// SQL Builder Example
// AND and OR conditions can be applied either within filter clauses or directly in the builder.
let query = select
.filter
.filter
.or
.order_by
.build_mut.0;
// CRUD Operations
let op = new;
let article = Article ;
// Insert with transaction
op.insert_one.await?;
3. Pagination Example
let results = op.fetch_paginated.await?;
let results = op.fetch_by_cursor.await?;
4. Optional: Global Configuration
// Soft delete configuration
set_global_soft_delete_field;
// Global_filter is applied on a per-thread basis.
// Multi-tenant filtering
set_global_filter, vec!);
License
MIT License