Skip to content
Open
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
62 changes: 62 additions & 0 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,26 @@ jobs:
SQLX_OFFLINE_DIR: .sqlx
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# Run tests to validate zstd compression for traffic
- run: >
cargo test
--no-default-features
--features any,mysql,mysql-zstd-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?ssl-mode=disabled&compression=zstd:1
SQLX_OFFLINE_DIR: .sqlx
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# Run tests to validate zlib compression for traffic
- run: >
cargo test
--no-default-features
--features any,mysql,mysql-zlib-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?ssl-mode=disabled&compression=zlib:1
SQLX_OFFLINE_DIR: .sqlx
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# Run the `test-attr` test again to cover cleanup.
- run: >
cargo test
Expand Down Expand Up @@ -426,6 +446,27 @@ jobs:
DATABASE_URL: mysql://root@localhost:3306/sqlx?sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# Run tests to validate zstd compression for traffic with tls
- if: ${{ matrix.tls != 'none' }}
run: >
cargo test
--no-default-features
--features any,mysql,mysql-zstd-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root@localhost:3306/sqlx?sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt&compression=zstd:1
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}

# Run tests to validate zlib compression for traffic with tls
- if: ${{ matrix.tls != 'none' }}
run: >
cargo test
--no-default-features
--features any,mysql,mysql-zlib-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root@localhost:3306/sqlx?sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt&compression=zlib:1
RUSTFLAGS: --cfg mysql_${{ matrix.mysql }}


mariadb:
name: MariaDB
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -461,6 +502,16 @@ jobs:
SQLX_OFFLINE_DIR: .sqlx
RUSTFLAGS: --cfg mariadb="${{ matrix.mariadb }}"

# Run tests to validate zlib compression for traffic
- run: >
cargo test
--no-default-features
--features any,mysql,mysql-zlib-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root:password@localhost:3306/sqlx?compression=zlib:1
SQLX_OFFLINE_DIR: .sqlx
RUSTFLAGS: --cfg mariadb="${{ matrix.mariadb }}"

# Run the `test-attr` test again to cover cleanup.
- run: >
cargo test
Expand Down Expand Up @@ -514,3 +565,14 @@ jobs:
env:
DATABASE_URL: mysql://root@localhost:3306/sqlx?sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt
RUSTFLAGS: --cfg mariadb="${{ matrix.mariadb }}"


# Run tests to validate zlib compression for traffic with tls
- if: ${{ matrix.tls != 'none' }}
run: >
cargo test
--no-default-features
--features any,mysql,mysql-zlib-compression,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }}
env:
DATABASE_URL: mysql://root@localhost:3306/sqlx?sslmode=verify_ca&ssl-ca=.%2Ftests%2Fcerts%2Fca.crt&ssl-key=.%2Ftests%2Fcerts%2Fkeys%2Fclient.key&ssl-cert=.%2Ftests%2Fcerts%2Fclient.crt&compression=zlib:1
RUSTFLAGS: --cfg mariadb="${{ matrix.mariadb }}"
68 changes: 68 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ uuid = ["sqlx-core/uuid", "sqlx-macros?/uuid", "sqlx-mysql?/uuid", "sqlx-postgre
regexp = ["sqlx-sqlite?/regexp"]
bstr = ["sqlx-core/bstr"]

# compression
mysql-zstd-compression = ["sqlx-mysql/zstd-compression"]
mysql-zlib-compression = ["sqlx-mysql/zlib-compression"]

[workspace.dependencies]
# Core Crates
sqlx-core = { version = "=0.9.0-alpha.1", path = "sqlx-core" }
Expand Down Expand Up @@ -401,6 +405,12 @@ name = "mysql-rustsec"
path = "tests/mysql/rustsec.rs"
required-features = ["mysql"]

[[test]]
name = "mysql-compression"
path = "tests/mysql/compression.rs"
required-features = ["mysql"]


#
# PostgreSQL
#
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ be removed in the future.

- `mysql`: Add support for the MySQL/MariaDB database server.

- `mysql-zlib-compression`: Add zlib compression support for MySQL/MariaDB database server.

- `mysql-zstd-compression`: Add std compression support for MySQL database server.

- `mssql`: Add support for the MSSQL database server.

- `sqlite`: Add support for the self-contained [SQLite](https://sqlite.org/) database engine with SQLite bundled and statically-linked.
Expand Down
6 changes: 6 additions & 0 deletions sqlx-mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ json = ["sqlx-core/json", "serde"]
any = ["sqlx-core/any"]
offline = ["sqlx-core/offline", "serde/derive"]
migrate = ["sqlx-core/migrate"]
zstd-compression = ["zstd"]
zlib-compression = ["flate2"]

# Type Integration features
bigdecimal = ["dep:bigdecimal", "sqlx-core/bigdecimal"]
Expand Down Expand Up @@ -67,6 +69,10 @@ stringprep = "0.1.2"
tracing = { version = "0.1.37", features = ["log"] }
whoami = { version = "1.2.1", default-features = false }

# Compression
zstd = { version = "0.13.3", optional = true, default-features = false, features = ["zdict_builder"] }
flate2 = { version = "1.1.5", optional = true, default-features = false, features = ["rust_backend", "zlib"] }
Comment on lines +73 to +74
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be better if these were under separate features. Most of the time, the user should know which compression algorithms their server supports and it can be pretty annoying to deal with building dependencies you don't need.

Copy link
Author

Choose a reason for hiding this comment

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

I have created two feature flags – mysql-zstd-compression, mysql-zlib-compression.


dotenvy.workspace = true
thiserror.workspace = true

Expand Down
4 changes: 2 additions & 2 deletions sqlx-mysql/src/connection/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl AuthPlugin {
0x04 => {
let payload = encrypt_rsa(stream, 0x02, password, nonce).await?;

stream.write_packet(&*payload)?;
stream.write_packet(&*payload).await?;
stream.flush().await?;

Ok(false)
Expand Down Expand Up @@ -143,7 +143,7 @@ async fn encrypt_rsa<'s>(
}

// client sends a public key request
stream.write_packet(&[public_key_request_id][..])?;
stream.write_packet(&[public_key_request_id][..]).await?;
stream.flush().await?;

// server sends a public key response
Expand Down
Loading
Loading