libsql-orm
A powerful, async-first ORM for libsql with first-class support for Cloudflare Workers and WebAssembly environments.
⚠️ Disclaimer: This library is in early development and not fully tested in production environments. Use at your own risk. Please report any issues you encounter and feel free to contribute via pull requests - we're happy to address them and welcome community contributions!
✨ Features
- 🚀 Cloudflare Workers Ready - Built specifically for edge computing environments
- 🔄 Async/Await Support - Fully async API with excellent performance
- 🎯 Type-Safe - Leverages Rust's type system for compile-time safety
- 📊 Rich Query Builder - Fluent API for complex queries
- 🔍 Advanced Filtering - Search, pagination, sorting, and aggregations
- 🎨 Derive Macros - Automatic model generation with
#[derive(Model)]
- 📦 Bulk Operations - Efficient batch inserts, updates, and deletes
- 🌐 WASM Compatible - Optimized for WebAssembly targets
- 🔧 Custom Table Names -
#[table_name("custom")]
attribute support - ✅ Boolean Type Safety - Automatic SQLite integer ↔ Rust boolean conversion
- 🏷️ Column Attributes -
#[orm_column(...)]
for column customization - 🔄 Upsert Operations - Smart create_or_update and upsert methods
🚀 Quick Start
Add this to your Cargo.toml
:
[]
= "0.1.0"
= { = "1.0", = ["derive"] }
= { = "0.4", = ["serde"] }
Basic Usage
use ;
use ;
use ;
// Custom table name (optional)
// In your async function
async
Cloudflare Workers Integration
use *;
use ;
// Custom table name
async
📚 Advanced Features
Custom Table Names
Use the #[table_name("custom_name")]
attribute to specify custom table names:
// Custom table name
// Default table name would be "user" (struct name lowercase)
// With attribute, table name is "user_accounts"
assert_eq!;
Benefits:
- 🏷️ Legacy Integration - Map to existing database tables
- 🎯 Naming Control - Override default naming conventions
- 📁 Multi-tenant - Use prefixes like
tenant_users
- 🔄 Migration Friendly - Rename tables without changing structs
Boolean Type Safety
libsql-orm automatically handles boolean conversion between SQLite and Rust:
use ;
use ;
// All boolean operations work seamlessly
let user = find_where.await?;
// JSON serialization works correctly
let json = to_string?; // ✅ Booleans as true/false
let deserialized: User = from_str?; // ✅ No errors
Key Features:
- ✅ Automatic Detection - Boolean fields identified at compile time
- ✅ Zero Configuration - Works with any boolean field name
- ✅ Type Safety - No runtime errors or invalid conversions
- ✅ Performance - Conversion logic generated at compile time
- ✅ JSON Compatible - Seamless serialization/deserialization
Column Attributes
Customize column properties with #[orm_column(...)]
:
use Model;
use ;
Query Builder
use ;
// Complex query with filtering and pagination
let query = new
.select
.r#where
.order_by
.limit
.offset;
let = query.build?;
Pagination
use ;
let pagination = new; // page 1, 10 items per page
let result: = find_paginated.await?;
// Access pagination info
// Page: result.pagination.page
// Total pages: result.pagination.total_pages.unwrap_or(0)
// Total items: result.pagination.total.unwrap_or(0)
for user in result.data
Bulk Operations
// Bulk insert
let users = vec!;
let saved_users = bulk_create.await?;
// Bulk delete
let ids_to_delete = vec!;
let deleted_count = bulk_delete.await?;
Aggregations
use Aggregate;
// Count users
let total_users = count.await?;
// Average age
let avg_age = aggregate.await?;
// Count with filter
let active_users_count = count_where.await?;
Search
use SearchFilter;
let search = new;
let results = search.await?;
Upsert Operations
libsql-orm provides intelligent create-or-update operations:
use ;
use ;
// Create or update based on primary key
let mut user = User ;
// Automatically decides whether to create or update
let saved_user = user.create_or_update.await?;
// Upsert based on unique constraints (e.g., email)
let user = User ;
// Will update existing record with this email, or create new if not found
let saved_user = user.upsert.await?;
// Multiple unique constraints
let saved_user = user.upsert.await?;
🏗️ Architecture
WASM Compatibility
libsql-orm is built from the ground up for WebAssembly environments:
- Uses
libsql
WASM bindings for database connectivity - Optimized async runtime for edge computing
- Minimal binary size with selective feature compilation
- Compatible with Cloudflare Workers, Deno Deploy, and other edge platforms
🔗 Ecosystem
libsql-orm works great with:
- libsql - The database engine
- Turso - Managed libsql hosting
- Cloudflare Workers - Edge computing platform
- worker-rs - Cloudflare Workers Rust SDK
🤝 Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
☕ Support the Project
If you find this library helpful and would like to support its development, consider making a donation:
💰 Donation Options
- GitHub Sponsors: Sponsor on GitHub
- Buy Me a Coffee: Buy me a coffee
- PayPal: PayPal Donation
🎯 What Your Support Helps With
- 🚀 Feature Development - Building new capabilities and improvements
- 🐛 Bug Fixes - Maintaining stability and reliability
- 📚 Documentation - Creating better guides and examples
- 🔧 Maintenance - Keeping the library up-to-date with dependencies
- ☁️ Infrastructure - Hosting costs for CI/CD and testing
Every contribution, no matter the size, helps make this library better for everyone! 🙏
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- libsql team for the excellent database engine
- Cloudflare for the Workers platform
- Rust community for the amazing ecosystem
Need help?
- 📚 Documentation
- 💬 Discussions
- 🐛 Issues