๐ We are pleased to release SeaQuery 0.26.0
! Here are some feature highlights ๐:
Dependency Upgradesโ
[#356] We have upgraded a few major dependencies:
- Upgrade
sqlx
to 0.6 - Upgrade
time
to 0.3 - Upgrade
uuid
to 1.0 - Upgrade
bigdecimal
to 0.3 - Upgrade
ipnetwork
to 0.19
Note that you might need to upgrade the corresponding dependency on your application as well.
VALUES listsโ
[#351] Add support for VALUES lists
// SELECT * FROM (VALUES (1, 'hello'), (2, 'world')) AS "x"
let query = SelectStatement::new()
.expr(Expr::asterisk())
.from_values(vec![(1i32, "hello"), (2, "world")], Alias::new("x"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT * FROM (VALUES (1, 'hello'), (2, 'world')) AS "x""#
);
Introduce sea-query-binderโ
[#273] Native support SQLx without marcos
use sea_query_binder::SqlxBinder;
// Create SeaQuery query with prepare SQLx
let (sql, values) = Query::select()
.columns([
Character::Id,
Character::Uuid,
Character::Character,
Character::FontSize,
Character::Meta,
Character::Decimal,
Character::BigDecimal,
Character::Created,
Character::Inet,
Character::MacAddress,
])
.from(Character::Table)
.order_by(Character::Id, Order::Desc)
.build_sqlx(PostgresQueryBuilder);
// Execute query
let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values)
.fetch_all(&mut pool)
.await?;
// Print rows
for row in rows.iter() {
println!("{:?}", row);
}
CASE WHEN statement supportโ
[#304] Add support for CASE WHEN
statement
let query = Query::select()
.expr_as(
CaseStatement::new()
.case(Expr::tbl(Glyph::Table, Glyph::Aspect).is_in(vec![2, 4]), Expr::val(true))
.finally(Expr::val(false)),
Alias::new("is_even")
)
.from(Glyph::Table)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT (CASE WHEN ("glyph"."aspect" IN (2, 4)) THEN TRUE ELSE FALSE END) AS "is_even" FROM "glyph""#
);
Add support for Ip(4,6)Network and MacAddressโ
[#309] Add support for Network types in PostgreSQL backend
Introduce sea-query-attrโ
[#296] Proc-macro for deriving Iden enum from struct
use sea_query::gen_type_def;
#[gen_type_def]
pub struct Hello {
pub name: String
}
println!("{:?}", HelloTypeDef::Name);
Add ability to alter foreign keysโ
[#299] Add support for ALTER
foreign Keys
let foreign_key_char = TableForeignKey::new()
.name("FK_character_glyph")
.from_tbl(Char::Table)
.from_col(Char::FontId)
.from_col(Char::Id)
.to_tbl(Glyph::Table)
.to_col(Char::FontId)
.to_col(Char::Id)
.to_owned();
let table = Table::alter()
.table(Character::Table)
.add_foreign_key(&foreign_key_char)
.to_owned();
assert_eq!(
table.to_string(PostgresQueryBuilder),
vec![
r#"ALTER TABLE "character""#,
r#"ADD CONSTRAINT "FK_character_glyph""#,
r#"FOREIGN KEY ("font_id", "id") REFERENCES "glyph" ("font_id", "id")"#,
r#"ON DELETE CASCADE ON UPDATE CASCADE,"#,
]
.join(" ")
);
Select DISTINCT ONโ
[#250]
let query = Query::select()
.from(Char::Table)
.distinct_on(vec![Char::Character])
.column(Char::Character)
.column(Char::SizeW)
.column(Char::SizeH)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT DISTINCT ON ("character") "character", "size_w", "size_h" FROM "character""#
);
Miscellaneous Enhancementsโ
- [#353] Support
LIKE ... ESCAPE ...
expression - [#306] Move
escape
andunescape
string to backend - [#365] Add method to make a column nullable
- [#348] Add
is
&is_not
to Expr - [#349] Add
CURRENT_TIMESTAMP
function - [#345] Add
in_tuple
method to Expr - [#266] Insert Default
- [#324] Make
sea-query-driver
an optional dependency - [#334] Add
ABS
function - [#332] Support
IF NOT EXISTS
when create index - [#314] Support different
blob
types in MySQL - [#331] Add
VarBinary
column type - [#335]
RETURNING
expression supportingSimpleExpr
Integration Examplesโ
SeaQuery plays well with the other crates in the rust ecosystem.
- Postgres Example
- Rusqlite Example
- SQLx Any Example
- SQLx Postgres Example
- SQLx MySql Example
- SQLx Sqlite Example
Communityโ
SeaQL is a community driven project. We welcome you to participate, contribute and together build for Rust's future.