ð我们很高兴发布Seaquery koude0!这是一些功能亮点ð:
静态标识符的新的IdenStatic
特征
[#508]代表带有&'static str
的标识符。 IdenStatic
特征看起来像这样:
pub trait IdenStatic: Iden + Copy + 'static {
fn as_str(&self) -> &'static str;
}
您可以轻松地为现有的Iden
得出它。只是将#[derive(Iden)]
更改为#[derive(IdenStatic)]
。
#[derive(IdenStatic)]
enum User {
Table,
Id,
FirstName,
LastName,
#[iden = "_email"]
Email,
}
assert_eq!(User::Email.as_str(), "_email");
新的PgExpr
和SqliteExpr
特征用于后端特定表达
[#519] Postgres特定和SQLite特定表达式正在移动到其相应的性状中。您需要在使用这些后端特定方法构造表达式之前将特征导入范围。
// Importing `PgExpr` trait before constructing Postgres expression
use sea_query::{extension::postgres::PgExpr, tests_cfg::*, *};
let query = Query::select()
.columns([Font::Name, Font::Variant, Font::Language])
.from(Font::Table)
.and_where(Expr::val("a").concatenate("b").concat("c").concat("d"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "name", "variant", "language" FROM "font" WHERE 'a' || 'b' || 'c' || 'd'"#
);
// Importing `SqliteExpr` trait before constructing SQLite expression
use sea_query::{extension::sqlite::SqliteExpr, tests_cfg::*, *};
let query = Query::select()
.column(Font::Name)
.from(Font::Table)
.and_where(Expr::col(Font::Name).matches("a"))
.to_owned();
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "name" FROM "font" WHERE "name" MATCH 'a'"#
);
Bug修复
- 将工会包裹在括号中https://github.com/SeaQL/sea-query/pull/498
- 在空条件上的语法错误https://github.com/SeaQL/sea-query/pull/505
// given
let (statement, values) = sea_query::Query::select()
.column(Glyph::Id)
.from(Glyph::Table)
.cond_where(Cond::any()
.add(Cond::all()) // empty all() => TRUE
.add(Cond::any()) // empty any() => FALSE
)
.build(sea_query::MysqlQueryBuilder);
// old behavior
assert_eq!(statement, r#"SELECT `id` FROM `glyph`"#);
// new behavior
assert_eq!(
statement,
r#"SELECT `id` FROM `glyph` WHERE (TRUE) OR (FALSE)"#
);
// a complex example
let (statement, values) = Query::select()
.column(Glyph::Id)
.from(Glyph::Table)
.cond_where(
Cond::all()
.add(Cond::all().not())
.add(Cond::any().not())
.not(),
)
.build(MysqlQueryBuilder);
assert_eq!(
statement,
r#"SELECT `id` FROM `glyph` WHERE NOT ((NOT TRUE) AND (NOT FALSE))"#
);
打破变化
- [#535] MSRV高达1.62
# Make sure you're running SeaQuery with Rust 1.62+ 🦀
$ rustup update
- [#492]
ColumnType::Array
定义从Array(SeaRc<Box<ColumnType>>)
更改为Array(SeaRc<ColumnType>)
1111 - [#475]
Func::*
现在返回FunctionCall
而不是SimpleExpr
- [#475]
Func::coalesce
现在接受IntoIterator<Item = SimpleExpr>
而不是IntoIterator<Item = Into<SimpleExpr>
- [#475]删除了
Expr::arg
和Expr::args
-不再需要这些功能 - [#507]将所有Postgres特定的操作员移至
PgBinOper
- [#476]
Expr
用于接受Into<Value>
的方法现在接受Into<SimpleExpr>
- [#476]
Expr::is_in
,Expr::is_not_in
现在接受Into<SimpleExpr>
而不是Into<Value>
并将其转换为SimpleExpr::Tuple
而不是SimpleExpr::Values
- [#475]
Expr::expr
现在接受Into<SimpleExpr>
而不是SimpleExpr
- [#519]将Postgres特定的
Expr
方法移至新特征PgExpr
- [#528]
Expr::equals
现在接受C: IntoColumnRef
而不是T: IntoIden, C: IntoIden
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(
Expr::col((Char::Table, Char::FontId))
- .equals(Font::Table, Font::Id)
+ .equals((Font::Table, Font::Id))
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`font_id` = `font`.`id`"#
);
- [#525]删除了整数和日期时间列类型的显示长度 /精度选项< / li>
API添加
- [#475]添加了
SelectStatement::from_function
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.column(ColumnRef::Asterisk)
.from_function(Func::random(), Alias::new("func"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT * FROM RAND() AS `func`"#
);
- [#486]添加了Postgres
pg_trgm
扩展的二进制运算符
use sea_query::extension::postgres::PgBinOper;
assert_eq!(
Query::select()
.expr(Expr::col(Font::Name).binary(PgBinOper::WordSimilarity, Expr::value("serif")))
.from(Font::Table)
.to_string(PostgresQueryBuilder),
r#"SELECT "name" <% 'serif' FROM "font""#
);
use sea_query::extension::sqlite::SqliteBinOper;
assert_eq!(
Query::select()
.column(Char::Character)
.from(Char::Table)
.and_where(Expr::col(Char::Character).binary(SqliteBinOper::Match, Expr::val("test")))
.build(SqliteQueryBuilder),
(
r#"SELECT "character" FROM "character" WHERE "character" MATCH ?"#.to_owned(),
Values(vec!["test".into()])
)
);
- [#497]添加了
FULL OUTER JOIN
- [#530]添加了
PgFunc::get_random_uuid
- [#528]添加了
SimpleExpr::eq
,SimpleExpr::ne
,Expr::not_equals
- [#529]添加了
PgFunc::starts_with
- [#535]添加了
Expr::custom_keyword
和SimpleExpr::not
use sea_query::*;
let query = Query::select()
.expr(Expr::custom_keyword(Alias::new("test")))
.to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT test"#);
- [#539]添加了
SimpleExpr::like
,SimpleExpr::not_like
和Expr::cast_as
- [#532]添加了对Postgres的
NULLS NOT DISTINCT
条款的支持 - [#531]添加了
Expr::cust_with_expr
和Expr::cust_with_exprs
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::cust_with_expr("data @? ($1::JSONPATH)", "hello"))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT data @? ('hello'::JSONPATH)"#
);
- [#538]增加了将
&String
转换为Value 的支持
杂项增强
- [#475]保持功能和参数的新结构
FunctionCall
- [#503]支持
BigDecimal
,IpNetwork
和MacAddress
forsea-query-postgres
- [#511]使
value::with_array
模块公开,因此将NotU8
特质公开 - [#524]删除
Sized
对SchemaBuilders
实施者的要求
集成示例
Seaquery与Rust生态系统中的其他板条箱一起运行得很好。
- Postgres Example
- Rusqlite Example
- SQLx Any Example
- SQLx Postgres Example
- SQLx MySql Example
- SQLx Sqlite Example
社区
SEAQL是一个社区驱动的项目。我们欢迎您参加,为Rust的未来做出贡献和共同建立。