Skip to content

Commit

Permalink
Merge pull request #4238 from weiznich/doc/fixes
Browse files Browse the repository at this point in the history
Try to improve the first user experience with our examples
  • Loading branch information
weiznich authored Oct 24, 2024
2 parents b170af7 + ea158f7 commit 47e8850
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 93 deletions.
67 changes: 28 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
matrix:
rust: ["stable", "beta", "nightly"]
backend: ["postgres", "sqlite", "mysql"]
os: [ubuntu-latest, macos-13, macos-14, windows-2019]
os: [ubuntu-latest, macos-13, macos-15, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-${{ hashFiles('**/Cargo.toml') }}
key: ${{ matrix.os }}-${{ matrix.backend }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Set environment variables
shell: bash
Expand Down Expand Up @@ -78,24 +78,13 @@ jobs:
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root:root@127.0.0.1/diesel_unit_test" >> $GITHUB_ENV
- name: Install postgres (MacOS)
if: matrix.os == 'macos-13' && matrix.backend == 'postgres'
if: matrix.os == 'macos-13' || matrix.os == 'macos-15' && matrix.backend == 'postgres'
run: |
brew install postgresql@14
brew services start postgresql@14
sleep 3
createuser -s postgres
echo "PG_DATABASE_URL=postgres://postgres@localhost/" >> $GITHUB_ENV
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres@localhost/diesel_example" >> $GITHUB_ENV
- name: Install postgres (MacOS M1)
if: matrix.os == 'macos-14' && matrix.backend == 'postgres'
run: |
brew install postgresql@14
brew services start postgresql@14
sleep 3
createuser -s postgres
echo "PG_DATABASE_URL=postgres://postgres@localhost/" >> $GITHUB_ENV
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres@localhost/diesel_example" >> $GITHUB_ENV
- name: Install sqlite (MacOS)
if: runner.os == 'macOS' && matrix.backend == 'sqlite'
Expand All @@ -107,31 +96,29 @@ jobs:
- name: Install mysql (MacOS)
if: matrix.os == 'macos-13' && matrix.backend == 'mysql'
run: |
brew install mariadb@10.11
/usr/local/opt/mariadb@10.11/bin/mysql_install_db
/usr/local/opt/mariadb@10.11/bin/mysql.server start
brew install mysql@9.0
/usr/local/opt/mysql@9.0/bin/mysql.server start
sleep 3
/usr/local/opt/mariadb@10.11/bin/mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'runner'@'localhost';" -urunner
echo "MYSQL_DATABASE_URL=mysql://runner@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://runner@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://runner@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/usr/local/opt/mariadb@10.11/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=10.11" >> $GITHUB_ENV
/usr/local/opt/mysql@9.0/bin/mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot
echo "MYSQL_DATABASE_URL=mysql://root@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/usr/local/opt/mysql@9.0/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=9.0" >> $GITHUB_ENV
- name: Install mysql (MacOS M1)
if: matrix.os == 'macos-14' && matrix.backend == 'mysql'
if: matrix.os == 'macos-15' && matrix.backend == 'mysql'
run: |
brew install mariadb@10.11
ls /opt/homebrew/opt/mariadb@10.11
/opt/homebrew/opt/mariadb@10.11/bin/mysql_install_db
/opt/homebrew/opt/mariadb@10.11/bin/mysql.server start
brew install mysql@9.0
ls /opt/homebrew/opt/mysql@9.0
/opt/homebrew/opt/mysql@9.0/bin/mysql.server start
sleep 3
/opt/homebrew/opt/mariadb@10.11/bin/mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'runner'@'localhost';" -urunner
echo "MYSQL_DATABASE_URL=mysql://runner@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://runner@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://runner@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/opt/homebrew/opt/mariadb@10.11/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=10.11" >> $GITHUB_ENV
/opt/homebrew/opt/mysql@9.0/bin/mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot
echo "MYSQL_DATABASE_URL=mysql://root@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=/opt/homebrew/opt/mysql@9.0/lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=9.0" >> $GITHUB_ENV
- name: Install sqlite (Windows)
if: runner.os == 'Windows' && matrix.backend == 'sqlite'
Expand All @@ -155,8 +142,8 @@ jobs:
shell: bash
run: |
choco install postgresql14 --force --params '/Password:root'
echo "C:\Program Files\PostgreSQL\14\bin" >> $GITHUB_PATH
echo "C:\Program Files\PostgreSQL\14\lib" >> $GITHUB_PATH
echo "OPENSSL_RUST_USE_NASM=0" >> $GITHUB_ENV
echo OPENSSL_SRC_PERL=C:/Strawberry/perl/bin/perl >> $GITHUB_ENV
echo "PQ_LIB_DIR=C:\Program Files\PostgreSQL\14\lib" >> $GITHUB_ENV
echo "PG_DATABASE_URL=postgres://postgres:root@localhost/" >> $GITHUB_ENV
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres:root@localhost/diesel_example" >> $GITHUB_ENV
Expand All @@ -172,9 +159,11 @@ jobs:
if: runner.os == 'Windows' && matrix.backend == 'mysql'
shell: bash
run: |
echo "MYSQL_DATABASE_URL=mysql://root@localhost/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@localhost/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@localhost/diesel_unit_test" >> $GITHUB_ENV
echo "OPENSSL_RUST_USE_NASM=0" >> $GITHUB_ENV
echo OPENSSL_SRC_PERL=C:/Strawberry/perl/bin/perl >> $GITHUB_ENV
echo "MYSQL_DATABASE_URL=mysql://root@127.0.0.1/diesel_test" >> $GITHUB_ENV
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@127.0.0.1/diesel_example" >> $GITHUB_ENV
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@127.0.0.1/diesel_unit_test" >> $GITHUB_ENV
echo "MYSQLCLIENT_LIB_DIR=C:\tools\mysql\current\lib" >> $GITHUB_ENV
echo "MYSQLCLIENT_VERSION=8.0.31" >> $GITHUB_ENV
echo "C:\tools\mysql\current\lib" >> $GITHUB_PATH
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ edition = "2021"

[workspace.dependencies]
libsqlite3-sys = "0.30.1"
pq-sys = "0.6"
openssl-sys = "0.9.100"
mysqlclient-sys = "0.4"

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
2 changes: 1 addition & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diesel"
version = "2.2.0"
version = "2.2.4"
license = "MIT OR Apache-2.0"
description = "A safe, extensible ORM and Query Builder for PostgreSQL, SQLite, and MySQL"
readme = "README.md"
Expand Down
20 changes: 16 additions & 4 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,22 @@
//! [dependencies]
//! libsqlite3-sys = { version = "0.29", features = ["bundled"] }
//! ```
//! - `postgres`: This feature enables the diesel postgres backend. Enabling this feature requires a compatible
//! copy of `libpq` for your target architecture. This features implies `postgres_backend`
//! - `mysql`: This feature enables the idesel mysql backend. Enabling this feature requires a compatible copy
//! of `libmysqlclient` for your target architecture. This feature implies `mysql_backend`
//! - `postgres`: This feature enables the diesel postgres backend. This features implies `postgres_backend`
//! Enabling this feature requires a compatible copy of `libpq` for your target architecture.
//! Alternatively, you can add `pq-sys` with the `bundled` feature as a dependency to your
//! crate so libpq will be bundled:
//! ```toml
//! [dependencies]
//! pq-sys = { version = "0.6", features = ["bundled"] }
//! openssl-sys = { version = "0.9.100", features = ["vendored"] }
//! ```
//! - `mysql`: This feature enables the diesel mysql backend. This feature implies `mysql_backend`.
//! Enabling this feature requires a compatible copy of `libmysqlclient` for your target architecture.
//! Alternatively, you can add `mysqlclient-sys` with the `bundled` feature as a dependency to your
//! crate so libmysqlclient will be bundled:
//! ```toml
//! [dependencies]
//! mysqlclient-sys = { version = "0.4", features = ["bundled"] }
//! - `postgres_backend`: This feature enables those parts of diesels postgres backend, that are not dependent
//! on `libpq`. Diesel does not provide any connection implementation with only this feature enabled.
//! This feature can be used to implement a custom implementation of diesels `Connection` trait for the
Expand Down
6 changes: 3 additions & 3 deletions diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ serde = { version = "1.0.193", features = ["derive", "std"] }
toml = "0.8"
url = "2.2.2"
libsqlite3-sys = { workspace = true, optional = true }
pq-sys = { version = ">=0.4, <0.7.0", optional = true }
openssl-sys = { version = "0.9.93", features = ["vendored"], optional = true }
mysqlclient-sys = { version = "0.4.0", optional = true }
pq-sys = { workspace = true, optional = true }
openssl-sys = { workspace = true, features = ["vendored"], optional = true }
mysqlclient-sys = { workspace = true, optional = true }
diffy = "0.4.0"
regex = "1.0.6"
serde_regex = "1.1"
Expand Down
57 changes: 32 additions & 25 deletions diesel_compile_tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion diesel_compile_tests/tests/fail/auto_type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ error[E0107]: type alias takes 0 generic arguments but 1 generic argument was su
36 | | .filter(user_has_post_with_id_greater_than(id_greater_than))
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |_________________|________________________________|
| | help: remove these generics
| | help: remove the unnecessary generics
| expected 0 generic arguments
|
note: type alias defined here, with 0 generic parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ error[E0505]: cannot move out of `buf` because it is borrowed
|
help: consider cloning the value if the performance cost is acceptable
|
11 - let query = diesel::select((&buf as &[u8]).into_sql::<sql_types::Binary>());
11 + let query = diesel::select((buf.clone() as &[u8]).into_sql::<sql_types::Binary>());
|
11 | let query = diesel::select((&buf.clone() as &[u8]).into_sql::<sql_types::Binary>());
| ++++++++
4 changes: 2 additions & 2 deletions diesel_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ ipnetwork = ">=0.12.2, <0.21.0"
bigdecimal = ">= 0.0.13, < 0.5.0"
rand = "0.8.4"
libsqlite3-sys = { workspace = true, optional = true }
pq-sys = { version = "0.6", optional = true }
pq-sys = { workspace = true, optional = true }
pq-src = { version = "0.3", optional = true }
mysqlclient-sys = { version = "0.4", optional = true }
mysqlclient-sys = { workspace = true, optional = true }
mysqlclient-src = { version = "0.1.0", optional = true }

[features]
Expand Down
1 change: 0 additions & 1 deletion diesel_tests/tests/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ fn copy_to_csv_all_options() {
let mut out = String::new();
let mut copy = diesel::copy_to(users::table)
.with_format(CopyFormat::Csv)
.with_freeze(true)
.with_delimiter(';')
.with_quote('"')
.with_escape('\\')
Expand Down
1 change: 1 addition & 0 deletions examples/mysql/all_about_inserts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ publish = false

[dependencies]
diesel = { version = "2.2.0", path = "../../../diesel", features = ["mysql", "chrono"] }
mysqlclient-sys = { workspace = true, features = ["bundled"] }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.68"
chrono = { version = "0.4.20", default-features = false, features = ["clock", "std"] }
Expand Down
Loading

0 comments on commit 47e8850

Please sign in to comment.