diff --git a/.github/workflows/mariadb.yml b/.github/workflows/mariadb.yml deleted file mode 100644 index cc653309a..000000000 --- a/.github/workflows/mariadb.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: MariaDB - -on: - pull_request: - push: - branches: - - master - -jobs: - mariadb: - - runs-on: ubuntu-latest - - strategy: - matrix: - mariadb: [10.1.43, 10.4.11] - - services: - mariadb: - image: mariadb:${{ matrix.mariadb }} - env: - MYSQL_ROOT_PASSWORD: password - MYSQL_DATABASE: sqlx - ports: - # will assign a random free host port - - 3306/tcp - # needed because the container does not provide a healthcheck - options: --health-cmd "mysqladmin ping --silent" --health-interval 30s --health-timeout 30s --health-retries 10 - - steps: - - uses: actions/checkout@v1 - - # Rust ------------------------------------------------ - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - if: steps.cache_rust.outputs.cache-hit != 'true' - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache target/ - uses: actions/cache@v1 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-mariadb-${{ hashFiles('**/Cargo.lock') }} - - # ----------------------------------------------------- - - - run: cargo test -p sqlx --no-default-features --features 'runtime-async-std mysql macros chrono' - env: - DATABASE_URL: mariadb://root:password@localhost:${{ job.services.mariadb.ports[3306] }}/sqlx - - # Rust ------------------------------------------------ - - - name: Prepare build directory for cache - run: | - find ./target/debug -maxdepth 1 -type f -delete \ - && rm -fr ./target/debug/{deps,.fingerprint}/*sqlx* \ - && rm -f ./target/.rustc_info.json - - # ----------------------------------------------------- diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml deleted file mode 100644 index 06295cc5e..000000000 --- a/.github/workflows/mysql.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: MySQL - -on: - pull_request: - push: - branches: - - master - -jobs: - mysql: - - runs-on: ubuntu-latest - - strategy: - matrix: - mysql: [5.7.28, 8.0.18] - - services: - mysql: - image: mysql:${{ matrix.mysql }} - env: - MYSQL_ROOT_PASSWORD: password - MYSQL_DATABASE: sqlx - ports: - # will assign a random free host port - - 3306/tcp - # needed because the container does not provide a healthcheck - options: >- - --health-cmd "mysqladmin ping --silent" --health-interval 30s --health-timeout 30s - --health-retries 10 -v /data/mysql:/var/lib/mysql - - - steps: - - uses: actions/checkout@v1 - - # Rust ------------------------------------------------ - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - if: steps.cache_rust.outputs.cache-hit != 'true' - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache target/ - uses: actions/cache@v1 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-mysql-${{ hashFiles('**/Cargo.lock') }} - - # ----------------------------------------------------- - - - run: cargo test -p sqlx --no-default-features --features 'runtime-async-std mysql macros chrono tls' - env: - # pass the path to the CA that the MySQL service generated - # Github Actions' YML parser doesn't handle multiline strings correctly - DATABASE_URL: mysql://root:password@localhost:${{ job.services.mysql.ports[3306] }}/sqlx?ssl-mode=VERIFY_CA&ssl-ca=%2Fdata%2Fmysql%2Fca.pem - - # Rust ------------------------------------------------ - - - name: Prepare build directory for cache - run: | - find ./target/debug -maxdepth 1 -type f -delete \ - && rm -fr ./target/debug/{deps,.fingerprint}/*sqlx* \ - && rm -f ./target/.rustc_info.json - - # ----------------------------------------------------- diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml deleted file mode 100644 index 89480dad1..000000000 --- a/.github/workflows/postgres.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Postgres - -on: - pull_request: - push: - branches: - - master - -jobs: - postgres: - - runs-on: ubuntu-latest - - strategy: - matrix: - postgres: [9.4.25, 10.11, 12.1] - - services: - postgres: - image: postgres:${{ matrix.postgres }} - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - # will assign a random free host port - - 5432/tcp - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@v1 - - # Rust ------------------------------------------------ - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - if: steps.cache_rust.outputs.cache-hit != 'true' - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache target/ - uses: actions/cache@v1 - with: - path: target - key: ${{ runner.os }}-cargo-build-target-postgres-${{ hashFiles('**/Cargo.lock') }} - - # ----------------------------------------------------- - - # Check that we build with TLS support (TODO: we need a postgres image with SSL certs to test) - - run: cargo check -p sqlx-core --no-default-features --features 'runtime-async-std postgres macros uuid chrono tls' - - # Test on async-std - - run: cargo test -p sqlx --no-default-features --features 'runtime-async-std postgres macros uuid chrono' - env: - DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres - - # Test on tokio - - run: cargo test -p sqlx --no-default-features --features 'runtime-tokio postgres macros uuid chrono' - env: - DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres - - # Rust ------------------------------------------------ - - - name: Prepare build directory for cache - run: | - find ./target/debug -maxdepth 1 -type f -delete \ - && rm -fr ./target/debug/{deps,.fingerprint}/*sqlx* \ - && rm -f ./target/.rustc_info.json - - # ----------------------------------------------------- diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a72bea6dd..2ccdebfdb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,8 +7,14 @@ on: - master jobs: - build: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: cargo fmt --all -- --check + + build: runs-on: ubuntu-latest steps: @@ -18,7 +24,6 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 - if: steps.cache_rust.outputs.cache-hit != 'true' with: toolchain: stable profile: minimal @@ -32,13 +37,17 @@ jobs: # ----------------------------------------------------- + # check: async-std - run: cargo check --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-async-std' + # check: tokio - run: cargo check --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-tokio' - - run: cargo test -p sqlx-core --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-async-std' + # unit test: async-std + - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'chrono uuid postgres mysql tls runtime-async-std' - - run: cargo test -p sqlx-core --no-default-features --features 'chrono uuid postgres mysql macros tls runtime-tokio' + # unit test: tokio + - run: cargo test --manifest-path sqlx-core/Cargo.toml --no-default-features --features 'chrono uuid postgres mysql tls runtime-tokio' # Rust ------------------------------------------------ @@ -49,3 +58,160 @@ jobs: && rm -f ./target/.rustc_info.json # ----------------------------------------------------- + + postgres: + needs: build + runs-on: ubuntu-latest + + strategy: + matrix: + postgres: [9.4.25, 10.11, 12.1] + + services: + postgres: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + # will assign a random free host port + - 5432/tcp + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # ----------------------------------------------------- + + # integration test: async-std + - run: cargo test --no-default-features --features 'runtime-async-std postgres macros uuid chrono tls' + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres + + # integration test: tokio + - run: cargo test --no-default-features --features 'runtime-tokio postgres macros uuid chrono tls' + env: + DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres + + mysql: + needs: build + runs-on: ubuntu-latest + + strategy: + matrix: + mysql: [5.7.28, 8.0.18] + + services: + mysql: + image: mysql:${{ matrix.mysql }} + env: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: sqlx + ports: + # will assign a random free host port + - 3306/tcp + # needed because the container does not provide a healthcheck + options: >- + --health-cmd "mysqladmin ping --silent" --health-interval 30s --health-timeout 30s + --health-retries 10 -v /data/mysql:/var/lib/mysql + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # ----------------------------------------------------- + + # integration test: async-std + - run: cargo test --no-default-features --features 'runtime-async-std mysql macros uuid chrono tls' + env: + # pass the path to the CA that the MySQL service generated + # NOTE: Github Actions' YML parser doesn't handle multiline strings correctly + DATABASE_URL: mysql://root:password@localhost:${{ job.services.mysql.ports[3306] }}/sqlx?ssl-mode=VERIFY_CA&ssl-ca=%2Fdata%2Fmysql%2Fca.pem + + # integration test: tokio + - run: cargo test --no-default-features --features 'runtime-tokio mysql macros uuid chrono tls' + env: + # pass the path to the CA that the MySQL service generated + # NOTE: Github Actions' YML parser doesn't handle multiline strings correctly + DATABASE_URL: mysql://root:password@localhost:${{ job.services.mysql.ports[3306] }}/sqlx?ssl-mode=VERIFY_CA&ssl-ca=%2Fdata%2Fmysql%2Fca.pem + + mariadb: + needs: build + runs-on: ubuntu-latest + + strategy: + matrix: + mariadb: [10.1.43, 10.4.11] + + services: + mariadb: + image: mariadb:${{ matrix.mariadb }} + env: + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: sqlx + ports: + # will assign a random free host port + - 3306/tcp + # needed because the container does not provide a healthcheck + options: --health-cmd "mysqladmin ping --silent" --health-interval 30s --health-timeout 30s --health-retries 10 + + steps: + - uses: actions/checkout@v1 + + # Rust ------------------------------------------------ + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache target/ + uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + # ----------------------------------------------------- + + # integration test: async-std + - run: cargo test --no-default-features --features 'runtime-async-std mysql macros chrono uuid chrono tls' + env: + DATABASE_URL: mariadb://root:password@localhost:${{ job.services.mariadb.ports[3306] }}/sqlx + + # integration test: tokio + - run: cargo test --no-default-features --features 'runtime-tokio mysql macros uuid chrono tls' + env: + DATABASE_URL: mariadb://root:password@localhost:${{ job.services.mariadb.ports[3306] }}/sqlx diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml deleted file mode 100644 index 1e8173466..000000000 --- a/.github/workflows/rustfmt.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Format - -on: - pull_request: - push: - branches: - - master - -jobs: - format: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - - run: cargo fmt -- --check diff --git a/src/macros.rs b/src/macros.rs index 36c4c8914..54cb6d782 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -4,7 +4,7 @@ /// if the query has output columns, or `()` (unit) otherwise: /// /// ```rust -/// # #[cfg(feature = "mysql")] +/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ /// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); @@ -23,7 +23,7 @@ /// # Ok(()) /// # } /// # -/// # #[cfg(not(feature = "mysql"))] +/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))] /// # fn main() {} /// ``` /// @@ -32,7 +32,7 @@ /// and this macro will typecheck passed arguments and error on missing ones: /// /// ```rust -/// # #[cfg(feature = "mysql")] +/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ /// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); @@ -53,7 +53,7 @@ /// # Ok(()) /// # } /// # -/// # #[cfg(not(feature = "mysql"))] +/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))] /// # fn main() {} /// ``` /// @@ -123,7 +123,7 @@ macro_rules! query ( /// /// `src/my_query.rs`: /// ```rust -/// # #[cfg(feature = "mysql")] +/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ /// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); @@ -141,7 +141,7 @@ macro_rules! query ( /// # Ok(()) /// # } /// # -/// # #[cfg(not(feature = "mysql"))] +/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))] /// # fn main() {} /// ``` #[macro_export] @@ -178,7 +178,7 @@ macro_rules! query_file ( /// /// The only modification to the syntax is that the struct name is given before the SQL string: /// ```rust -/// # #[cfg(feature = "mysql")] +/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ /// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); @@ -206,7 +206,7 @@ macro_rules! query_file ( /// # Ok(()) /// # } /// # -/// # #[cfg(not(feature = "mysql"))] +/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))] /// # fn main() {} /// ``` #[macro_export] @@ -232,7 +232,7 @@ macro_rules! query_as ( /// Enforces requirements of both macros; see them for details. /// /// ```rust -/// # #[cfg(feature = "mysql")] +/// # #[cfg(all(feature = "mysql", feature = "runtime-async-std"))] /// # #[async_std::main] /// # async fn main() -> sqlx::Result<()>{ /// # let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL must be set"); @@ -256,7 +256,7 @@ macro_rules! query_as ( /// # Ok(()) /// # } /// # -/// # #[cfg(not(feature = "mysql"))] +/// # #[cfg(any(not(feature = "mysql"), not(feature = "runtime-async-std")))] /// # fn main() {} /// ``` #[macro_export] diff --git a/tests/mysql-types.rs b/tests/mysql-types.rs index 5680db9ab..4fa15a50b 100644 --- a/tests/mysql-types.rs +++ b/tests/mysql-types.rs @@ -53,9 +53,13 @@ async fn mysql_bytes() -> anyhow::Result<()> { let value = &b"Hello, World"[..]; - let rec = sqlx::query!("SELECT (X'48656c6c6f2c20576f726c64' = ?) as _1, CAST(? as BINARY) as _2", value, value) - .fetch_one(&mut conn) - .await?; + let rec = sqlx::query!( + "SELECT (X'48656c6c6f2c20576f726c64' = ?) as _1, CAST(? as BINARY) as _2", + value, + value + ) + .fetch_one(&mut conn) + .await?; assert!(rec._1 != 0);