| Crates.io | torii-storage-seaorm |
| lib.rs | torii-storage-seaorm |
| version | 0.5.1 |
| created_at | 2025-06-27 04:36:13.711754+00 |
| updated_at | 2025-07-23 00:22:04.911563+00 |
| description | SeaORM storage plugin for Torii |
| homepage | |
| repository | https://github.com/cmackenzie1/torii-rs |
| max_upload_size | |
| id | 1728151 |
| size | 185,760 |
SeaORM storage backend for the Torii authentication framework.
This crate provides a SeaORM-based storage implementation for Torii that works with multiple database backends including PostgreSQL, MySQL, and SQLite. SeaORM is a modern async ORM for Rust that provides type-safe database operations and excellent performance.
Add this to your Cargo.toml:
[dependencies]
torii-storage-seaorm = "0.4.0"
use torii_storage_seaorm::SeaORMStorage;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to database (supports PostgreSQL, MySQL, SQLite)
let storage = SeaORMStorage::connect("sqlite://todos.db?mode=rwc").await?;
// Run migrations to set up the schema
storage.migrate().await?;
// Convert to repository provider and use with Torii
let repositories = Arc::new(storage.into_repository_provider());
let torii = torii::Torii::new(repositories);
Ok(())
}
use torii_storage_seaorm::SeaORMStorage;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// PostgreSQL
let storage = SeaORMStorage::connect("postgresql://user:password@localhost/torii").await?;
// MySQL
// let storage = SeaORMStorage::connect("mysql://user:password@localhost/torii").await?;
// SQLite
// let storage = SeaORMStorage::connect("sqlite://auth.db?mode=rwc").await?;
storage.migrate().await?;
let repositories = Arc::new(storage.into_repository_provider());
let torii = torii::Torii::new(repositories);
Ok(())
}
use torii_storage_seaorm::SeaORMStorage;
use torii::Torii;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let storage = SeaORMStorage::connect("sqlite://auth.db?mode=rwc").await?;
storage.migrate().await?;
let repositories = Arc::new(storage.into_repository_provider());
let torii = Torii::new(repositories);
// Register a user
let user = torii.register_user_with_password("user@example.com", "secure_password").await?;
// Login
let (user, session) = torii.login_user_with_password(
"user@example.com",
"secure_password",
None, // user_agent
None, // ip_address
).await?;
println!("User logged in: {}", user.email);
println!("Session token: {}", session.token);
Ok(())
}
This crate can be used with any database backend supported by SeaORM:
This crate provides SeaORMRepositoryProvider which implements the RepositoryProvider trait from torii-core, allowing it to be used directly with the main Torii authentication coordinator.
The crate defines SeaORM entity models for all authentication data:
User - User accounts and profile informationSession - Active user sessionsPassword - Hashed password credentialsOAuthAccount - Connected OAuth accountsPasskey - WebAuthn passkey credentialsPasskeyChallenge - Temporary passkey challengesMagicLink - Magic link tokens and metadataAll entities include appropriate relationships and indexes for optimal performance.
This crate implements repository patterns for:
The crate includes built-in migration management through SeaORM's migration system. All necessary tables and indexes are automatically created when you call migrate().
SeaORM provides excellent performance characteristics: