Skip to content

Commit

Permalink
Diesel integration (#658)
Browse files Browse the repository at this point in the history
* feat: Prepare new crate for diesel

* feat: add sqlite support for diesel integration

* fix: diesel sqlite change some type mapping

* fix: More sqlite fixes

* feat: add mysql support for diesel integration

* fix: Multiple small fixes to diesel integration

* feat: add postgres support for diesel integration

* chore: add diesel mysql example

* chore: add diesel postgres example

* fix: remove defaults for diesel integration

* chore: add diesel sqlite example

* fix: fix diesel postgres example missing features

* chore: use official diesel commit

* Add diesel to build

* Update Diesel version

* Fix workflow expression

* Fix problem with bigdecimal build

* Remove useless install step

* Simplify update logic
  • Loading branch information
Sytten authored Sep 8, 2023
1 parent edf747b commit 92b0220
Show file tree
Hide file tree
Showing 18 changed files with 1,862 additions and 12 deletions.
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
- 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

0 comments on commit 92b0220

Please sign in to comment.