MySQL/MariaDB driver implementation for the abstract Feather Database Swift API package.
- MySQL/MariaDB driver for Feather Database
- Automatic query parameter escaping via Swift string interpolation.
- Async sequence query results with
Decodablerow support. - Designed for modern Swift concurrency
- DocC-based API Documentation
- Unit tests and code coverage
- Swift 6.1+
- Platforms:
- Linux
- macOS 15+
- iOS 18+
- tvOS 18+
- watchOS 11+
- visionOS 2+
Add the dependency to your Package.swift:
.package(url: "https://github.com/feather-framework/feather-mysql-database", exact: "1.0.0-beta.4"),Then add FeatherMySQLDatabase to your target dependencies:
.product(name: "FeatherMySQLDatabase", package: "feather-mysql-database"),API documentation is available at the link below:
Here is a brief example:
import Logging
import MySQLNIO
import NIOCore
import NIOPosix
import NIOSSL
import FeatherDatabase
import FeatherMySQLDatabase
var logger = Logger(label: "example")
logger.logLevel = .info
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let finalCertPath = URL(fileURLWithPath: "path/to/ca.pem")
var tlsConfig = TLSConfiguration.makeClientConfiguration()
let rootCert = try NIOSSLCertificate.fromPEMFile(finalCertPath)
tlsConfig.trustRoots = .certificates(rootCert)
tlsConfig.certificateVerification = .fullVerification
let connection =
try await MySQLConnection.connect(
to: try SocketAddress(ipAddress: "127.0.0.1", port: 3306),
username: "mariadb",
database: "mariadb",
password: "mariadb",
tlsConfiguration: tlsConfig,
logger: logger,
on: eventLoopGroup.next()
)
.get()
let database = MySQLDatabaseClient(
connection: connection,
logger: logger
)
do {
let result = try await database.withConnection { connection in
try await connection.run(
query: #"""
SELECT
VERSION() AS `version`
WHERE
1=\#(1);
"""#
)
}
for try await item in result {
let version = try item.decode(column: "version", as: String.self)
print(version)
}
try await connection.close().get()
try await eventLoopGroup.shutdownGracefully()
}
catch {
try await connection.close().get()
try await eventLoopGroup.shutdownGracefully()
throw error
}Warning
This repository is a work in progress, things can break until it reaches v1.0.0.
The following database driver implementations are available for use:
- Build:
swift build - Test:
- local:
swift test - using Docker:
make docker-test
- local:
- Format:
make format - Check:
make check
Pull requests are welcome. Please keep changes focused and include tests for new logic.