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 src="https://www.sea-ql.org/SeaORM/img/SeaORM banner.png"/>
14//!
15//!   <h1>SeaORM</h1>
16//!
17//!   <h3>🐚 An async & dynamic ORM for Rust</h3>
18//!
19//!   [![crate](https://img.shields.io/crates/v/sea-orm.svg)](https://crates.io/crates/sea-orm)
20//!   [![docs](https://docs.rs/sea-orm/badge.svg)](https://docs.rs/sea-orm)
21//!   [![build status](https://github.com/SeaQL/sea-orm/actions/workflows/rust.yml/badge.svg)](https://github.com/SeaQL/sea-orm/actions/workflows/rust.yml)
22//!
23//! </div>
24//!
25//! # SeaORM
26//!
27//! [中文文档](https://github.com/SeaQL/sea-orm/blob/master/README-zh.md)
28//!
29//! #### SeaORM is a relational ORM to help you build web services in Rust with the familiarity of dynamic languages.
30//!
31//! [![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/)
32//! If you like what we do, consider starring, sharing and contributing!
33//!
34//! Please help us with maintaining SeaORM by completing the [SeaQL Community Survey 2025](https://www.sea-ql.org/community-survey/)!
35//!
36//! [![Discord](https://img.shields.io/discord/873880840487206962?label=Discord)](https://discord.com/invite/uCPdDXzbdv)
37//! Join our Discord server to chat with other members of the SeaQL community!
38//!
39//! ## Getting Started
40//!
41//! + [Documentation](https://www.sea-ql.org/SeaORM)
42//! + [Tutorial](https://www.sea-ql.org/sea-orm-tutorial)
43//! + [Cookbook](https://www.sea-ql.org/sea-orm-cookbook)
44//!
45//! Integration examples:
46//!
47//! + [Actix v4 Example](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example)
48//! + [Axum Example](https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example)
49//! + [GraphQL Example](https://github.com/SeaQL/sea-orm/tree/master/examples/graphql_example)
50//! + [jsonrpsee Example](https://github.com/SeaQL/sea-orm/tree/master/examples/jsonrpsee_example)
51//! + [Loco TODO 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)
52//! + [Poem Example](https://github.com/SeaQL/sea-orm/tree/master/examples/poem_example)
53//! + [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)
54//! + [Salvo Example](https://github.com/SeaQL/sea-orm/tree/master/examples/salvo_example)
55//! + [Tonic Example](https://github.com/SeaQL/sea-orm/tree/master/examples/tonic_example)
56//! + [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)
57//!
58//! If you want a simple, clean example that fits in a single file that demonstrates the best of SeaORM, you can try:
59//! + [Quickstart](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs)
60//!
61//! ## Features
62//!
63//! 1. Async
64//!
65//!     Relying on [SQLx](https://github.com/launchbadge/sqlx), SeaORM is a new library with async support from day 1.
66//!
67//! 2. Dynamic
68//!
69//!     Built upon [SeaQuery](https://github.com/SeaQL/sea-query), SeaORM allows you to build complex dynamic queries.
70//!
71//! 3. Service Oriented
72//!
73//!     Quickly build services that join, filter, sort and paginate data in REST, GraphQL and gRPC APIs.
74//!
75//! 4. Production Ready
76//!
77//!     SeaORM is feature-rich, well-tested and used in production by companies and startups.
78//!
79//! ## A quick taste of SeaORM
80//!
81//! Let's have a quick walk through of the unique features of SeaORM.
82//!
83//! ### Entity
84//! You don't have to write this by hand! Entity files can be generated from an existing database with `sea-orm-cli`,
85//! following is generated with `--entity-format dense` (new in 2.0).
86//! ```
87//! # #[cfg(feature = "macros")]
88//! # mod entities {
89//! # mod filling {
90//! # use sea_orm::entity::prelude::*;
91//! # #[sea_orm::model]
92//! # #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
93//! # #[sea_orm(table_name = "filling")]
94//! # pub struct Model {
95//! #     #[sea_orm(primary_key)]
96//! #     pub id: i32,
97//! #     pub name: String,
98//! #     #[sea_orm(has_many, via = "cake_filling")]
99//! #     pub cakes: Vec<super::cake::Entity>,
100//! # }
101//! # impl ActiveModelBehavior for ActiveModel {}
102//! # }
103//! # mod cake_filling {
104//! # use sea_orm::entity::prelude::*;
105//! # #[sea_orm::model]
106//! # #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
107//! # #[sea_orm(table_name = "cake_filling")]
108//! # pub struct Model {
109//! #     #[sea_orm(primary_key, auto_increment = false)]
110//! #     pub cake_id: i32,
111//! #     #[sea_orm(primary_key, auto_increment = false)]
112//! #     pub filling_id: i32,
113//! #     #[sea_orm(belongs_to, from = "CakeId", to = "Id")]
114//! #     pub cake: Option<super::cake::Entity> ,
115//! #     #[sea_orm(belongs_to, from = "FillingId", to = "Id")]
116//! #     pub filling: Option<super::filling::Entity> ,
117//! # }
118//! # impl ActiveModelBehavior for ActiveModel {}
119//! # }
120//! mod cake {
121//!     use sea_orm::entity::prelude::*;
122//!
123//!     #[sea_orm::model]
124//!     #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
125//!     #[sea_orm(table_name = "cake")]
126//!     pub struct Model {
127//!         #[sea_orm(primary_key)]
128//!         pub id: i32,
129//!         pub name: String,
130//!         #[sea_orm(has_one)]
131//!         pub fruit: HasOne<super::fruit::Entity>,
132//!         #[sea_orm(has_many, via = "cake_filling")] // M-N relation with junction
133//!         pub fillings: HasMany<super::filling::Entity>,
134//!     }
135//! # impl ActiveModelBehavior for ActiveModel {}
136//! }
137//! mod fruit {
138//!     use sea_orm::entity::prelude::*;
139//!
140//!     #[sea_orm::model]
141//!     #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
142//!     #[sea_orm(table_name = "fruit")]
143//!     pub struct Model {
144//!         #[sea_orm(primary_key)]
145//!         pub id: i32,
146//!         pub name: String,
147//!         #[sea_orm(unique)]
148//!         pub cake_id: Option<i32>,
149//!         #[sea_orm(belongs_to, from = "cake_id", to = "id")]
150//!         pub cake: HasOne<super::cake::Entity>,
151//!     }
152//! # impl ActiveModelBehavior for ActiveModel {}
153//! }
154//! # }
155//! ```
156//! ### Entity Loader
157//!
158//! The Entity Loader intelligently uses join for 1-1 and data loader for 1-N relations,
159//! eliminating the N+1 problem even when performing nested queries.
160//! ```
161//! # use sea_orm::{DbConn, error::*, prelude::*, entity::*, query::*, tests_cfg::*};
162//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
163//! // join paths:
164//! // cake -> fruit
165//! // cake -> cake_filling -> filling -> ingredient
166//!
167//! let super_cake = cake::Entity::load()
168//!     .filter_by_id(42) // shorthand for .filter(cake::Column::Id.eq(42))
169//!     .with(fruit::Entity) // 1-1 uses join
170//!     .with((filling::Entity, ingredient::Entity)) // 1-N uses data loader
171//!     .one(db)
172//!     .await?
173//!     .unwrap();
174//!
175//! // 3 queries are executed under the hood:
176//! // 1. SELECT FROM cake JOIN fruit WHERE id = $
177//! // 2. SELECT FROM filling JOIN cake_filling WHERE cake_id IN (..)
178//! // 3. SELECT FROM ingredient WHERE filling_id IN (..)
179//!
180//! super_cake
181//!     == cake::ModelEx {
182//!         id: 42,
183//!         name: "Black Forest".into(),
184//!         fruit: Some(
185//!             fruit::ModelEx {
186//! #           id: 1,
187//!                 name: "Cherry".into(),
188//! #           cake_id: Some(1),
189//!             }
190//!             .into(),
191//!         ),
192//!         fillings: vec![filling::ModelEx {
193//! #           id: 2,
194//!             name: "Chocolate".into(),
195//! #           vendor_id: None,
196//! #           ignored_attr: 0,
197//!             ingredients: vec![ingredient::ModelEx {
198//! #               id: 3,
199//!                 name: "Syrup".into(),
200//! #               filling_id: Some(2),
201//! #               filling: Default::default(),
202//! #               ingredient_id: None,
203//! #               ingredient: None,
204//!             }],
205//!         }],
206//!     };
207//! # Ok(())
208//! # }
209//! ```
210//! ### Select
211//! SeaORM models 1-N and M-N relationships at the Entity level,
212//! letting you traverse many-to-many links through a junction table in a single call.
213//! ```
214//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
215//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
216//! // find all models
217//! let cakes: Vec<cake::Model> = Cake::find().all(db).await?;
218//!
219//! // find and filter
220//! let chocolate: Vec<cake::Model> = Cake::find()
221//!     .filter(cake::Column::Name.contains("chocolate"))
222//!     .all(db)
223//!     .await?;
224//!
225//! // find one model
226//! let cheese: Option<cake::Model> = Cake::find_by_id(1).one(db).await?;
227//! let cheese: cake::Model = cheese.unwrap();
228//!
229//! // find related models (lazy)
230//! let fruit: Option<fruit::Model> = cheese.find_related(Fruit).one(db).await?;
231//!
232//! // find related models (eager): for 1-1 relations
233//! let cake_with_fruit: Vec<(cake::Model, Option<fruit::Model>)> =
234//!     Cake::find().find_also_related(Fruit).all(db).await?;
235//!
236//! // find related models (eager): works for both 1-N and M-N relations
237//! let cake_with_fillings: Vec<(cake::Model, Vec<filling::Model>)> = Cake::find()
238//!     .find_with_related(Filling) // for M-N relations, two joins are performed
239//!     .all(db) // rows are automatically consolidated by left entity
240//!     .await?;
241//! # Ok(())
242//! # }
243//! ```
244//! ### Nested Select
245//!
246//! Partial models prevent overfetching by letting you querying only the fields
247//! you need; it also makes writing deeply nested relational queries simple.
248//! ```
249//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
250//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
251//! use sea_orm::DerivePartialModel;
252//!
253//! #[derive(DerivePartialModel)]
254//! #[sea_orm(entity = "cake::Entity")]
255//! struct CakeWithFruit {
256//!     id: i32,
257//!     name: String,
258//!     #[sea_orm(nested)]
259//!     fruit: Option<fruit::Model>, // this can be a regular or another partial model
260//! }
261//!
262//! let cakes: Vec<CakeWithFruit> = Cake::find()
263//!     .left_join(fruit::Entity) // no need to specify join condition
264//!     .into_partial_model() // only the columns in the partial model will be selected
265//!     .all(db)
266//!     .await?;
267//! # Ok(())
268//! # }
269//! ```
270//!
271//! ### Insert
272//! SeaORM's ActiveModel lets you work directly with Rust data structures and
273//! persist them through a simple API.
274//! It's easy to insert large batches of rows from different data sources.
275//! ```
276//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
277//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
278//! let apple = fruit::ActiveModel {
279//!     name: Set("Apple".to_owned()),
280//!     ..Default::default() // no need to set primary key
281//! };
282//!
283//! let pear = fruit::ActiveModel {
284//!     name: Set("Pear".to_owned()),
285//!     ..Default::default()
286//! };
287//!
288//! // insert one: Active Record style
289//! let apple = apple.insert(db).await?;
290//! apple.id == 1;
291//! # let apple = fruit::ActiveModel {
292//! #     name: Set("Apple".to_owned()),
293//! #     ..Default::default() // no need to set primary key
294//! # };
295//!
296//! // insert one: repository style
297//! let result = Fruit::insert(apple).exec(db).await?;
298//! result.last_insert_id == 1;
299//! # let apple = fruit::ActiveModel {
300//! #     name: Set("Apple".to_owned()),
301//! #     ..Default::default() // no need to set primary key
302//! # };
303//!
304//! // insert many returning last insert id
305//! let result = Fruit::insert_many([apple, pear]).exec(db).await?;
306//! result.last_insert_id == Some(2);
307//! # Ok(())
308//! # }
309//! ```
310//!
311//! ### Insert (advanced)
312//! You can take advantage of database specific features to perform upsert and idempotent insert.
313//! ```
314//! # use sea_orm::{DbConn, TryInsertResult, error::*, entity::*, query::*, tests_cfg::*};
315//! # async fn function_1(db: &DbConn) -> Result<(), DbErr> {
316//! # let apple = fruit::ActiveModel {
317//! #     name: Set("Apple".to_owned()),
318//! #     ..Default::default() // no need to set primary key
319//! # };
320//! # let pear = fruit::ActiveModel {
321//! #     name: Set("Pear".to_owned()),
322//! #     ..Default::default()
323//! # };
324//! // insert many with returning (if supported by database)
325//! let models: Vec<fruit::Model> = Fruit::insert_many([apple, pear])
326//!     .exec_with_returning(db)
327//!     .await?;
328//! models[0]
329//!     == fruit::Model {
330//!         id: 1, // database assigned value
331//!         name: "Apple".to_owned(),
332//!         cake_id: None,
333//!     };
334//! # Ok(())
335//! # }
336//!
337//! # async fn function_2(db: &DbConn) -> Result<(), DbErr> {
338//! # let apple = fruit::ActiveModel {
339//! #     name: Set("Apple".to_owned()),
340//! #     ..Default::default() // no need to set primary key
341//! # };
342//! # let pear = fruit::ActiveModel {
343//! #     name: Set("Pear".to_owned()),
344//! #     ..Default::default()
345//! # };
346//! // insert with ON CONFLICT on primary key do nothing, with MySQL specific polyfill
347//! let result = Fruit::insert_many([apple, pear])
348//!     .on_conflict_do_nothing()
349//!     .exec(db)
350//!     .await?;
351//!
352//! matches!(result, TryInsertResult::Conflicted);
353//! # Ok(())
354//! # }
355//! ```
356//!
357//! ### Update
358//! ActiveModel avoids race conditions by updating only the fields you've changed,
359//! never overwriting untouched columns.
360//! You can also craft complex bulk update queries with a fluent query building API.
361//! ```
362//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
363//! use fruit::Column::CakeId;
364//! use sea_orm::sea_query::{Expr, Value};
365//!
366//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
367//! let pear: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await?;
368//! let mut pear: fruit::ActiveModel = pear.unwrap().into();
369//!
370//! pear.name = Set("Sweet pear".to_owned()); // update value of a single field
371//!
372//! // update one: only changed columns will be updated
373//! let pear: fruit::Model = pear.update(db).await?;
374//!
375//! // update many: UPDATE "fruit" SET "cake_id" = "cake_id" + 2
376//! //               WHERE "fruit"."name" LIKE '%Apple%'
377//! Fruit::update_many()
378//!     .col_expr(CakeId, Expr::col(CakeId).add(Expr::val(2)))
379//!     .filter(fruit::Column::Name.contains("Apple"))
380//!     .exec(db)
381//!     .await?;
382//! # Ok(())
383//! # }
384//! ```
385//! ### Save
386//! You can perform "insert or update" operation with ActiveModel, making it easy to compose transactional operations.
387//! ```
388//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
389//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
390//! let banana = fruit::ActiveModel {
391//!     id: NotSet,
392//!     name: Set("Banana".to_owned()),
393//!     ..Default::default()
394//! };
395//!
396//! // create, because primary key `id` is `NotSet`
397//! let mut banana = banana.save(db).await?;
398//!
399//! banana.id == Unchanged(2);
400//! banana.name = Set("Banana Mongo".to_owned());
401//!
402//! // update, because primary key `id` is present
403//! let banana = banana.save(db).await?;
404//! # Ok(())
405//! # }
406//! ```
407//! ### Delete
408//! The same ActiveModel API consistent with insert and update.
409//! ```
410//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
411//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
412//! // delete one: Active Record style
413//! let orange: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await?;
414//! let orange: fruit::Model = orange.unwrap();
415//! orange.delete(db).await?;
416//!
417//! // delete one: repository style
418//! let orange = fruit::ActiveModel {
419//!     id: Set(2),
420//!     ..Default::default()
421//! };
422//! fruit::Entity::delete(orange).exec(db).await?;
423//!
424//! // delete many: DELETE FROM "fruit" WHERE "fruit"."name" LIKE '%Orange%'
425//! fruit::Entity::delete_many()
426//!     .filter(fruit::Column::Name.contains("Orange"))
427//!     .exec(db)
428//!     .await?;
429//!
430//! # Ok(())
431//! # }
432//! ```
433//! ### Ergonomic Raw SQL
434//! Let SeaORM handle 90% of all the transactional queries.
435//! When your query is too complex to express, SeaORM still offer convenience in writing raw SQL.
436//!
437//! The `raw_sql!` macro is like the `format!` macro but without the risk of SQL injection.
438//! It supports nested parameter interpolation, array and tuple expansion, and even repeating group,
439//! offering great flexibility in crafting complex queries.
440//!
441//! ```
442//! # use sea_orm::{DbErr, DbConn};
443//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
444//! # use sea_orm::{entity::*, query::*, tests_cfg::*, raw_sql};
445//! # struct Item { id: i32 }
446//! let item = Item { id: 2 }; // nested parameter access
447//!
448//! let cake: Option<cake::Model> = Cake::find()
449//!     .from_raw_sql(raw_sql!(
450//!         Sqlite,
451//!         r#"SELECT "id", "name" FROM "cake" WHERE id = {item.id}"#
452//!     ))
453//!     .one(db)
454//!     .await?;
455//! # Ok(())
456//! # }
457//! ```
458//! ```
459//! # use sea_orm::{DbErr, DbConn};
460//! # async fn functio(db: &DbConn) -> Result<(), DbErr> {
461//! # use sea_orm::{query::*, FromQueryResult, raw_sql};
462//! #[derive(FromQueryResult)]
463//! struct CakeWithBakery {
464//!     name: String,
465//!     #[sea_orm(nested)]
466//!     bakery: Option<Bakery>,
467//! }
468//!
469//! #[derive(FromQueryResult)]
470//! struct Bakery {
471//!     #[sea_orm(alias = "bakery_name")]
472//!     name: String,
473//! }
474//!
475//! let cake_ids = [2, 3, 4]; // expanded by the `..` operator
476//!
477//! // can use many APIs with raw SQL, including nested select
478//! let cake: Option<CakeWithBakery> = CakeWithBakery::find_by_statement(raw_sql!(
479//!     Sqlite,
480//!     r#"SELECT "cake"."name", "bakery"."name" AS "bakery_name"
481//!        FROM "cake"
482//!        LEFT JOIN "bakery" ON "cake"."bakery_id" = "bakery"."id"
483//!        WHERE "cake"."id" IN ({..cake_ids})"#
484//! ))
485//! .one(db)
486//! .await?;
487//! # Ok(())
488//! # }
489//! ```
490//!
491//! ## 🧭 Seaography: instant GraphQL API
492//!
493//! [Seaography](https://github.com/SeaQL/seaography) is a GraphQL framework built for SeaORM.
494//! Seaography allows you to build GraphQL resolvers quickly.
495//! With just a few commands, you can launch a fullly-featured GraphQL server from SeaORM entities,
496//! complete with filter, pagination, relational queries and mutations!
497//!
498//! Look at the [Seaography Example](https://github.com/SeaQL/sea-orm/tree/master/examples/seaography_example) to learn more.
499//!
500//! <img src="https://raw.githubusercontent.com/SeaQL/sea-orm/master/examples/seaography_example/Seaography%20example.png"/>
501//!
502//! ## 🖥️ SeaORM Pro: Professional Admin Panel
503//!
504//! [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!
505//!
506//! SeaORM Pro will be updated to support the latest features in SeaORM 2.0.
507//!
508//! Features:
509//!
510//! + Full CRUD
511//! + Built on React + GraphQL
512//! + Built-in GraphQL resolver
513//! + Customize the UI with TOML config
514//! + Custom GraphQL endpoints *(new in 2.0)*
515//! + Role Based Access Control *(new in 2.0)*
516//!
517//! Learn More
518//!
519//! + [Example Repo](https://github.com/SeaQL/sea-orm-pro)
520//! + [Getting Started](https://www.sea-ql.org/sea-orm-pro/docs/install-and-config/getting-started/)
521//!
522//! ![](https://raw.githubusercontent.com/SeaQL/sea-orm/refs/heads/master/docs/sea-orm-pro-dark.png#gh-dark-mode-only)
523//! ![](https://raw.githubusercontent.com/SeaQL/sea-orm/refs/heads/master/docs/sea-orm-pro-light.png#gh-light-mode-only)
524//!
525//! ## SQL Server Support
526//!
527//! [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.
528//!
529//! ## Releases
530//!
531//! 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/2548).
532//!
533//! 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.
534//!
535//! + [A Sneak Peek at SeaORM 2.0](https://www.sea-ql.org/blog/2025-09-16-sea-orm-2.0/)
536//! + [SeaORM 2.0: A closer look](https://www.sea-ql.org/blog/2025-09-24-sea-orm-2.0/)
537//! + [Role Based Access Control in SeaORM 2.0](https://www.sea-ql.org/blog/2025-09-30-sea-orm-rbac/)
538//!
539//! If you make extensive use of SeaORM's underlying query builder, we recommend checking out our blog post on SeaQuery 1.0 release:
540//!
541//! + [The road to SeaQuery 1.0](https://www.sea-ql.org/blog/2025-08-30-sea-query-1.0/)
542//!
543//! It doesn't mean that SeaORM is 'done', we've designed an architecture to allow us to deliver new features without major breaking changes.
544//!
545//! + [Change Log](https://github.com/SeaQL/sea-orm/tree/master/CHANGELOG.md)
546//!
547//! ## License
548//!
549//! Licensed under either of
550//!
551//! -   Apache License, Version 2.0
552//!     ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
553//! -   MIT license
554//!     ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
555//!
556//! at your option.
557//!
558//! ## Contribution
559//!
560//! Unless you explicitly state otherwise, any contribution intentionally submitted
561//! for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
562//! dual licensed as above, without any additional terms or conditions.
563//!
564//! We invite you to participate, contribute and together help build Rust's future.
565//!
566//! A big shout out to our contributors!
567//!
568//! [![Contributors](https://opencollective.com/sea-orm/contributors.svg?width=1000&button=false)](https://github.com/SeaQL/sea-orm/graphs/contributors)
569//!
570//! ## Who's using SeaORM?
571//!
572//! SeaORM is trusted by companies and startups for both internal tools and public‑facing applications, thanks to its ergonomics and the familiarity it brings from dynamic languages.
573//! Built on async Rust, it combines high performance and a strong type system without sacrificing developer productivity.
574//!
575//! Here is a short list of awesome open source software built with SeaORM. [Full list here](https://github.com/SeaQL/sea-orm/blob/master/COMMUNITY.md#built-with-seaorm). Feel free to submit yours!
576//!
577//! | Project | GitHub | Tagline |
578//! |---------|--------|---------|
579//! | [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 |
580//! | [OpenObserve](https://github.com/openobserve/openobserve) | ![GitHub stars](https://img.shields.io/github/stars/openobserve/openobserve.svg?style=social) | Open-source observability platform |
581//! | [RisingWave](https://github.com/risingwavelabs/risingwave) | ![GitHub stars](https://img.shields.io/github/stars/risingwavelabs/risingwave.svg?style=social) | Stream processing and management platform |
582//! | [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 |
583//! | [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 |
584//! | [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 |
585//! | [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 |
586//! | [Lapdev](https://github.com/lapce/lapdev) | ![GitHub stars](https://img.shields.io/github/stars/lapce/lapdev.svg?style=social) | Self-hosted remote development enviroment |
587//! | [System Initiative](https://github.com/systeminit/si) | ![GitHub stars](https://img.shields.io/github/stars/systeminit/si.svg?style=social) | DevOps Automation Platform |
588//! | [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 |
589//!
590//! ## Sponsorship
591//!
592//! [SeaQL.org](https://www.sea-ql.org/) is an independent open-source organization run by passionate developers. If you enjoy using our libraries, please star and share our repositories. 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.
593//!
594//! ### Gold Sponsors
595//!
596//! <table><tr>
597//! <td><a href="https://qdx.co/">
598//!   <img src="https://www.sea-ql.org/static/sponsors/QDX.svg" width="138"/>
599//! </a></td>
600//! </tr></table>
601//!
602//! [QDX](https://qdx.co/) pioneers quantum dynamics-powered drug discovery, leveraging AI and supercomputing to accelerate molecular modeling.
603//! We're immensely grateful to QDX for sponsoring the development of SeaORM, the SQL toolkit that powers their data engineering workflows.
604//!
605//! ### Silver Sponsors
606//!
607//! We're grateful to our silver sponsors: Digital Ocean, for sponsoring our servers. And JetBrains, for sponsoring our IDE.
608//!
609//! <table><tr>
610//! <td><a href="https://www.digitalocean.com/">
611//!   <img src="https://www.sea-ql.org/static/sponsors/DigitalOcean.svg" width="125">
612//! </a></td>
613//!
614//! <td><a href="https://www.jetbrains.com/">
615//!   <img src="https://www.sea-ql.org/static/sponsors/JetBrains.svg" width="125">
616//! </a></td>
617//! </tr></table>
618//!
619//! ## Mascot
620//!
621//! A friend of Ferris, Terres the hermit crab is the official mascot of SeaORM. His hobby is collecting shells.
622//!
623//! <img alt="Terres" src="https://www.sea-ql.org/SeaORM/img/Terres.png" width="400"/>
624//!
625//! ### Rustacean Sticker Pack 🦀
626//!
627//! The Rustacean Sticker Pack is the perfect way to express your passion for Rust.
628//! Our stickers are made with a premium water-resistant vinyl with a unique matte finish.
629//! Stick them on your laptop, notebook, or any gadget to show off your love for Rust!
630//!
631//! Sticker Pack Contents:
632//! - Logo of SeaQL projects: SeaQL, SeaORM, SeaQuery, Seaography, FireDBG
633//! - Mascot of SeaQL: Terres the Hermit Crab
634//! - Mascot of Rust: Ferris the Crab
635//! - The Rustacean word
636//!
637//! [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.
638//!
639//! <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>
640#![doc(
641    html_logo_url = "https://raw.githubusercontent.com/SeaQL/sea-query/master/docs/SeaQL icon dark.png"
642)]
643
644mod database;
645mod docs;
646mod driver;
647pub mod dynamic;
648/// Module for the Entity type and operations
649pub mod entity;
650/// Error types for all database operations
651pub mod error;
652/// This module performs execution of queries on a Model or ActiveModel
653mod executor;
654/// Types and methods to perform metric collection
655pub mod metric;
656/// Types and methods to perform queries
657pub mod query;
658#[cfg(feature = "rbac")]
659#[cfg_attr(docsrs, doc(cfg(feature = "rbac")))]
660pub mod rbac;
661/// Types that defines the schemas of an Entity
662pub mod schema;
663/// Helpers for working with Value
664pub mod value;
665
666#[doc(hidden)]
667#[cfg(all(feature = "macros", feature = "tests-cfg"))]
668pub mod tests_cfg;
669mod util;
670
671pub use database::*;
672#[allow(unused_imports)]
673pub use driver::*;
674pub use entity::*;
675pub use error::*;
676pub use executor::*;
677pub use query::*;
678pub use schema::*;
679
680#[cfg(feature = "macros")]
681pub use sea_orm_macros::{
682    DeriveActiveEnum, DeriveActiveModel, DeriveActiveModelBehavior, DeriveColumn, DeriveDisplay,
683    DeriveEntity, DeriveEntityModel, DeriveIden, DeriveIntoActiveModel, DeriveMigrationName,
684    DeriveModel, DeriveModelEx, DerivePartialModel, DerivePrimaryKey, DeriveRelatedEntity,
685    DeriveRelation, DeriveValueType, FromJsonQueryResult, FromQueryResult, raw_sql,
686    sea_orm_compact_model as compact_model, sea_orm_model as model,
687};
688
689pub use sea_query;
690pub use sea_query::Iden;
691
692pub use sea_orm_macros::EnumIter;
693pub use strum;
694
695#[cfg(feature = "sqlx-dep")]
696pub use sqlx;