Skip to main content

sea_orm/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3#![deny(
4    missing_debug_implementations,
5    clippy::missing_panics_doc,
6    clippy::unwrap_used,
7    clippy::print_stderr,
8    clippy::print_stdout
9)]
10
11//! <div align="center">
12//!
13//!   <img alt="SeaORM" src="https://www.sea-ql.org/blog/img/SeaORM 2.0 Banner.png"/>
14//!
15//!   <h1></h1>
16//!   <h3>SeaORM is a powerful ORM for building web services in Rust</h3>
17//!
18//!   [![crate](https://img.shields.io/crates/v/sea-orm.svg)](https://crates.io/crates/sea-orm)
19//!   [![build status](https://github.com/SeaQL/sea-orm/actions/workflows/rust.yml/badge.svg)](https://github.com/SeaQL/sea-orm/actions/workflows/rust.yml)
20//!   [![GitHub stars](https://img.shields.io/github/stars/SeaQL/sea-orm.svg?style=social&label=Star&maxAge=1)](https://github.com/SeaQL/sea-orm/stargazers/)
21//!   <br>Support us with a ⭐ !
22//!
23//! </div>
24//!
25//! # 🐚 SeaORM
26//!
27//! [δΈ­ζ–‡ζ–‡ζ‘£](https://github.com/SeaQL/sea-orm/blob/master/README-zh.md)
28//!
29//! ### Advanced Relations
30//!
31//! Model complex relationships 1-1, 1-N, M-N, and even self-referential in a high-level, conceptual way.
32//!
33//! ### Familiar Concepts
34//!
35//! Inspired by popular ORMs in the Ruby, Python, and Node.js ecosystem, SeaORM offers a developer experience that feels instantly recognizable.
36//!
37//! ### Feature Rich
38//!
39//! SeaORM is a batteries-included ORM with filters, pagination, and nested queries to accelerate building REST, GraphQL, and gRPC APIs.
40//!
41//! ### Production Ready
42//!
43//! With 250k+ weekly downloads, SeaORM is production-ready, trusted by startups and enterprises worldwide.
44//!
45//! ## Getting Started
46//!
47//! [![Discord](https://img.shields.io/discord/873880840487206962?label=Discord)](https://discord.com/invite/uCPdDXzbdv)
48//! Join our Discord server to chat with others!
49//!
50//! + [Documentation](https://www.sea-ql.org/SeaORM)
51//!
52//! Integration examples:
53//!
54//! + [Actix Example](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
55//! + [Axum Example](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example)
56//! + [GraphQL Example](https://github.com/SeaQL/sea-orm/tree/master/examples/graphql_example)
57//! + [jsonrpsee Example](https://github.com/SeaQL/sea-orm/tree/master/examples/jsonrpsee_example)
58//! + [Loco Example](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_example) / [Loco REST Starter](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_starter)
59//! + [Poem Example](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example)
60//! + [Rocket Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_example) / [Rocket OpenAPI Example](https://github.com/SeaQL/sea-orm/tree/master/examples/rocket_okapi_example)
61//! + [Salvo Example](https://github.com/SeaQL/sea-orm/tree/master/examples/salvo_example)
62//! + [Tonic Example](https://github.com/SeaQL/sea-orm/tree/master/examples/tonic_example)
63//! + [Seaography Example (Bakery)](https://github.com/SeaQL/sea-orm/tree/master/examples/seaography_example) / [Seaography Example (Sakila)](https://github.com/SeaQL/seaography/tree/main/examples/sqlite)
64//!
65//! If you want a simple, clean example that fits in a single file that demonstrates the best of SeaORM, you can try:
66//! + [Quickstart](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs)
67//!
68//! Let's have a quick walk through of the unique features of SeaORM.
69//!
70//! ## Expressive Entity format
71//! You don't have to write this by hand! Entity files can be generated from an existing database using `sea-orm-cli`,
72//! following is generated with `--entity-format dense` *(new in 2.0)*.
73//! ```
74//! # #[cfg(feature = "macros")]
75//! # mod entities {
76//! # mod profile {
77//! # use sea_orm::entity::prelude::*;
78//! # #[sea_orm::model]
79//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
80//! # #[sea_orm(table_name = "profile")]
81//! # pub struct Model {
82//! #     #[sea_orm(primary_key)]
83//! #     pub id: i32,
84//! #     pub picture: String,
85//! #     #[sea_orm(unique)]
86//! #     pub user_id: i32,
87//! #     #[sea_orm(belongs_to, from = "user_id", to = "id")]
88//! #     pub user: BelongsTo<super::user::Entity>,
89//! # }
90//! # impl ActiveModelBehavior for ActiveModel {}
91//! # }
92//! # mod tag {
93//! # use sea_orm::entity::prelude::*;
94//! # #[sea_orm::model]
95//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
96//! # #[sea_orm(table_name = "post")]
97//! # pub struct Model {
98//! #     #[sea_orm(primary_key)]
99//! #     pub id: i32,
100//! #     #[sea_orm(has_many, via = "post_tag")]
101//! #     pub tags: HasMany<super::tag::Entity>,
102//! # }
103//! # impl ActiveModelBehavior for ActiveModel {}
104//! # }
105//! # mod post_tag {
106//! # use sea_orm::entity::prelude::*;
107//! # #[sea_orm::model]
108//! # #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
109//! # #[sea_orm(table_name = "post_tag")]
110//! # pub struct Model {
111//! #     #[sea_orm(primary_key, auto_increment = false)]
112//! #     pub post_id: i32,
113//! #     #[sea_orm(primary_key, auto_increment = false)]
114//! #     pub tag_id: i32,
115//! #     #[sea_orm(belongs_to, from = "post_id", to = "id")]
116//! #     pub post: BelongsTo<super::post::Entity>,
117//! #     #[sea_orm(belongs_to, from = "tag_id", to = "id")]
118//! #     pub tag: BelongsTo<super::tag::Entity>,
119//! # }
120//! # impl ActiveModelBehavior for ActiveModel {}
121//! # }
122//! mod user {
123//!     use sea_orm::entity::prelude::*;
124//!
125//!     #[sea_orm::model]
126//!     #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
127//!     #[sea_orm(table_name = "user")]
128//!     pub struct Model {
129//!         #[sea_orm(primary_key)]
130//!         pub id: i32,
131//!         pub name: String,
132//!         #[sea_orm(unique)]
133//!         pub email: String,
134//!         #[sea_orm(has_one)]
135//!         pub profile: HasOne<super::profile::Entity>,
136//!         #[sea_orm(has_many)]
137//!         pub posts: HasMany<super::post::Entity>,
138//!     }
139//! # impl ActiveModelBehavior for ActiveModel {}
140//! }
141//! mod post {
142//!     use sea_orm::entity::prelude::*;
143//!
144//!     #[sea_orm::model]
145//!     #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
146//!     #[sea_orm(table_name = "post")]
147//!     pub struct Model {
148//!         #[sea_orm(primary_key)]
149//!         pub id: i32,
150//!         pub user_id: i32,
151//!         pub title: String,
152//!         #[sea_orm(belongs_to, from = "user_id", to = "id")]
153//!         pub author: BelongsTo<super::user::Entity>,
154//!         #[sea_orm(has_many, via = "post_tag")] // M-N relation with junction
155//!         pub tags: HasMany<super::tag::Entity>,
156//!     }
157//! # impl ActiveModelBehavior for ActiveModel {}
158//! }
159//! # }
160//! ```
161//!
162//! ## Smart Entity Loader
163//! The Entity Loader intelligently uses join for 1-1 and data loader for 1-N relations,
164//! eliminating the N+1 problem even when performing nested queries.
165//! ```
166//! # use sea_orm::{DbConn, DbErr, prelude::*, entity::*, query::*, tests_cfg::*};
167//! # fn function(db: &DbConn) -> Result<(), DbErr> {
168//! // join paths:
169//! // user -> profile
170//! // user -> post
171//! //         post -> post_tag -> tag
172//! let smart_user = user::Entity::load()
173//!     .filter_by_id(42) // shorthand for .filter(user::COLUMN.id.eq(42))
174//!     .with(profile::Entity) // 1-1 uses join
175//!     .with((post::Entity, tag::Entity)) // 1-N uses data loader
176//!     .one(db)?
177//!     .unwrap();
178//!
179//! // 3 queries are executed under the hood:
180//! // 1. SELECT FROM user JOIN profile WHERE id = $
181//! // 2. SELECT FROM post WHERE user_id IN (..)
182//! // 3. SELECT FROM tag JOIN post_tag WHERE post_id IN (..)
183//!
184//! smart_user
185//!     == user::ModelEx {
186//!         id: 42,
187//!         name: "Bob".into(),
188//!         email: "bob@sea-ql.org".into(),
189//!         profile: HasOne::loaded(Some(profile::ModelEx {
190//! #           id: 1,
191//!             picture: "image.jpg".into(),
192//! #           user_id: 1,
193//! #           user: BelongsTo::Unloaded,
194//!         })),
195//!         posts: HasMany::Loaded(vec![post::ModelEx {
196//! #           id: 2,
197//! #           user_id: 1,
198//!             title: "Nice weather".into(),
199//! #           author: BelongsTo::Unloaded,
200//! #           comments: HasMany::Unloaded,
201//!             tags: HasMany::Loaded(vec![tag::ModelEx {
202//! #               id: 3,
203//!                 tag: "sunny".into(),
204//! #               posts: HasMany::Unloaded,
205//!             }]),
206//!         }]),
207//!     };
208//! # Ok(())
209//! # }
210//! ```
211//!
212//! ## ActiveModel: nested persistence made simple
213//! Persist an entire object graph: user, profile (1-1), posts (1-N), and tags (M-N)
214//! in a single operation using a fluent builder API. SeaORM automatically determines
215//! the dependencies and inserts or deletes objects in the correct order.
216//! This requires the SeaORM 2.0 dense entity format.
217//!
218//! ```
219//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
220//! # fn function(db: &DbConn) -> Result<(), DbErr> {
221//! // this creates the nested object as shown above:
222//! let user = user::ActiveModel::builder()
223//!     .set_name("Bob")
224//!     .set_email("bob@sea-ql.org")
225//!     .set_profile(profile::ActiveModel::builder().set_picture("image.jpg"))
226//!     .add_post(
227//!         post::ActiveModel::builder()
228//!             .set_title("Nice weather")
229//!             .add_tag(tag::ActiveModel::builder().set_tag("sunny")),
230//!     )
231//!     .save(db)?;
232//! # Ok(())
233//! # }
234//! ```
235//!
236//! ## Schema first or Entity first? Your choice
237//!
238//! SeaORM provides a powerful migration system that lets you create tables, modify schemas, and seed data with ease.
239//!
240//! With SeaORM 2.0, you also get a first-class [Entity First Workflow](https://www.sea-ql.org/blog/2025-10-30-sea-orm-2.0/):
241//! simply define new entities or add columns to existing ones,
242//! and SeaORM will automatically detect the changes and create the new tables, columns, unique keys, and foreign keys.
243//!
244//! ```ignore
245//! // SeaORM resolves foreign key dependencies and creates the tables in topological order.
246//! // Requires the `entity-registry` and `schema-sync` feature flags.
247//! db.get_schema_registry("my_crate::entity::*").sync(db);
248//! ```
249//!
250//! ## Ergonomic Raw SQL
251//!
252//! Let SeaORM handle 95% of your transactional queries.
253//! For the remaining cases that are too complex to express,
254//! SeaORM still offers convenient support for writing raw SQL.
255//! ```
256//! # use sea_orm::{DbErr, DbConn};
257//! # fn function(db: &DbConn) -> Result<(), DbErr> {
258//! # use sea_orm::{entity::*, query::*, tests_cfg::*, raw_sql};
259//! # struct Item<'a> { name: &'a str }
260//! let user = Item { name: "Bob" }; // nested parameter access
261//! let ids = [2, 3, 4]; // expanded by the `..` operator
262//!
263//! let user: Option<user::Model> = user::Entity::find()
264//!     .from_raw_sql(raw_sql!(
265//!         Sqlite,
266//!         r#"SELECT "id", "name" FROM "user"
267//!            WHERE "name" LIKE {user.name}
268//!            AND "id" in ({..ids})
269//!         "#
270//!     ))
271//!     .one(db)?;
272//! # Ok(())
273//! # }
274//! ```
275//!
276//! ## Synchronous Support
277//!
278//! [`sea-orm-sync`](https://crates.io/crates/sea-orm-sync) provides the full SeaORM API without requiring an runtime, making it ideal for lightweight CLI programs with SQLite.
279//!
280//! See the [quickstart example](https://github.com/SeaQL/sea-orm/blob/master/sea-orm-sync/examples/quickstart/src/main.rs) for usage.
281//!
282//! ## Basics
283//!
284//! ### Select
285//! SeaORM models 1-N and M-N relationships at the Entity level,
286//! letting you traverse many-to-many links through a junction table in a single call.
287//! ```
288//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
289//! # fn function(db: &DbConn) -> Result<(), DbErr> {
290//! // find all models
291//! let cakes: Vec<cake::Model> = Cake::find().all(db)?;
292//!
293//! // find and filter
294//! let chocolate: Vec<cake::Model> = Cake::find()
295//!     .filter(Cake::COLUMN.name.contains("chocolate"))
296//!     .all(db)?;
297//!
298//! // find one model
299//! let cheese: Option<cake::Model> = Cake::find_by_id(1).one(db)?;
300//! let cheese: cake::Model = cheese.unwrap();
301//!
302//! // find related models (lazy)
303//! let fruit: Option<fruit::Model> = cheese.find_related(Fruit).one(db)?;
304//!
305//! // find related models (eager): for 1-1 relations
306//! let cake_with_fruit: Vec<(cake::Model, Option<fruit::Model>)> =
307//!     Cake::find().find_also_related(Fruit).all(db)?;
308//!
309//! // find related models (eager): works for both 1-N and M-N relations
310//! let cake_with_fillings: Vec<(cake::Model, Vec<filling::Model>)> = Cake::find()
311//!     .find_with_related(Filling) // for M-N relations, two joins are performed
312//!     .all(db) // rows are automatically consolidated by left entity
313//!     ?;
314//! # Ok(())
315//! # }
316//! ```
317//! ### Nested Select
318//!
319//! Partial models prevent overfetching by letting you querying only the fields
320//! you need; it also makes writing deeply nested relational queries simple.
321//! ```
322//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
323//! # fn function(db: &DbConn) -> Result<(), DbErr> {
324//! use sea_orm::DerivePartialModel;
325//!
326//! #[derive(DerivePartialModel)]
327//! #[sea_orm(entity = "cake::Entity")]
328//! struct CakeWithFruit {
329//!     id: i32,
330//!     name: String,
331//!     #[sea_orm(nested)]
332//!     fruit: Option<fruit::Model>, // this can be a regular or another partial model
333//! }
334//!
335//! let cakes: Vec<CakeWithFruit> = Cake::find()
336//!     .left_join(fruit::Entity) // no need to specify join condition
337//!     .into_partial_model() // only the columns in the partial model will be selected
338//!     .all(db)?;
339//! # Ok(())
340//! # }
341//! ```
342//!
343//! ### Insert
344//! SeaORM's ActiveModel lets you work directly with Rust data structures and
345//! persist them through a simple API.
346//! It's easy to insert large batches of rows from different data sources.
347//! ```
348//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
349//! # fn function(db: &DbConn) -> Result<(), DbErr> {
350//! let apple = fruit::ActiveModel {
351//!     name: Set("Apple".to_owned()),
352//!     ..Default::default() // no need to set primary key
353//! };
354//!
355//! let pear = fruit::ActiveModel {
356//!     name: Set("Pear".to_owned()),
357//!     ..Default::default()
358//! };
359//!
360//! // insert one: Active Record style
361//! let apple = apple.insert(db)?;
362//! apple.id == 1;
363//! # let apple = fruit::ActiveModel {
364//! #     name: Set("Apple".to_owned()),
365//! #     ..Default::default() // no need to set primary key
366//! # };
367//!
368//! // insert one: repository style
369//! let result = Fruit::insert(apple).exec(db)?;
370//! result.last_insert_id == 1;
371//! # let apple = fruit::ActiveModel {
372//! #     name: Set("Apple".to_owned()),
373//! #     ..Default::default() // no need to set primary key
374//! # };
375//!
376//! // insert many returning last insert id
377//! let result = Fruit::insert_many([apple, pear]).exec(db)?;
378//! result.last_insert_id == Some(2);
379//! # Ok(())
380//! # }
381//! ```
382//!
383//! ### Insert (advanced)
384//! You can take advantage of database specific features to perform upsert and idempotent insert.
385//! ```
386//! # use sea_orm::{DbConn, TryInsertResult, DbErr, entity::*, query::*, tests_cfg::*};
387//! # fn function_1(db: &DbConn) -> Result<(), DbErr> {
388//! # let apple = fruit::ActiveModel {
389//! #     name: Set("Apple".to_owned()),
390//! #     ..Default::default() // no need to set primary key
391//! # };
392//! # let pear = fruit::ActiveModel {
393//! #     name: Set("Pear".to_owned()),
394//! #     ..Default::default()
395//! # };
396//! // insert many with returning (if supported by database)
397//! let models: Vec<fruit::Model> = Fruit::insert_many([apple, pear]).exec_with_returning(db)?;
398//! models[0]
399//!     == fruit::Model {
400//!         id: 1, // database assigned value
401//!         name: "Apple".to_owned(),
402//!         cake_id: None,
403//!     };
404//! # Ok(())
405//! # }
406//!
407//! # fn function_2(db: &DbConn) -> Result<(), DbErr> {
408//! # let apple = fruit::ActiveModel {
409//! #     name: Set("Apple".to_owned()),
410//! #     ..Default::default() // no need to set primary key
411//! # };
412//! # let pear = fruit::ActiveModel {
413//! #     name: Set("Pear".to_owned()),
414//! #     ..Default::default()
415//! # };
416//! // insert with ON CONFLICT on primary key do nothing, with MySQL specific polyfill
417//! let result = Fruit::insert_many([apple, pear])
418//!     .on_conflict_do_nothing()
419//!     .exec(db)?;
420//!
421//! matches!(result, TryInsertResult::Conflicted);
422//! # Ok(())
423//! # }
424//! ```
425//!
426//! ### Update
427//! ActiveModel avoids race conditions by updating only the fields you've changed,
428//! never overwriting untouched columns.
429//! You can also craft complex bulk update queries with a fluent query building API.
430//! ```
431//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
432//! use sea_orm::sea_query::{Expr, Value};
433//!
434//! # fn function(db: &DbConn) -> Result<(), DbErr> {
435//! let pear: Option<fruit::Model> = Fruit::find_by_id(1).one(db)?;
436//! let mut pear: fruit::ActiveModel = pear.unwrap().into();
437//!
438//! pear.name = Set("Sweet pear".to_owned()); // update value of a single field
439//!
440//! // update one: only changed columns will be updated
441//! let pear: fruit::Model = pear.update(db)?;
442//!
443//! // update many: UPDATE "fruit" SET "cake_id" = "cake_id" + 2
444//! //               WHERE "fruit"."name" LIKE '%Apple%'
445//! Fruit::update_many()
446//!     .col_expr(fruit::COLUMN.cake_id, fruit::COLUMN.cake_id.add(2))
447//!     .filter(fruit::COLUMN.name.contains("Apple"))
448//!     .exec(db)?;
449//! # Ok(())
450//! # }
451//! ```
452//! ### Save
453//! You can perform "insert or update" operation with ActiveModel, making it easy to compose transactional operations.
454//! ```
455//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
456//! # fn function(db: &DbConn) -> Result<(), DbErr> {
457//! let banana = fruit::ActiveModel {
458//!     id: NotSet,
459//!     name: Set("Banana".to_owned()),
460//!     ..Default::default()
461//! };
462//!
463//! // create, because primary key `id` is `NotSet`
464//! let mut banana = banana.save(db)?;
465//!
466//! banana.id == Unchanged(2);
467//! banana.name = Set("Banana Mongo".to_owned());
468//!
469//! // update, because primary key `id` is present
470//! let banana = banana.save(db)?;
471//! # Ok(())
472//! # }
473//! ```
474//! ### Delete
475//! The same ActiveModel API consistent with insert and update.
476//! ```
477//! # use sea_orm::{DbConn, DbErr, entity::*, query::*, tests_cfg::*};
478//! # fn function(db: &DbConn) -> Result<(), DbErr> {
479//! // delete one: Active Record style
480//! let orange: Option<fruit::Model> = Fruit::find_by_id(1).one(db)?;
481//! let orange: fruit::Model = orange.unwrap();
482//! orange.delete(db)?;
483//!
484//! // delete one: repository style
485//! let orange = fruit::ActiveModel {
486//!     id: Set(2),
487//!     ..Default::default()
488//! };
489//! fruit::Entity::delete(orange).exec(db)?;
490//!
491//! // delete many: DELETE FROM "fruit" WHERE "fruit"."name" LIKE '%Orange%'
492//! fruit::Entity::delete_many()
493//!     .filter(fruit::COLUMN.name.contains("Orange"))
494//!     .exec(db)?;
495//!
496//! # Ok(())
497//! # }
498//! ```
499//! ### Raw SQL Query
500//! The `raw_sql!` macro is like the `format!` macro but without the risk of SQL injection.
501//! It supports nested parameter interpolation, array and tuple expansion, and even repeating group,
502//! offering great flexibility in crafting complex queries.
503//!
504//! ```
505//! # use sea_orm::{DbErr, DbConn};
506//! # fn functio(db: &DbConn) -> Result<(), DbErr> {
507//! # use sea_orm::{query::*, FromQueryResult, raw_sql};
508//! #[derive(FromQueryResult)]
509//! struct CakeWithBakery {
510//!     name: String,
511//!     #[sea_orm(nested)]
512//!     bakery: Option<Bakery>,
513//! }
514//!
515//! #[derive(FromQueryResult)]
516//! struct Bakery {
517//!     #[sea_orm(alias = "bakery_name")]
518//!     name: String,
519//! }
520//!
521//! let cake_ids = [2, 3, 4]; // expanded by the `..` operator
522//!
523//! // can use many APIs with raw SQL, including nested select
524//! let cake: Option<CakeWithBakery> = CakeWithBakery::find_by_statement(raw_sql!(
525//!     Sqlite,
526//!     r#"SELECT "cake"."name", "bakery"."name" AS "bakery_name"
527//!        FROM "cake"
528//!        LEFT JOIN "bakery" ON "cake"."bakery_id" = "bakery"."id"
529//!        WHERE "cake"."id" IN ({..cake_ids})"#
530//! ))
531//! .one(db)?;
532//! # Ok(())
533//! # }
534//! ```
535//!
536//! ## 🧭 Seaography: instant GraphQL API
537//!
538//! [Seaography](https://github.com/SeaQL/seaography) is a GraphQL framework built for SeaORM.
539//! Seaography allows you to build GraphQL resolvers quickly.
540//! With just a few commands, you can launch a fullly-featured GraphQL server from SeaORM entities,
541//! complete with filter, pagination, relational queries and mutations!
542//!
543//! Look at the [Seaography Example](https://github.com/SeaQL/sea-orm/tree/master/examples/seaography_example) to learn more.
544//!
545//! <img src="https://raw.githubusercontent.com/SeaQL/sea-orm/master/examples/seaography_example/Seaography%20example.png"/>
546//!
547//! ## πŸ–₯️ SeaORM Pro: Professional Admin Panel
548//!
549//! [SeaORM Pro](https://github.com/SeaQL/sea-orm-pro/) is an admin panel solution allowing you to quickly and easily launch an admin panel for your application - frontend development skills not required, but certainly nice to have!
550//!
551//! SeaORM Pro has been updated to support the latest features in SeaORM 2.0.
552//!
553//! Features:
554//!
555//! + Full CRUD
556//! + Built on React + GraphQL
557//! + Built-in GraphQL resolver
558//! + Customize the UI with TOML config
559//! + Role Based Access Control *(new in 2.0)*
560//!
561//! Read the [Getting Started](https://www.sea-ql.org/sea-orm-pro/docs/install-and-config/getting-started/) guide to learn more.
562//!
563//! ![](https://raw.githubusercontent.com/SeaQL/sea-orm/refs/heads/master/docs/sea-orm-pro-dark.png#gh-dark-mode-only)
564//! ![](https://raw.githubusercontent.com/SeaQL/sea-orm/refs/heads/master/docs/sea-orm-pro-light.png#gh-light-mode-only)
565//!
566//! ## SQL Server Support
567//!
568//! [SQL Server for SeaORM](https://www.sea-ql.org/SeaORM-X/) offers the same SeaORM API for MSSQL. We ported all test cases and examples, complemented by MSSQL specific documentation. If you are building enterprise software, you can [request commercial access](https://forms.office.com/r/1MuRPJmYBR). It is currently based on SeaORM 1.0, but we will offer free upgrade to existing users when SeaORM 2.0 is finalized.
569//!
570//! ## Releases
571//!
572//! SeaORM 2.0 has reached its release candidate phase. We'd love for you to try it out and help shape the final release by [sharing your feedback](https://github.com/SeaQL/sea-orm/discussions/).
573//!
574//! + [Change Log](https://github.com/SeaQL/sea-orm/tree/master/CHANGELOG.md)
575//!
576//! SeaORM 2.0 is shaping up to be our most significant release yet - with a few breaking changes, plenty of enhancements, and a clear focus on developer experience.
577//!
578//! + [A Sneak Peek at SeaORM 2.0](https://www.sea-ql.org/blog/2025-09-16-sea-orm-2.0/)
579//! + [SeaORM 2.0: A closer look](https://www.sea-ql.org/blog/2025-09-24-sea-orm-2.0/)
580//! + [Role Based Access Control in SeaORM 2.0](https://www.sea-ql.org/blog/2025-09-30-sea-orm-rbac/)
581//! + [Seaography 2.0: A Powerful and Extensible GraphQL Framework](https://www.sea-ql.org/blog/2025-10-08-seaography/)
582//! + [SeaORM 2.0: New Entity Format](https://www.sea-ql.org/blog/2025-10-20-sea-orm-2.0/)
583//! + [SeaORM 2.0: Entity First Workflow](https://www.sea-ql.org/blog/2025-10-30-sea-orm-2.0/)
584//! + [SeaORM 2.0: Strongly-Typed Column](https://www.sea-ql.org/blog/2025-11-11-sea-orm-2.0/)
585//! + [What's new in SeaORM Pro 2.0](https://www.sea-ql.org/blog/2025-11-21-whats-new-in-seaormpro-2.0/)
586//! + [SeaORM 2.0: Nested ActiveModel](https://www.sea-ql.org/blog/2025-11-25-sea-orm-2.0/)
587//! + [A walk-through of SeaORM 2.0](https://www.sea-ql.org/blog/2025-12-05-sea-orm-2.0/)
588//! + [How we made SeaORM synchronous](https://www.sea-ql.org/blog/2025-12-12-sea-orm-2.0/)
589//! + [SeaORM 2.0 Migration Guide](https://www.sea-ql.org/blog/2026-01-12-sea-orm-2.0/)
590//! + [SeaORM now supports Arrow & Parquet](https://www.sea-ql.org/blog/2026-02-22-sea-orm-arrow/)
591//! + [SeaORM 2.0 with SQL Server Support](https://www.sea-ql.org/blog/2026-02-25-sea-orm-x/)
592//!
593//! If you make extensive use of SeaQuery, we recommend checking out our blog post on SeaQuery 1.0 release:
594//!
595//! + [The road to SeaQuery 1.0](https://www.sea-ql.org/blog/2025-08-30-sea-query-1.0/)
596//!
597//! ## License
598//!
599//! Licensed under either of
600//!
601//! -   Apache License, Version 2.0
602//!     ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
603//! -   MIT license
604//!     ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
605//!
606//! at your option.
607//!
608//! ## Contribution
609//!
610//! Unless you explicitly state otherwise, any contribution intentionally submitted
611//! for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
612//! dual licensed as above, without any additional terms or conditions.
613//!
614//! We invite you to participate, contribute and together help build Rust's future.
615//!
616//! A big shout out to our contributors!
617//!
618//! [![Contributors](https://opencollective.com/sea-orm/contributors.svg?width=1000&button=false)](https://github.com/SeaQL/sea-orm/graphs/contributors)
619//!
620//! ## Who's using SeaORM?
621//!
622//! Here is a short list of awesome open source software built with SeaORM. Feel free to [submit yours](https://github.com/SeaQL/sea-orm/blob/master/COMMUNITY.md#built-with-seaorm)!
623//!
624//! | Project | GitHub | Tagline |
625//! |---------|--------|---------|
626//! | [Zed](https://github.com/zed-industries/zed) | ![GitHub stars](https://img.shields.io/github/stars/zed-industries/zed.svg?style=social) | A high-performance, multiplayer code editor |
627//! | [Servo](https://github.com/servo/servo) | ![GitHub stars](https://img.shields.io/github/stars/servo/servo.svg?style=social) | The Servo Parallel Browser Engine Project |
628//! | [OpenObserve](https://github.com/openobserve/openobserve) | ![GitHub stars](https://img.shields.io/github/stars/openobserve/openobserve.svg?style=social) | Open-source observability platform |
629//! | [RisingWave](https://github.com/risingwavelabs/risingwave) | ![GitHub stars](https://img.shields.io/github/stars/risingwavelabs/risingwave.svg?style=social) | Stream processing and management platform |
630//! | [Warpgate](https://github.com/warp-tech/warpgate) | ![GitHub stars](https://img.shields.io/github/stars/warp-tech/warpgate.svg?style=social) | Smart SSH bastion that works with any SSH client |
631//! | [LLDAP](https://github.com/nitnelave/lldap) | ![GitHub stars](https://img.shields.io/github/stars/nitnelave/lldap.svg?style=social) | A light LDAP server for user management |
632//! | [Svix](https://github.com/svix/svix-webhooks) | ![GitHub stars](https://img.shields.io/github/stars/svix/svix-webhooks.svg?style=social) | The enterprise ready webhooks service |
633//! | [Ryot](https://github.com/IgnisDa/ryot) | ![GitHub stars](https://img.shields.io/github/stars/ignisda/ryot.svg?style=social) | The only self hosted tracker you will ever need |
634//! | [OctoBase](https://github.com/toeverything/OctoBase) | ![GitHub stars](https://img.shields.io/github/stars/toeverything/OctoBase.svg?style=social) | A light-weight, scalable, offline collaborative data backend |
635//! | [System Initiative](https://github.com/systeminit/si) | ![GitHub stars](https://img.shields.io/github/stars/systeminit/si.svg?style=social) | DevOps Automation Platform |
636//!
637//! ## Sponsorship
638//!
639//! [SeaQL.org](https://www.sea-ql.org/) is an independent open-source organization run by passionate developers.
640//! If you feel generous, a small donation via [GitHub Sponsor](https://github.com/sponsors/SeaQL) will be greatly appreciated, and goes a long way towards sustaining the organization.
641//!
642//! ### Gold Sponsors
643//!
644//! <table><tr>
645//! <td><a href="https://qdx.co/">
646//!   <img src="https://www.sea-ql.org/static/sponsors/QDX.svg" width="138"/>
647//! </a></td>
648//! </tr></table>
649//!
650//! [QDX](https://qdx.co/) pioneers quantum dynamics-powered drug discovery, leveraging AI and supercomputing to accelerate molecular modeling.
651//! We're immensely grateful to QDX for sponsoring the development of SeaORM, the SQL toolkit that powers their data intensive applications.
652//!
653//! ### Silver Sponsors
654//!
655//! We're grateful to our silver sponsors: Digital Ocean, for sponsoring our servers. And JetBrains, for sponsoring our IDE.
656//!
657//! <table><tr>
658//! <td><a href="https://www.digitalocean.com/">
659//!   <img src="https://www.sea-ql.org/static/sponsors/DigitalOcean.svg" width="125">
660//! </a></td>
661//!
662//! <td><a href="https://www.jetbrains.com/">
663//!   <img src="https://www.sea-ql.org/static/sponsors/JetBrains.svg" width="125">
664//! </a></td>
665//! </tr></table>
666//!
667//! ## Mascot
668//!
669//! A friend of Ferris, Terres the hermit crab is the official mascot of SeaORM. His hobby is collecting shells.
670//!
671//! <img alt="Terres" src="https://www.sea-ql.org/SeaORM/img/Terres.png" width="400"/>
672//!
673//! ## πŸ¦€ Rustacean Sticker Pack
674//! The Rustacean Sticker Pack is the perfect way to express your passion for Rust. Our stickers are made with a premium water-resistant vinyl with a unique matte finish.
675//!
676//! Sticker Pack Contents:
677//!
678//! + Logo of SeaQL projects: SeaQL, SeaORM, SeaQuery, Seaography
679//! + Mascots: Ferris the Crab x 3, Terres the Hermit Crab
680//! + The Rustacean wordmark
681//!
682//! [Support SeaQL and get a Sticker Pack!](https://www.sea-ql.org/sticker-pack/) All proceeds contributes directly to the ongoing development of SeaQL projects.
683//!
684//! <a href="https://www.sea-ql.org/sticker-pack/"><img alt="Rustacean Sticker Pack by SeaQL" src="https://www.sea-ql.org/static/sticker-pack-1s.jpg" width="600"/></a>
685#![doc(
686    html_logo_url = "https://raw.githubusercontent.com/SeaQL/sea-query/master/docs/SeaQL icon dark.png"
687)]
688
689mod database;
690mod docs;
691mod driver;
692pub mod dynamic;
693pub mod entity;
694/// Error types returned by SeaORM operations.
695pub mod error;
696mod executor;
697/// Per-query metric collection hooks.
698pub mod metric;
699pub mod query;
700#[cfg(feature = "rbac")]
701#[cfg_attr(docsrs, doc(cfg(feature = "rbac")))]
702pub mod rbac;
703pub mod schema;
704/// Helpers for working with [`sea_query::Value`].
705pub mod value;
706
707#[doc(hidden)]
708#[cfg(all(feature = "macros", feature = "tests-cfg"))]
709pub mod tests_cfg;
710mod util;
711
712pub use database::*;
713#[allow(unused_imports)]
714pub use driver::*;
715pub use entity::*;
716pub use error::*;
717pub use executor::*;
718pub use query::*;
719pub use schema::*;
720
721#[cfg(feature = "macros")]
722pub use sea_orm_macros::{
723    DeriveActiveEnum, DeriveActiveModel, DeriveActiveModelBehavior, DeriveActiveModelEx,
724    DeriveArrowSchema, DeriveColumn, DeriveDisplay, DeriveEntity, DeriveEntityModel, DeriveIden,
725    DeriveIntoActiveModel, DeriveMigrationName, DeriveModel, DeriveModelEx, DerivePartialModel,
726    DerivePrimaryKey, DeriveRelatedEntity, DeriveRelation, DeriveValueType, FromJsonQueryResult,
727    FromQueryResult, raw_sql, sea_orm_compact_model as compact_model, sea_orm_model as model,
728};
729
730pub use sea_query;
731pub use sea_query::Iden;
732
733pub use sea_orm_macros::EnumIter;
734pub use strum;
735
736#[cfg(feature = "with-arrow")]
737pub use sea_orm_arrow::arrow;
738
739#[cfg(feature = "sqlx-dep")]
740pub use sqlx;