Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diesel integration #658

Merged
merged 19 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ name: tests
on:
pull_request:
paths-ignore:
- '**.md'
- '.github/ISSUE_TEMPLATE/**'
- "**.md"
- ".github/ISSUE_TEMPLATE/**"
- .gitignore
push:
branches:
- master
- 0.*.x
- pr/**/ci
paths-ignore:
- '**.md'
- '.github/ISSUE_TEMPLATE/**'
- "**.md"
- ".github/ISSUE_TEMPLATE/**"
- .gitignore

concurrency:
Expand Down Expand Up @@ -135,6 +135,26 @@ jobs:
- run: cargo build --manifest-path sea-query-postgres/Cargo.toml --workspace --features=with-mac_address
- run: cargo build --manifest-path sea-query-postgres/Cargo.toml --workspace --features=postgres-array

diesel-build:
name: Build `sea-query-diesel`
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- run: cargo update --manifest-path sea-query-diesel/Cargo.toml --workspace -p bigdecimal:0.4.1 --precise 0.3.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be required anymore as diesel 2.1.1 added support for bigdecimal 0.4: https://crates.io/crates/diesel/2.1.1/dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha the issue is on sea-query side, they only support 0.3 and the resolver takes 0.4 for diesel so it causes a build failure because the types are incompatible. Its a PITA that we still don't have a way to pin a sub dependency without a lockfile.

- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-chrono,with-json,with-rust_decimal,with-bigdecimal,with-uuid,with-time,with-ipnetwork,with-mac_address,postgres-array
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-chrono
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-json
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-rust_decimal
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres --features=with-rust_decimal-postgres
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features mysql --features=with-rust_decimal-mysql
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-bigdecimal
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-uuid
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-time
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-ipnetwork
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=with-mac_address
- run: cargo build --manifest-path sea-query-diesel/Cargo.toml --workspace --features postgres,sqlite,mysql --features=postgres-array

test:
name: Unit Test
runs-on: ubuntu-latest
Expand All @@ -157,10 +177,11 @@ jobs:
sqlite:
name: SQLite
runs-on: ubuntu-latest
needs: ["test", "derive-test", "rusqlite-build", "binder-build"]
needs:
["test", "derive-test", "rusqlite-build", "binder-build", "diesel-build"]
strategy:
matrix:
example: [rusqlite, sqlx_sqlite]
example: [rusqlite, sqlx_sqlite, diesel_sqlite]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -170,11 +191,11 @@ jobs:
mysql:
name: MySQL
runs-on: ubuntu-latest
needs: ["test", "derive-test", "binder-build"]
needs: ["test", "derive-test", "binder-build", "diesel-build"]
strategy:
matrix:
version: [8.0, 5.7]
example: [sqlx_mysql]
example: [sqlx_mysql, diesel_mysql]
services:
mysql:
image: mysql:${{ matrix.version }}
Expand All @@ -200,11 +221,11 @@ jobs:
mariadb:
name: MariaDB
runs-on: ubuntu-latest
needs: ["test", "derive-test", "binder-build"]
needs: ["test", "derive-test", "binder-build", "diesel-build"]
strategy:
matrix:
version: [10.6]
example: [sqlx_mysql]
example: [sqlx_mysql, diesel_mysql]
services:
mariadb:
image: mariadb:${{ matrix.version }}
Expand All @@ -230,11 +251,12 @@ jobs:
postgres:
name: PostgreSQL
runs-on: ubuntu-latest
needs: ["test", "derive-test", "binder-build", "postgres-build"]
needs:
["test", "derive-test", "binder-build", "postgres-build", "diesel-build"]
strategy:
matrix:
version: [14.4, 13.7, 12.11]
example: [postgres, sqlx_postgres]
example: [postgres, sqlx_postgres, diesel_postgres]
services:
postgres:
image: postgres:${{ matrix.version }}
Expand All @@ -253,6 +275,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- if: ${{ matrix.example == 'diesel_postgres' }}
run: cargo update --manifest-path examples/${{ matrix.example }}/Cargo.toml -p bigdecimal:0.4.1 --precise 0.3.1
- run: cargo build --manifest-path examples/${{ matrix.example }}/Cargo.toml
- run: cargo run --manifest-path examples/${{ matrix.example }}/Cargo.toml

Expand Down
26 changes: 26 additions & 0 deletions examples/diesel_mysql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[workspace]
# A separate workspace

[package]
name = "sea-query-diesel-mysql-example"
version = "0.1.0"
edition = "2021"

[dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock"] }
time = { version = "0.3", features = ["parsing", "macros"] }
serde_json = { version = "1" }
uuid = { version = "1", features = ["serde", "v4"] }
diesel = { version = "2.1.1", features = ["mysql"] }
sea-query = { path = "../.." }
sea-query-diesel = { path = "../../sea-query-diesel", features = [
"mysql",
"with-chrono",
"with-json",
"with-uuid",
"with-time",
] }

# NOTE: if you are copying this example into your own project, use the following line instead:
# sea-query = { version = "0"}
# sea-query-diesel = { version = "0", features = [...] }
35 changes: 35 additions & 0 deletions examples/diesel_mysql/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SeaQuery Diesel MySQL example

Running:

```sh
cargo run
```

Example output:

```
Create table character: Ok(())

Insert into character Ok(4)

Select one from character:
CharacterStructChrono { id: 4, uuid: UUID(3a23c42d-8cd9-4a0f-a8c3-0ced15d42228), name: "A", font_size: 12, meta: Object {"notes": String("some notes here")}, created: Some(2020-01-01T02:02:02) }

Select one from character:
CharacterStructTime { id: 4, uuid: UUID(3a23c42d-8cd9-4a0f-a8c3-0ced15d42228), name: "A", font_size: 12, meta: Object {"notes": String("some notes here")}, created: Some(2020-01-01 2:02:02.0) }


Update character: Ok(1)

Select one from character:
CharacterStructChrono { id: 4, uuid: UUID(3a23c42d-8cd9-4a0f-a8c3-0ced15d42228), name: "A", font_size: 24, meta: Object {"notes": String("some notes here")}, created: Some(2020-01-01T02:02:02) }

Select one from character:
CharacterStructTime { id: 4, uuid: UUID(3a23c42d-8cd9-4a0f-a8c3-0ced15d42228), name: "A", font_size: 24, meta: Object {"notes": String("some notes here")}, created: Some(2020-01-01 2:02:02.0) }


Count character: Ok(CountField { count: 4 })

Delete character: Ok(1)
```
Loading