Skip to content

Commit

Permalink
Merge branch 'SeaQL:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai authored Jul 15, 2023
2 parents 405f0f6 + b7e5413 commit 13ad352
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 27 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/release-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
message: |
### :tada: Released In [${releaseTag}](${releaseUrl}) :tada:
Your participation is what makes us unique; your adoption is what drives us forward.
Thank you all in the Rust community for making SeaQL what it is today. :crab:
You are also invited to shape it's future! Please star our repos, every ⭐ counts!
Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --package sea-query-derive --all-features
- run: cargo test --package sea-query-derive --all-features
- run: cargo build --package sea-query-derive
- run: cargo test --package sea-query-derive

sqlite:
name: SQLite
Expand Down
31 changes: 26 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 0.29.0 - Pending
## 0.29.1 - 2023-07-12

+ 2023-03-22: `0.29.0-rc.1`
+ `0.29.0-rc.1`: 2023-03-22
+ `0.29.0`: Yanked

### New Features

* Added `ValueTuple::Many` for tuple with length up to 12 https://github.com/SeaQL/sea-query/pull/564
* Added create Table `CHECK` Constraints https://github.com/SeaQL/sea-query/pull/567
* Added `CREATE TABLE CHECK` constraints https://github.com/SeaQL/sea-query/pull/567
* Added support generated column spec https://github.com/SeaQL/sea-query/pull/581
* Added `BIT_AND`, `BIT_OR` functions https://github.com/SeaQL/sea-query/pull/582
* Added implementation `SqlxBinder`, `RusqliteBinder` and `PostgresBinder` for `WithQuery` https://github.com/SeaQL/sea-query/pull/580
* Added new type `Asteriks` https://github.com/SeaQL/sea-query/pull/596
* Added `IF NOT EXISTS` for `DROP INDEX` in Postgres and Sqlite https://github.com/SeaQL/sea-query/pull/610
* Added `->` and `->>` operators for Postgres https://github.com/SeaQL/sea-query/pull/617/files
* Added `->` and `->>` operators for Postgres https://github.com/SeaQL/sea-query/pull/617
* Added `TableCreateStatement::set_extra` and `TableCreateStatement::get_extra` https://github.com/SeaQL/sea-query/pull/611
* Added `TableCreateStatement::comment` and `ColumnDef::comment` for MySQL comments https://github.com/SeaQL/sea-query/pull/622
* Added `PgExpr::get_json_field` and `PgExpr::cast_json_field` methods for constructing Postgres JSON expressions https://github.com/SeaQL/sea-query/pull/630
* Added `PgBinOper::Regex` and `PgBinOper::RegexCaseInsensitive` for Postgres Regex operators
* Added `BinOper::Custom` for defining custom binary operators
* Added `GLOB` operator for Sqlite https://github.com/SeaQL/sea-query/pull/651/
* Added `CREATE or DROP EXTENSION` statements for Postgres https://github.com/SeaQL/sea-query/pull/616
* Added a feature flag `hashable-value`, which will `impl Hash for Value`; when enabled, `Value::Float(NaN) == Value::Float(NaN)` would be true https://github.com/SeaQL/sea-query/pull/598
* Added `PgBinOper::Overlap` for Postgres operators https://github.com/SeaQL/sea-query/pull/653

### Enhancements

* Implemented `PartialEq` for `DynIden`, `SimpleExpr` and related types https://github.com/SeaQL/sea-query/pull/620

### Breaking changes

* Removed variants `Four, Five, Six` from `enum ValueTuple` as part of https://github.com/SeaQL/sea-query/pull/564
* Removed `Expr::tbl`, `Expr::greater_than`, `Expr::greater_or_equal`, `Expr::less_than`, `Expr::less_or_equal`, `Expr::into_simple_expr` https://github.com/SeaQL/sea-query/pull/551
* Removed `SimpleExpr::equals` and `SimpleExpr::not_equals` https://github.com/SeaQL/sea-query/pull/551
* Removed `InsertStatement::exprs`, `InsertStatement::exprs_panic` https://github.com/SeaQL/sea-query/pull/551
Expand All @@ -56,6 +61,22 @@ let _: DynIden = Rc::new(Alias::new("char"));
// replace with:
let _: DynIden = SeaRc::new(Alias::new("char"));
```
* Added new type `Quote` and changed the `Iden` trait:
```rust
struct Quote(pub(crate) u8, pub(crate) u8);

trait Iden {
// then:
fn prepare(&self, s: &mut dyn fmt::Write, q: char);
// now:
fn prepare(&self, s: &mut dyn fmt::Write, q: Quote);

// then:
fn quoted(&self, q: char) -> String;
// now:
fn quoted(&self, q: Quote) -> String;
}
```

### House keeping

Expand Down Expand Up @@ -595,7 +616,7 @@ In order to co-exist with the `time` crate, `Date`, `Time`, `DateTime` etc are r

### Bug Fixes

* Fix PostgreSQL `ColumnType::TinyInteger` mapping by @billy1624 in https://github.com/SeaQL/sea-query/pull/207
* Fix Postgres `ColumnType::TinyInteger` mapping by @billy1624 in https://github.com/SeaQL/sea-query/pull/207
* PR without clippy warmings in file changed tab by @billy1624 in https://github.com/SeaQL/sea-query/pull/212

**Full Changelog**: https://github.com/SeaQL/sea-query/compare/0.20.0...0.21.0
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "sea-query-derive"]

[package]
name = "sea-query"
version = "0.29.0"
version = "0.29.1"
authors = [
"Chris Tsang <[email protected]>",
"Billy Chan <[email protected]>",
Expand All @@ -30,7 +30,7 @@ path = "src/lib.rs"
[dependencies]
inherent = "1.0"
sea-query-attr = { version = "0.1.1", path = "sea-query-attr", default-features = false, optional = true }
sea-query-derive = { version = "0.3.0", path = "sea-query-derive", default-features = false, optional = true }
sea-query-derive = { version = "0.4.0", path = "sea-query-derive", default-features = false, optional = true }
serde_json = { version = "1", default-features = false, optional = true, features = ["std"] }
derivative = { version = "2.2", default-features = false, optional = true }
chrono = { version = "0.4", default-features = false, optional = true, features = ["clock"] }
Expand Down
6 changes: 0 additions & 6 deletions build-tools/cargo-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@ set -e
cd sea-query-attr
cargo publish
cd ..
# sleep 30

# publish `sea-query-derive`
cd sea-query-derive
cargo publish
cd ..
# sleep 30

# publish `sea-query`
cargo publish
# sleep 30

# publish `sea-query-binder`
cd sea-query-binder
cargo publish
cd ..
# sleep 30

# publish `sea-query-rusqlite`
cd sea-query-rusqlite
cargo publish
cd ..
# sleep 30

# publish `sea-query-postgres`
cd sea-query-postgres
cargo publish
cd ..
# sleep 30
2 changes: 1 addition & 1 deletion sea-query-attr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ darling = { version = "0.14", default-features = false }
[dev-dependencies]
trybuild = "1.0"
sea-query = { version = "0", path = ".." }
strum = { version = "0.24", features = ["derive"] }
strum = { version = "0.25", features = ["derive"] }
7 changes: 5 additions & 2 deletions sea-query-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sea-query-derive"
version = "0.3.0"
version = "0.4.0"
authors = [ "Follpvosten <[email protected]>", "Rene Leveille <[email protected]>" ]
edition = "2021"
description = "Derive macro for sea-query's Iden trait"
Expand All @@ -24,4 +24,7 @@ thiserror = { version = "1.0", default-features = false }
[dev-dependencies]
trybuild = "1.0"
sea-query = { version = "0", path = ".." }
strum = { version = "0.24", features = ["derive"] }
strum = { version = "0.25", features = ["derive"] }

[features]
sea-orm = []
27 changes: 21 additions & 6 deletions sea-query-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ fn impl_iden_for_unit_struct(
ident: &proc_macro2::Ident,
table_name: &str,
) -> proc_macro2::TokenStream {
let sea_query_path = sea_query_path();

let prepare = if must_be_valid_iden(table_name) {
quote! {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: sea_query::Quote) {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: #sea_query_path::Quote) {
write!(s, "{}", q.left()).unwrap();
self.unquoted(s);
write!(s, "{}", q.right()).unwrap();
Expand All @@ -57,8 +59,9 @@ fn impl_iden_for_unit_struct(
} else {
quote! {}
};

quote! {
impl sea_query::Iden for #ident {
impl #sea_query_path::Iden for #ident {
#prepare

fn unquoted(&self, s: &mut dyn ::std::fmt::Write) {
Expand All @@ -76,6 +79,8 @@ fn impl_iden_for_enum<'a, T>(
where
T: Iterator<Item = &'a Variant>,
{
let sea_query_path = sea_query_path();

let mut is_all_valid = true;

let match_arms = match variants
Expand All @@ -93,7 +98,7 @@ where

let prepare = if is_all_valid {
quote! {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: sea_query::Quote) {
fn prepare(&self, s: &mut dyn ::std::fmt::Write, q: #sea_query_path::Quote) {
write!(s, "{}", q.left()).unwrap();
self.unquoted(s);
write!(s, "{}", q.right()).unwrap();
Expand All @@ -104,7 +109,7 @@ where
};

quote! {
impl sea_query::Iden for #ident {
impl #sea_query_path::Iden for #ident {
#prepare

fn unquoted(&self, s: &mut dyn ::std::fmt::Write) {
Expand Down Expand Up @@ -151,6 +156,8 @@ pub fn derive_iden(input: TokenStream) -> TokenStream {

#[proc_macro_derive(IdenStatic, attributes(iden, method))]
pub fn derive_iden_static(input: TokenStream) -> TokenStream {
let sea_query_path = sea_query_path();

let DeriveInput {
ident, data, attrs, ..
} = parse_macro_input!(input);
Expand All @@ -173,7 +180,7 @@ pub fn derive_iden_static(input: TokenStream) -> TokenStream {
return quote! {
#impl_iden

impl sea_query::IdenStatic for #ident {
impl #sea_query_path::IdenStatic for #ident {
fn as_str(&self) -> &'static str {
#table_name
}
Expand Down Expand Up @@ -212,7 +219,7 @@ pub fn derive_iden_static(input: TokenStream) -> TokenStream {
let output = quote! {
#impl_iden

impl sea_query::IdenStatic for #ident {
impl #sea_query_path::IdenStatic for #ident {
fn as_str(&self) -> &'static str {
match self {
#match_arms
Expand All @@ -229,3 +236,11 @@ pub fn derive_iden_static(input: TokenStream) -> TokenStream {

output.into()
}

fn sea_query_path() -> proc_macro2::TokenStream {
if cfg!(feature = "sea-orm") {
quote!(sea_orm::sea_query)
} else {
quote!(sea_query)
}
}
1 change: 1 addition & 0 deletions src/backend/postgres/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl QueryBuilder for PostgresQueryBuilder {
PgBinOper::Contains => "@>",
PgBinOper::Contained => "<@",
PgBinOper::Concatenate => "||",
PgBinOper::Overlap => "&&",
PgBinOper::Similarity => "%",
PgBinOper::WordSimilarity => "<%",
PgBinOper::StrictWordSimilarity => "<<%",
Expand Down
1 change: 1 addition & 0 deletions src/extension/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum PgBinOper {
Contains,
Contained,
Concatenate,
Overlap,
Similarity,
WordSimilarity,
StrictWordSimilarity,
Expand Down
45 changes: 45 additions & 0 deletions tests/postgres/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,51 @@ fn sub_query_with_fn() {
);
}

#[test]
fn select_array_contains_bin_oper() {
assert_eq!(
Query::select()
.column(Char::Character)
.from(Char::Table)
.and_where(Expr::col(Char::Character).binary(PgBinOper::Contains, Expr::val("test")))
.build(PostgresQueryBuilder),
(
r#"SELECT "character" FROM "character" WHERE "character" @> $1"#.to_owned(),
Values(vec!["test".into()])
)
);
}

#[test]
fn select_array_contained_bin_oper() {
assert_eq!(
Query::select()
.column(Char::Character)
.from(Char::Table)
.and_where(Expr::col(Char::Character).binary(PgBinOper::Contained, Expr::val("test")))
.build(PostgresQueryBuilder),
(
r#"SELECT "character" FROM "character" WHERE "character" <@ $1"#.to_owned(),
Values(vec!["test".into()])
)
);
}

#[test]
fn select_array_overlap_bin_oper() {
assert_eq!(
Query::select()
.column(Char::Character)
.from(Char::Table)
.and_where(Expr::col(Char::Character).binary(PgBinOper::Overlap, Expr::val("test")))
.build(PostgresQueryBuilder),
(
r#"SELECT "character" FROM "character" WHERE "character" && $1"#.to_owned(),
Values(vec!["test".into()])
)
);
}

#[test]
fn get_json_field_bin_oper() {
assert_eq!(
Expand Down

0 comments on commit 13ad352

Please sign in to comment.