Skip to content

Commit

Permalink
Merge pull request #704 from SeaQL/diesel
Browse files Browse the repository at this point in the history
Diesel Integration
  • Loading branch information
tyt2y3 committed Sep 23, 2023
1 parent fe2d243 commit d179e82
Show file tree
Hide file tree
Showing 18 changed files with 1,988 additions and 0 deletions.
162 changes: 162 additions & 0 deletions .github/workflows/diesel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: diesel-tests

on:
pull_request:
paths:
- '.github/workflows/diesel.yml'
- 'examples/diesel_*/**'
- 'sea-query-diesel/**'
push:
branches:
- master
- 0.*.x
- pr/**/ci
- ci-*
paths:
- '.github/workflows/diesel.yml'
- 'examples/diesel_*/**'
- 'sea-query-diesel/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- run: cargo fmt --manifest-path examples/diesel_sqlite/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/diesel_postgres/Cargo.toml --all -- --check
- run: cargo fmt --manifest-path examples/diesel_mysql/Cargo.toml --all -- --check

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

sqlite:
name: SQLite
runs-on: ubuntu-latest
needs: diesel-build
strategy:
matrix:
example: [diesel_sqlite]
steps:
- uses: actions/checkout@v3
- 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

mysql:
name: MySQL
runs-on: ubuntu-latest
needs: diesel-build
strategy:
matrix:
version: [8.0, 5.7]
example: [diesel_mysql]
services:
mysql:
image: mysql:${{ matrix.version }}
env:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: query
MYSQL_USER: sea
MYSQL_PASSWORD: sea
MYSQL_ROOT_PASSWORD: sea
ports:
- "3306:3306"
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v3
- 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

mariadb:
name: MariaDB
runs-on: ubuntu-latest
needs: diesel-build
strategy:
matrix:
version: [10.6]
example: [diesel_mysql]
services:
mariadb:
image: mariadb:${{ matrix.version }}
env:
MYSQL_HOST: 127.0.0.1
MYSQL_DATABASE: query
MYSQL_USER: sea
MYSQL_PASSWORD: sea
MYSQL_ROOT_PASSWORD: sea
ports:
- "3306:3306"
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v3
- 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

postgres:
name: PostgreSQL
runs-on: ubuntu-latest
needs: diesel-build
strategy:
matrix:
version: [14.4, 13.7, 12.11]
example: [diesel_postgres]
services:
postgres:
image: postgres:${{ matrix.version }}
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_DB: query
POSTGRES_USER: sea
POSTGRES_PASSWORD: sea
ports:
- "5432:5432"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- 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
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 d179e82

Please sign in to comment.