| Crates.io | torii-storage-postgres |
| lib.rs | torii-storage-postgres |
| version | 0.5.1 |
| created_at | 2025-02-27 04:20:10.417016+00 |
| updated_at | 2025-07-23 00:21:31.517252+00 |
| description | Postgres storage backend for the torii authentication ecosystem |
| homepage | |
| repository | https://github.com/cmackenzie1/torii-rs |
| max_upload_size | |
| id | 1571238 |
| size | 125,792 |
PostgreSQL storage backend for the Torii authentication framework.
This crate provides a complete PostgreSQL-based storage implementation for Torii, including all core authentication features like user management, sessions, passwords, OAuth, passkeys, and magic links. It is designed for production workloads that require high performance and reliability.
Add this to your Cargo.toml:
[dependencies]
torii-storage-postgres = "0.4.0"
use torii_storage_postgres::PostgresStorage;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to PostgreSQL database
let storage = PostgresStorage::connect("postgresql://user:password@localhost/torii").await?;
// Run migrations to set up the schema
storage.migrate().await?;
// Note: PostgresRepositoryProvider is still in development
// let repositories = Arc::new(storage.into_repository_provider());
// let torii = torii::Torii::new(repositories);
Ok(())
}
use torii_storage_postgres::PostgresStorage;
use sqlx::PgPool;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a connection pool
let pool = PgPool::connect("postgresql://user:password@localhost/torii").await?;
// Create storage instance
let storage = PostgresStorage::new(pool);
// Run migrations
storage.migrate().await?;
Ok(())
}
The PostgreSQL schema includes the following tables:
users - User accounts and profile informationsessions - Active user sessionspasswords - Hashed password credentialsoauth_accounts - Connected OAuth accountspasskeys - WebAuthn passkey credentialspasskey_challenges - Temporary passkey challengesmagic_links - Magic link tokens and metadataAll tables include appropriate indexes and constraints for optimal query performance and data integrity.
This crate currently provides the base PostgreSQL storage implementation with user and session management. The full repository provider implementation is still in development and will be available in future releases.
This crate implements the following storage traits:
UserStorage - User account managementSessionStorage - Session managementuuid-ossp extension for UUID generation