All Projects → vapor → Mysql Kit

vapor / Mysql Kit

Licence: mit
🐬 Pure Swift MySQL client built on non-blocking, event-driven sockets.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Mysql Kit

Vapor Clean
A Vapor 3 template with no additional cruft.
Stars: ✭ 80 (-49.69%)
Mutual labels:  server-side-swift, vapor, swift-linux
Sql Kit
*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Stars: ✭ 115 (-27.67%)
Mutual labels:  mysql, server-side-swift, vapor
fluent-postgres-driver
🐘 PostgreSQL driver for Fluent.
Stars: ✭ 120 (-24.53%)
Mutual labels:  vapor, server-side-swift, swift-linux
Fluent
Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
Stars: ✭ 1,071 (+573.58%)
Mutual labels:  server-side-swift, vapor, swift-linux
Redis
Vapor provider for RediStack
Stars: ✭ 434 (+172.96%)
Mutual labels:  server-side-swift, vapor, swift-linux
fluent-mysql-driver
🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
Stars: ✭ 69 (-56.6%)
Mutual labels:  vapor, server-side-swift, swift-linux
auth
👤 Authentication and Authorization framework for Fluent.
Stars: ✭ 51 (-67.92%)
Mutual labels:  vapor, server-side-swift, swift-linux
Htmlkit
A type-safe DSL that renders dynamic HTML templates in Swift
Stars: ✭ 229 (+44.03%)
Mutual labels:  server-side-swift, vapor, swift-linux
Leaf
🍃 An expressive, performant, and extensible templating language built for Swift.
Stars: ✭ 310 (+94.97%)
Mutual labels:  server-side-swift, vapor, swift-linux
Jwt
Vapor JWT provider
Stars: ✭ 266 (+67.3%)
Mutual labels:  server-side-swift, vapor, swift-linux
Fluent Sqlite Driver
Fluent driver for SQLite
Stars: ✭ 51 (-67.92%)
Mutual labels:  server-side-swift, vapor, swift-linux
Api Template
💧 A starting point for Vapor APIs.
Stars: ✭ 130 (-18.24%)
Mutual labels:  server-side-swift, vapor, swift-linux
sqlite-kit
Non-blocking SQLite client library with SQL builder built on SwiftNIO
Stars: ✭ 51 (-67.92%)
Mutual labels:  vapor, server-side-swift, swift-linux
Core
🌎 Utility package containing tools for byte manipulation, Codable, OS APIs, and debugging.
Stars: ✭ 62 (-61.01%)
Mutual labels:  server-side-swift, vapor, swift-linux
Console Kit
💻 APIs for creating interactive CLI tools.
Stars: ✭ 252 (+58.49%)
Mutual labels:  server-side-swift, vapor, swift-linux
async
⏱ Promises and reactive-streams in Swift built for high-performance and scalability.
Stars: ✭ 35 (-77.99%)
Mutual labels:  vapor, server-side-swift, swift-linux
Http
🚀 Non-blocking, event-driven HTTP built on Swift NIO.
Stars: ✭ 220 (+38.36%)
Mutual labels:  server-side-swift, vapor, swift-linux
routing-kit
🚍 High-performance trie-node router.
Stars: ✭ 95 (-40.25%)
Mutual labels:  vapor, server-side-swift, swift-linux
Sockets
🔌 Non-blocking TCP socket layer, with event-driven server and client.
Stars: ✭ 559 (+251.57%)
Mutual labels:  server-side-swift, vapor, swift-linux
Open Crypto
🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Stars: ✭ 115 (-27.67%)
Mutual labels:  server-side-swift, vapor, swift-linux
MySQL Documentation Team Chat MIT License Continuous Integration Swift 5.2

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

Major Releases

The table below shows a list of PostgresKit major releases alongside their compatible NIO and Swift versions.

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"

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

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

Supported Platforms

MySQLKit supports the following platforms:

  • Ubuntu 16.04+
  • macOS 10.15+

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.

import MySQLKit

let configuration = MySQLConfiguration(
    hostname: "localhost",
    port: 3306,
    username: "vapor_username",
    password: "vapor_password",
    database: "vapor_database"
)

URL string based configuration is also supported.

guard let configuration = MySQLConfiguration(url: "mysql://...") else {
    ...
}

To connect via unix-domain sockets, use unixDomainSocketPath instead of hostname and port.

let configuration = MySQLConfiguration(
    unixDomainSocketPath: "/path/to/socket",
    username: "vapor_username",
    password: "vapor_password",
    database: "vapor_database"
)

Connection Pool

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.

pools.withConnection { conn 
    print(conn) // MySQLConnection on randomly chosen event loop
}

To get a pool for a specific event loop, use pool(for:). This returns an EventLoopConnectionPool.

let eventLoop: EventLoop = ...
let pool = pools.pool(for: eventLoop)

pool.withConnection { conn
    print(conn) // MySQLConnection on eventLoop
}

MySQLDatabase

Both EventLoopGroupConnectionPool and EventLoopConnectionPool can be used to create instances of MySQLDatabase.

let mysql = pool.database(logger: ...) // MySQLDatabase
let rows = try mysql.simpleQuery("SELECT @@version;").wait()

Visit MySQLNIO's docs for more information on using MySQLDatabase.

SQLDatabase

A MySQLDatabase can be used to create an instance of SQLDatabase.

let sql = mysql.sql() // SQLDatabase
let planets = try sql.select().column("*").from("planets").all().wait()

Visit SQLKit's docs for more information on using SQLDatabase.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].