MySQLKit is a MySQL client library built on SQLKit. 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.
Configuration
Database connection options and credentials are specified using a MySQLConfiguration struct.
Once you have a MySQLConfiguration, you can use it to create a connection source and pool.
let eventLoopGroup: EventLoopGroup = ...
defer { try! eventLoopGroup.syncShutdown() }
let pools = EventLoopGroupConnectionPool(
source: MySQLConnectionSource(configuration: configuration),
on: eventLoopGroup
)
defer { pools.shutdown() }
First create a MySQLConnectionSource using the configuration struct. This type is responsible for creating new connections to your database server as needed.
Next, use the connection source to create an EventLoopGroupConnectionPool. You will also need to pass an EventLoopGroup. For more information on creating an EventLoopGroup, visit SwiftNIO’s documentation. Make sure to shutdown the connection pool before it deinitializes.
EventLoopGroupConnectionPool is a collection of pools for each event loop. When using EventLoopGroupConnectionPool directly, random event loops will be chosen as needed.
🐬 Non-blocking, event-driven Swift client for MySQL.
Major Releases
The table below shows a list of MySQLKit major releases alongside their compatible NIO and Swift versions.
from: "4.0.0"
from: "3.0.0"
from: "2.0.0"
from: "1.0.0"
Use the SPM string to easily include the dependency in your
Package.swift
file.Supported Platforms
MySQLKit supports the following platforms:
Overview
MySQLKit is a MySQL client library built on SQLKit. 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.
Configuration
Database connection options and credentials are specified using a
MySQLConfiguration
struct.URL string based configuration is also supported.
To connect via unix-domain sockets, use
unixDomainSocketPath
instead ofhostname
andport
.Connection Pool
Once you have a
MySQLConfiguration
, you can use it to create a connection source and pool.First create a
MySQLConnectionSource
using the configuration struct. This type is responsible for creating new connections to your database server as needed.Next, use the connection source to create an
EventLoopGroupConnectionPool
. You will also need to pass anEventLoopGroup
. For more information on creating anEventLoopGroup
, visit SwiftNIO’s documentation. Make sure to shutdown the connection pool before it deinitializes.EventLoopGroupConnectionPool
is a collection of pools for each event loop. When usingEventLoopGroupConnectionPool
directly, random event loops will be chosen as needed.To get a pool for a specific event loop, use
pool(for:)
. This returns anEventLoopConnectionPool
.MySQLDatabase
Both
EventLoopGroupConnectionPool
andEventLoopConnectionPool
can be used to create instances ofMySQLDatabase
.Visit MySQLNIO’s docs for more information on using
MySQLDatabase
.SQLDatabase
A
MySQLDatabase
can be used to create an instance ofSQLDatabase
.Visit SQLKit’s docs for more information on using
SQLDatabase
.