sea_orm/schema/mod.rs
1//! Build `CREATE TABLE`, `CREATE TYPE`, and related schema statements from
2//! [`Entity`](crate::EntityTrait) definitions.
3//!
4//! Use [`Schema::new`] with a [`DbBackend`] to get a helper, then call
5//! [`Schema::builder`] for a fluent [`SchemaBuilder`] that emits `sea_query`
6//! statements you can execute on a connection. With the `entity-registry`
7//! and `schema-sync` feature flags enabled, `db.get_schema_registry(prefix)`
8//! syncs all registered entities at once.
9
10use crate::DbBackend;
11
12mod builder;
13mod entity;
14#[cfg(feature = "serde_json")]
15mod json;
16mod topology;
17
18pub use builder::*;
19use topology::*;
20
21/// Helper that converts an [`EntityTrait`](crate::EntityTrait) into different
22/// [`sea_query`] statements (CREATE TABLE / CREATE TYPE / etc) for a given
23/// [`DbBackend`].
24#[derive(Debug)]
25pub struct Schema {
26 backend: DbBackend,
27}
28
29impl Schema {
30 /// Create a helper for a specific database backend
31 pub fn new(backend: DbBackend) -> Self {
32 Self { backend }
33 }
34
35 /// Creates a schema builder that can apply schema changes to database
36 pub fn builder(self) -> SchemaBuilder {
37 SchemaBuilder::new(self)
38 }
39}