Skip to content

Commit

Permalink
Upgrade to SQLx v0.7 (#652)
Browse files Browse the repository at this point in the history
* Upgrade to SQLx v0.7

* Upgrade ipnetwork to v0.20

* Encode chrono types in Any driver as string

* Temporary enable `sqlx/bigdecimal` feature when `with-rust_decimal` is enabled (launchbadge/sqlx#2549)

* Fixup

* Fixup

* Fixup

* CI

* Fixup

* Revert "Temporary enable `sqlx/bigdecimal` feature when `with-rust_decimal` is enabled (launchbadge/sqlx#2549)"

This reverts commit fa50aa2.

* CI fmt checks

* Bump `sea-query-binder` to v0.5.0

* Refactor
  • Loading branch information
billy1624 committed Jul 20, 2023
1 parent b7e5413 commit 02ab378
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 56 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ jobs:
with:
toolchain: nightly
components: rustfmt
- run: cargo fmt --all -- --check
- run: cargo fmt --manifest-path Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-attr/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-binder/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-rusqlite/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-derive/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-postgres/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path sea-query-rusqlite/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/sqlx_sqlite/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/sqlx_any/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/rusqlite/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/sqlx_postgres/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/postgres/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/sqlx_mysql/Cargo.toml --all -- --check

clippy:
name: Clippy
Expand Down Expand Up @@ -247,3 +255,12 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --manifest-path examples/${{ matrix.example }}/Cargo.toml
- run: cargo run --manifest-path examples/${{ matrix.example }}/Cargo.toml

any:
name: Any
runs-on: ubuntu-latest
needs: ["test", "derive-test", "binder-build"]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --manifest-path examples/sqlx_any/Cargo.toml
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ uuid = { version = "1", default-features = false, optional = true }
proc-macro2 = { version = "1", default-features = false, optional = true }
quote = { version = "1", default-features = false, optional = true }
time = { version = "0.3", default-features = false, optional = true, features = ["macros", "formatting"] }
ipnetwork = { version = "0.19", default-features = false, optional = true }
ipnetwork = { version = "0.20", default-features = false, optional = true }
mac_address = { version = "1.1", default-features = false, optional = true }
ordered-float = { version = "3.4", default-features = false, optional = true }

Expand Down
2 changes: 1 addition & 1 deletion examples/sqlx_any/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_json = "1"
rust_decimal = { version = "1" }
bigdecimal = { version = "0.3" }
async-std = { version = "1.8", features = [ "attributes" ] }
sqlx = "0.6"
sqlx = "0.7"
sea-query = { path = "../../" }
sea-query-binder = { path = "../../sea-query-binder", features = [
"sqlx-postgres",
Expand Down
22 changes: 11 additions & 11 deletions examples/sqlx_any/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{NaiveDate, NaiveDateTime};
use chrono::NaiveDate;
use sea_query::{
ColumnDef, Expr, Func, Iden, MysqlQueryBuilder, OnConflict, Order, PostgresQueryBuilder, Query,
QueryBuilder, SchemaBuilder, SqliteQueryBuilder, Table,
Expand Down Expand Up @@ -65,7 +65,7 @@ async fn main() {
.col(ColumnDef::new(Character::Created).date_time())
.build_any(schema_builder);

let result = sqlx::query(&sql).execute(&mut pool).await;
let result = sqlx::query(&sql).execute(&mut *pool).await;
println!("Create table character: {result:?}\n");

// Create
Expand All @@ -90,7 +90,7 @@ async fn main() {
.build_any_sqlx(query_builder);

let row = sqlx::query_with(&sql, values)
.fetch_one(&mut pool)
.fetch_one(&mut *pool)
.await
.unwrap();
let id: i32 = row.try_get(0).unwrap();
Expand All @@ -111,7 +111,7 @@ async fn main() {
.build_any_sqlx(query_builder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -128,7 +128,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_any_sqlx(query_builder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Update character: {result:?}\n");

// Read
Expand All @@ -146,7 +146,7 @@ async fn main() {
.build_any_sqlx(query_builder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -163,7 +163,7 @@ async fn main() {
.build_any_sqlx(query_builder);

let row = sqlx::query_with(&sql, values)
.fetch_one(&mut pool)
.fetch_one(&mut *pool)
.await
.unwrap();
print!("Count character: ");
Expand All @@ -184,7 +184,7 @@ async fn main() {
)
.build_any_sqlx(query_builder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Insert into character (with upsert): {result:?}\n");

// Read
Expand All @@ -201,7 +201,7 @@ async fn main() {
.build_any_sqlx(query_builder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -217,7 +217,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_any_sqlx(query_builder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Delete character: {result:?}");
}

Expand All @@ -236,5 +236,5 @@ struct CharacterStructChrono {
id: i32,
character: String,
font_size: i32,
created: NaiveDateTime,
created: String,
}
2 changes: 1 addition & 1 deletion examples/sqlx_mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde_json = "1"
rust_decimal = { version = "1" }
bigdecimal = { version = "0.3" }
async-std = { version = "1.8", features = [ "attributes" ] }
sqlx = "0.6"
sqlx = "0.7"
sea-query = { path = "../../" }
sea-query-binder = { path = "../../sea-query-binder", features = [
"sqlx-mysql",
Expand Down
24 changes: 12 additions & 12 deletions examples/sqlx_mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() {
.col(ColumnDef::new(Character::Created).date_time())
.build(MysqlQueryBuilder);

let result = sqlx::query(&sql).execute(&mut pool).await;
let result = sqlx::query(&sql).execute(&mut *pool).await;
println!("Create table character: {result:?}\n");

// Create
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn main() {
])
.build_sqlx(MysqlQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Insert into character: {result:?}\n");
let id = result.unwrap().last_insert_id();

Expand All @@ -115,7 +115,7 @@ async fn main() {
.build_sqlx(MysqlQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -125,7 +125,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -142,7 +142,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(MysqlQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Update character: {result:?}\n");

// Read
Expand All @@ -164,7 +164,7 @@ async fn main() {
.build_sqlx(MysqlQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -174,7 +174,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -197,7 +197,7 @@ async fn main() {
)
.build_sqlx(MysqlQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Insert into character (with upsert): {result:?}\n");
let id = result.unwrap().last_insert_id();

Expand All @@ -219,7 +219,7 @@ async fn main() {
.build_sqlx(MysqlQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -229,7 +229,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -246,7 +246,7 @@ async fn main() {
.build_sqlx(MysqlQueryBuilder);

let row = sqlx::query_with(&sql, values)
.fetch_one(&mut pool)
.fetch_one(&mut *pool)
.await
.unwrap();
print!("Count character: ");
Expand All @@ -261,7 +261,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(MysqlQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Delete character: {result:?}");
}

Expand Down
4 changes: 2 additions & 2 deletions examples/sqlx_postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ uuid = { version = "1", features = ["serde", "v4"] }
serde_json = "1"
rust_decimal = { version = "1" }
bigdecimal = { version = "0.3" }
ipnetwork = { version = "0.19" }
ipnetwork = { version = "0.20" }
mac_address = { version = "1.1" }
async-std = { version = "1.8", features = [ "attributes" ] }
sqlx = "0.6"
sqlx = "0.7"
sea-query = { path = "../../" }
sea-query-binder = { path = "../../sea-query-binder", features = [
"sqlx-postgres",
Expand Down
24 changes: 12 additions & 12 deletions examples/sqlx_postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() {
.col(ColumnDef::new(Character::MacAddress).mac_address())
.build(PostgresQueryBuilder);

let result = sqlx::query(&sql).execute(&mut pool).await;
let result = sqlx::query(&sql).execute(&mut *pool).await;
println!("Create table character: {result:?}\n");

// Create
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn main() {
.build_sqlx(PostgresQueryBuilder);

let row = sqlx::query_with(&sql, values)
.fetch_one(&mut pool)
.fetch_one(&mut *pool)
.await
.unwrap();
let id: i32 = row.try_get(0).unwrap();
Expand All @@ -138,7 +138,7 @@ async fn main() {
.build_sqlx(PostgresQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -148,7 +148,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -165,7 +165,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(PostgresQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Update character: {result:?}\n");

// Read
Expand All @@ -189,7 +189,7 @@ async fn main() {
.build_sqlx(PostgresQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -199,7 +199,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -216,7 +216,7 @@ async fn main() {
.build_sqlx(PostgresQueryBuilder);

let row = sqlx::query_with(&sql, values)
.fetch_one(&mut pool)
.fetch_one(&mut *pool)
.await
.unwrap();
print!("Count character: ");
Expand All @@ -238,7 +238,7 @@ async fn main() {
)
.build_sqlx(PostgresQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Insert into character (with upsert): {result:?}\n");

// Read
Expand All @@ -261,7 +261,7 @@ async fn main() {
.build_sqlx(PostgresQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -271,7 +271,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values)
.fetch_all(&mut pool)
.fetch_all(&mut *pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -287,7 +287,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(PostgresQueryBuilder);

let result = sqlx::query_with(&sql, values).execute(&mut pool).await;
let result = sqlx::query_with(&sql, values).execute(&mut *pool).await;
println!("Delete character: {result:?}");
}

Expand Down
2 changes: 1 addition & 1 deletion examples/sqlx_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ time = { version = "0.3", features = ["macros"] }
uuid = { version = "1", features = ["serde", "v4"] }
serde_json = "1"
async-std = { version = "1.8", features = [ "attributes" ] }
sqlx = "0.6.1"
sqlx = "0.7"
sea-query = { path = "../../" }
sea-query-binder = { path = "../../sea-query-binder", features = [
"sqlx-sqlite",
Expand Down
Loading

0 comments on commit 02ab378

Please sign in to comment.