Skip to content

Commit

Permalink
Update for new SQLKit and support more URL string formats (#325)
Browse files Browse the repository at this point in the history
* Update package infrastructure, bump Swift minimum to 5.8, add ExistentialAny and StrictConcurrency compliance
* Leverage the new SQLKit functionality, remove various crashing codepaths from the encoder and decoder, add more features to the dialect, improve NULL handling, other misc cleanup
* Remove obsolete file
* Add Swift 5.9 manifest
* Improve docs
* Add support for additional MySQL URL formats.
* Add 100% doc comments coverage (rather trivial for this package)
* Add tests for new URL formats and use the undeprecated SQLBenchmarker API
* Make MySQLConfiguration Sendable
  • Loading branch information
gwynne authored Apr 29, 2024
1 parent a9375f8 commit 395a6ea
Show file tree
Hide file tree
Showing 22 changed files with 866 additions and 355 deletions.
9 changes: 8 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
* @0xTim @gwynne
* @gwynne
/.github/CONTRIBUTING.md @gwynne @0xTim
/.github/workflows/*.yml @gwynne @0xTim
/.github/workflows/test.yml @gwynne
/.spi.yml @gwynne @0xTim
/.gitignore @gwynne @0xTim
/LICENSE @gwynne @0xTim
/README.md @gwynne @0xTim
2 changes: 1 addition & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
package_name: mysql-kit
modules: MySQLKit
pathsToInvalidate: /mysqlkit
pathsToInvalidate: /mysqlkit/*
58 changes: 26 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ env:
MYSQL_PASSWORD_B: 'test_password'

jobs:

api-breakage:
if: ${{ !(github.event.pull_request.draft || false) }}
if: ${{ github.event_name == 'pull_request' && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.9-jammy
container: swift:jammy
steps:
- name: Check out code
- name: Checkout
uses: actions/checkout@v4
with: { 'fetch-depth': 0 }
- name: Run API breakage check action
uses: vapor/ci/.github/actions/ci-swift-check-api-breakage@reusable-workflows
- name: API breaking changes
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
swift package diagnose-api-breaking-changes origin/main
dependents:
if: ${{ !(github.event.pull_request.draft || false) }}
Expand All @@ -53,13 +54,13 @@ jobs:
MYSQL_USER: test_username
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
container: swift:5.9-jammy
container: swift:5.10-jammy
strategy:
fail-fast: false
matrix:
dbimage:
- mysql:5.7
- mysql:8.1
- mysql:8
- mariadb:11
- percona:8.0
steps:
Expand All @@ -85,15 +86,15 @@ jobs:
dbimage:
- mysql:5.7
- mysql:8.0
- mysql:8.1
- mysql:8.3
- mariadb:10.4
- mariadb:11
- percona:8.0
runner:
# List is deliberately incomplete; we want to avoid running 50 jobs on every commit
- swift:5.7-focal
- swift:5.9-jammy
- swiftlang/swift:nightly-5.10-jammy
- swift:5.8-focal
- swift:5.10-jammy
- swiftlang/swift:nightly-6.0-jammy
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
Expand All @@ -105,43 +106,36 @@ jobs:
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
steps:
- name: Save MySQL version to env
run: |
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
- name: Display versions
shell: bash
run: |
if [[ '${{ contains(matrix.container, 'nightly') }}' == 'true' ]]; then
SWIFT_PLATFORM="$(source /etc/os-release && echo "${ID}${VERSION_ID}")" SWIFT_VERSION="$(cat /.swift_tag)"
printf 'SWIFT_PLATFORM=%s\nSWIFT_VERSION=%s\n' "${SWIFT_PLATFORM}" "${SWIFT_VERSION}" >>"${GITHUB_ENV}"
fi
printf 'OS: %s\nTag: %s\nVersion:\n' "${SWIFT_PLATFORM}-${RUNNER_ARCH}" "${SWIFT_VERSION}" && swift --version
- name: Check out package
uses: actions/checkout@v4
- name: Run local tests with coverage and TSan
run: swift test --enable-code-coverage --sanitize=thread
- name: Submit coverage report to Codecov.io
uses: vapor/[email protected]
uses: vapor/[email protected]
with:
codecov_token: ${{ secrets.CODECOV_TOKEN }}

# Run unit tests (macOS). Don't bother with lots of variations, Linux will cover that.
macos-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
formula: [ '[email protected]' ]
macos: [ 'macos-13' ]
xcode: [ 'latest-stable' ]
runs-on: ${{ matrix.macos }}
include:
- macos-version: macos-13
xcode-version: '~14.3'
- macos-version: macos-14
xcode-version: latest
runs-on: ${{ matrix.macos-version }}
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode }}
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Install MySQL server from Homebrew
run: brew install ${{ matrix.formula }} && brew link --force ${{ matrix.formula }}
run: brew install mysql && brew link --force mysql
- name: Start MySQL server
run: brew services start ${{ matrix.formula }}
run: brew services start mysql
- name: Wait for MySQL server to be ready
run: until echo | mysql -uroot; do sleep 1; done
timeout-minutes: 5
Expand Down
51 changes: 33 additions & 18 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -13,25 +13,40 @@ let package = Package(
.library(name: "MySQLKit", targets: ["MySQLKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/mysql-nio.git", from: "1.0.0"),
.package(url: "https://github.com/vapor/mysql-nio.git", from: "1.7.1"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "2.0.0" ..< "4.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.64.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.26.0"),
],
targets: [
.target(name: "MySQLKit", dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "MySQLNIO", package: "mysql-nio"),
.product(name: "SQLKit", package: "sql-kit"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
]),
.testTarget(name: "MySQLKitTests", dependencies: [
.target(name: "MySQLKit"),
.product(name: "SQLKitBenchmark", package: "sql-kit"),
]),
.target(
name: "MySQLKit",
dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "MySQLNIO", package: "mysql-nio"),
.product(name: "SQLKit", package: "sql-kit"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "MySQLKitTests",
dependencies: [
.product(name: "SQLKitBenchmark", package: "sql-kit"),
.target(name: "MySQLKit"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
53 changes: 53 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "mysql-kit",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
],
products: [
.library(name: "MySQLKit", targets: ["MySQLKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/mysql-nio.git", from: "1.7.1"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.29.2"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "2.0.0" ..< "4.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.64.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.26.0"),
],
targets: [
.target(
name: "MySQLKit",
dependencies: [
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "MySQLNIO", package: "mysql-nio"),
.product(name: "SQLKit", package: "sql-kit"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "MySQLKitTests",
dependencies: [
.product(name: "SQLKitBenchmark", package: "sql-kit"),
.target(name: "MySQLKit"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
57 changes: 23 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,42 @@
<img src="https://user-images.githubusercontent.com/1342803/75589537-fbfc9100-5a48-11ea-8732-e75dfe32e338.png" height="64" alt="MySQL">

<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
</a>
<a href="https://discord.gg/vapor">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/sql-kit/actions">
<img src="https://github.com/vapor/sql-kit/workflows/test/badge.svg" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.2-brightgreen.svg" alt="Swift 5.2">
</a>
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/mysql-kit/assets/1130717/d5582d0a-f8b2-4fab-aeea-79b170bebc28">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/mysql-kit/assets/1130717/71d0fa71-5ded-492c-9657-4206f233419e">
<img src="https://github.com/vapor/mysql-kit/assets/1130717/71d0fa71-5ded-492c-9657-4206f233419e" height="96" alt="MySQLKit">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/mysql-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/mysql-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/mysql-kit"><img src="https://img.shields.io/codecov/c/github/vapor/mysql-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
</p>

🐬 Non-blocking, event-driven Swift client for MySQL.
<br>

### Major Releases
MySQLKit is an [SQLKit] driver for MySQL clients. It supports building and serializing MySQL-dialect SQL queries. MySQLKit uses [MySQLNIO] to connect and communicate with the database server asynchronously. [AsyncKit] is used to provide connection pooling.

The table below shows a list of MySQLKit major releases alongside their compatible NIO and Swift versions.
[SQLKit]: https://github.com/vapor/sql-kit
[MySQLNIO]: https://github.com/vapor/mysql-nio
[AsyncKit]: https://github.com/vapor/async-kit

|Version|NIO|Swift|SPM|
|---|---|---|---|
|4.0|2.0|5.2+|`from: "4.0.0"`|
|3.0|1.0|4.0+|`from: "3.0.0"`|
|2.0|N/A|3.1+|`from: "2.0.0"`|
|1.0|N/A|3.1+|`from: "1.0.0"`|
### Usage

Use the SPM string to easily include the dependency in your `Package.swift` file.
Use the SPM string to easily include the dependendency in your `Package.swift` file.

```swift
.package(url: "https://github.com/vapor/mysql-kit.git", from: ...)
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.0.0")
```

### Supported Platforms

MySQLKit supports the following platforms:

- Ubuntu 16.04+
- Ubuntu 20.04+
- macOS 10.15+

## Overview

MySQLKit is a MySQL client library built on [SQLKit](https://github.com/vapor/sql-kit). It supports building and serializing MySQL-dialect SQL queries. MySQLKit uses [MySQLNIO](https://github.com/vapor/mysql-nio) to connect and communicate with the database server asynchronously. [AsyncKit](https://github.com/vapor/async-kit) is used to provide connection pooling.

### Configuration

Database connection options and credentials are specified using a `MySQLConfiguration` struct.
Expand Down Expand Up @@ -141,4 +130,4 @@ let sql = mysql.sql() // SQLDatabase
let planets = try sql.select().column("*").from("planets").all().wait()
```

Visit [SQLKit's docs](https://github.com/vapor/sql-kit) for more information on using `SQLDatabase`.
Visit [SQLKit's docs](https://api.vapor.codes/sqlkit/documentation/sqlkit) for more information on using `SQLDatabase`.
Loading

0 comments on commit 395a6ea

Please sign in to comment.