Skip to main content

🐚 SeaORM X is built on top of SeaORM with support for SQL Server


Native MSSQL Driver

Powered by SQLz with connection pooling, nested transactions via savepoints, and automatic schema rewriting.

Built on SeaORM 2.0

Every 2.0 feature ships to MSSQL: Entity Loader, Nested ActiveModel, strongly-typed COLUMN, and raw_sql! macro.

Schema First or Entity First

Generate entities from existing MSSQL schemas with sea-orm-cli, or define entities in Rust and sync to the database.

Service Oriented

Build services that join, filter, sort and paginate data in REST, GraphQL and gRPC APIs. Works with Actix, Axum, Loco, Poem, and more.

SeaORM X in action

// A table create statement
let table = Table::create()
.table(Glyph::Table)
.col(ColumnDef::new(Glyph::Id).integer().not_null().auto_increment().primary_key())
.col(ColumnDef::new(Glyph::Aspect).integer().not_null())
.col(ColumnDef::new(Glyph::Image).string().not_null())
.foreign_key(
ForeignKey::create()
.name("FK_2e303c3a712662f1fc2a4d0aad6")
.from(Glyph::Table, Glyph::Id)
.to(CharGlyph::Table, CharGlyph::GlyphId)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade)
)
.to_owned();
assert_eq!(
table.to_string(MsSqlQueryBuilder),
[
r#"CREATE TABLE [glyph] ("#,
r#"[id] int NOT NULL IDENTITY PRIMARY KEY,"#,
r#"[aspect] int NOT NULL,"#,
r#"[image] nvarchar(255) NOT NULL,"#,
r#"CONSTRAINT [FK_2e303c3a712662f1fc2a4d0aad6]"#,
r#"FOREIGN KEY ([id]) REFERENCES [character_glyph] ([glyph_id])"#,
r#"ON DELETE CASCADE ON UPDATE CASCADE"#,
r#")"#,
].join(" ")
);
// A prepared select statement
assert_eq!(
Query::select()
.column(Glyph::Image)
.from(Glyph::Table)
.and_where(Expr::col(Glyph::Image).like("A"))
.and_where(Expr::col(Glyph::Id).is_in([1, 2, 3]))
.build(MsSqlQueryBuilder),
(
"SELECT [image] FROM [glyph] WHERE [image] LIKE @P1 AND [id] IN (@P2, @P3, @P4)"
.to_owned(),
Values(vec![
Value::String(Some(Box::new("A".to_owned()))),
Value::Int(Some(1)),
Value::Int(Some(2)),
Value::Int(Some(3))
])
)
);
// A raw select statement
assert_eq!(
Query::select()
.column(Glyph::Id)
.from(Glyph::Table)
.cond_where(
Cond::any()
.add(
Cond::all()
.add(Expr::col(Glyph::Aspect).is_null())
.add(Expr::col(Glyph::Image).is_null())
)
.add(
Cond::all()
.add(Expr::col(Glyph::Aspect).is_in([3, 4]))
.add(Expr::col(Glyph::Image).like("A%"))
)
)
.to_string(MsSqlQueryBuilder),
[
r#"SELECT [id] FROM [glyph]"#,
r#"WHERE ([aspect] IS NULL AND [image] IS NULL)"#,
r#"OR ([aspect] IN (3, 4) AND [image] LIKE 'A%')"#,
]
.join(" ")
);

Meet Terres, our official mascot

A friend of Ferris, Terres the hermit crab is a member of the Rustacean family.