talira

A powerful relational ORM for Rust

open sourceMIT OR Apache-2.0self-hostablefree

SeaORM is an async relational ORM for Rust, built on SQLx and SeaQuery, for MySQL/MariaDB, PostgreSQL and SQLite on tokio. Entities can be generated from an existing database with sea-orm-cli, or written first and synced to the schema, and relations cover 1-1, 1-N, M-N and self-referential links. Its entity loader uses joins and batched queries to avoid N+1s in nested loads, ActiveModel builders persist whole object graphs in one call, and it has migrations, pagination and raw SQL. sea-orm-sync offers the same API without an async runtime, Seaography builds GraphQL APIs from its entities, and SQL Server support (SeaORM-X) is commercial.

Problems it solves

  • I want an ActiveRecord-style ORM in Rust instead of writing SQL strings everywhere
  • generate Rust model structs from our existing Postgres schema
  • query related rows with joins in Rust without N+1 queries
  • write database migrations in Rust and run them on deploy
  • an async database layer for an axum or actix-web API
  • insert a user with their profile, posts and tags in one call and let the library order the writes
  • add a column to my struct and have the table updated without writing a migration by hand
  • paginate and filter query results for a REST or GraphQL endpoint in Rust
  • use the same ORM against SQLite in tests and Postgres in production
  • an ORM for a small Rust CLI with SQLite that doesn't need tokio
  • Diesel's compile-time query types are too hard to work with for dynamic queries
  • stand up a GraphQL API over my database tables in Rust quickly

Features

  • MySQL/MariaDB, PostgreSQL and SQLite via SQLx
  • entity generation from a database (sea-orm-cli)
  • entity-first schema sync (2.0)
  • 1-1, 1-N, M-N and self-referential relations
  • smart entity loader that avoids N+1
  • nested ActiveModel persistence
  • migrations
  • pagination and nested selects
  • raw SQL with parameter expansion
  • synchronous API via sea-orm-sync (Rusqlite)
View 2 more
  • Seaography GraphQL
  • SeaORM Pro admin panel

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what SeaORM does.

  1. SQLx The Rust SQL Toolkit

Compare SeaORM with the top 3