sea-orm-turso
A universal SeaORM adapter for Turso Database, providing MVCC, in-process, async database access.
Implements SeaORM's [ConnectionTrait] and [TransactionTrait], so it works as a drop-in replacement for any SeaORM-supported database.
Features
- MVCC: Full multi-version concurrency control via Turso engine
- In-process: No network overhead, runs directly in your application
- Async: Native async/await support via Tokio
- WAL persistence: In-memory speed with file-based durability
- Universal: Works with any SeaORM-based framework (Loco, Axum, etc.)
Installation
[]
= "0.1"
= "2.0"
Quick Start
use TursoConnection;
use ;
async
Usage with SeaORM
The TursoConnection implements SeaORM's ConnectionTrait and TransactionTrait, so it works seamlessly with all SeaORM APIs:
use ;
// Query
let users = find
.filter
.all
.await?;
// Insert
let new_user = ActiveModel ;
new_user.insert.await?;
// Update
let mut active: ActiveModel = existing_model.into;
active.name = Set;
active.update.await?;
// Delete
existing_model.delete.await?;
// Transaction
db.transaction.await?;
Integration with Loco
use TursoConnection;
// In your app.rs after_context hook:
async
Persistence
Turso's local engine uses WAL (Write-Ahead Logging) for persistence. Data is stored
in-memory for fast reads and periodically synced to disk via WAL. The adapter calls
cacheflush() and persist() after every write operation to ensure data durability.
Note: Turso's local engine creates its own WAL format when it first creates the database file. If you have an existing SQLite file created by another library, use a separate file path for Turso to ensure proper WAL support.
Architecture
┌─────────────────────────────┐
│ Your SeaORM Code │
├─────────────────────────────┤
│ TursoConnection │ ← Implements ConnectionTrait + TransactionTrait
├─────────────────────────────┤
│ Turso Engine (MVCC) │ ← In-process, async, concurrent writes
├─────────────────────────────┤
│ WAL → File Persistence │ ← Survives restarts
└─────────────────────────────┘
API
Connection
use TursoConnection;
// Connect to a file
let db = connect.await?;
// Connect to memory (no persistence)
let db = connect_memory.await?;
// From existing Turso database
let db = from_existing;
Convenience Functions
use sea_orm_turso;
// Shorthand for TursoConnection::connect
let db = connect.await?;
// Shorthand for TursoConnection::connect_memory
let db = connect_memory.await?;
Related
- SeaORM - The ORM this adapter supports
- Turso - The database engine powering this adapter
- SeaQL/sea-orm#2763 - Original feature request
License
MIT OR Apache-2.0