All Projects → novi → Mysql Swift

novi / Mysql Swift

Licence: mit
A type safe MySQL client for Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Mysql Swift

Mysql Kit
🐬 Pure Swift MySQL client built on non-blocking, event-driven sockets.
Stars: ✭ 159 (+7.43%)
Mutual labels:  mysql, server-side-swift
Perfect Mysql
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.
Stars: ✭ 108 (-27.03%)
Mutual labels:  mysql, server-side-swift
Sql Kit
*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Stars: ✭ 115 (-22.3%)
Mutual labels:  mysql, server-side-swift
Bitter.core
bitter.core is a high-performance and easy-to-use netcore / netframework orm framework. I think you'll love it. designed for development and efficiency. efficiency, high performance and high stability are always the pursuit of programmers. bittercore was born for that. you want to be lazy, even lazier! simple, more simple! controllable, more controllable! please use it bitter.Core .
Stars: ✭ 136 (-8.11%)
Mutual labels:  mysql
Easyappointments
Easy!Appointments is a highly customizable web application that allows customers to book appointments with you via a sophisticated web interface. Moreover, it provides the ability to sync your data with Google Calendar so you can use them with other services. It is an open source project that you can download and install even for commercial use. Easy!Appointments will run smoothly with your existing website as it can be installed in a single folder of the server and of course share an existing database.
Stars: ✭ 2,013 (+1260.14%)
Mutual labels:  mysql
Dapper.linq
Dapper.Linq
Stars: ✭ 143 (-3.38%)
Mutual labels:  mysql
Canal Elasticsearch
基于阿里巴的canal向elasticsearch中同步数据mysql数据的小工具
Stars: ✭ 147 (-0.68%)
Mutual labels:  mysql
Mysqldump
Node Module to Create a Backup from MySQL
Stars: ✭ 136 (-8.11%)
Mutual labels:  mysql
Go Mysqlstack
MySQL protocol library implementing in Go (golang)
Stars: ✭ 145 (-2.03%)
Mutual labels:  mysql
Js Sql Parser
SQL(select) parser written with jison. parse SQL into abstract syntax tree(AST) and stringify back to SQL. sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html
Stars: ✭ 141 (-4.73%)
Mutual labels:  mysql
Sqlingo
💥 A lightweight DSL & ORM which helps you to write SQL in Go.
Stars: ✭ 142 (-4.05%)
Mutual labels:  mysql
Owasp Mth3l3m3nt Framework
OWASP Mth3l3m3nt Framework is a penetration testing aiding tool and exploitation framework. It fosters a principle of attack the web using the web as well as pentest on the go through its responsive interface.
Stars: ✭ 139 (-6.08%)
Mutual labels:  mysql
Sns Forum Website
牛客网高级项目(SNS+社区问答类网站)
Stars: ✭ 143 (-3.38%)
Mutual labels:  mysql
Sql Fundamentals
👨‍🏫 Mike's SQL Fundamentals and Professional SQL Courses
Stars: ✭ 140 (-5.41%)
Mutual labels:  mysql
Lapidus
Stream your PostgreSQL, MySQL or MongoDB databases anywhere, fast.
Stars: ✭ 145 (-2.03%)
Mutual labels:  mysql
Yoshop
萤火小程序商城,是在Thinkphp5基础上搭建的一个PHP项目,前后端完全开源。Thinkphp5以易学易用著称,让您轻松打造自己的独立商城,同时也方便二次开发,让您快速搭建个性化独立商城。
Stars: ✭ 137 (-7.43%)
Mutual labels:  mysql
Dapper.fsharp
Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL and PostgreSQL
Stars: ✭ 145 (-2.03%)
Mutual labels:  mysql
Koa2 Blog
第一个web项目,仿照cnode,欢迎新建账号试用
Stars: ✭ 141 (-4.73%)
Mutual labels:  mysql
Limesurvey
Limesurvey is the number one open-source survey software.
Stars: ✭ 1,918 (+1195.95%)
Mutual labels:  mysql
Oxidtools
200 TOOLS BY 0XID4FF0X FOR TERMUX
Stars: ✭ 143 (-3.38%)
Mutual labels:  mysql

mysql-swift

Platform Linux, macOS CircleCI

MySQL client library for Swift. This is inspired by Node.js' mysql.

  • Based on libmysqlclient
  • Raw SQL query
  • Simple query formatting and escaping (same as Node's)
  • Mapping queried results to Codable structs or classes

Note: No asynchronous I/O support currently. It depends libmysqlclient.

// Declare a model

struct User: Codable, QueryParameter {
    let id: Int
    let userName: String
    let age: Int?
    let status: Status
    let createdAt: Date
    
    enum Status: String, Codable {
        case created = "created"
        case verified = "verified"
    }
    
    private enum CodingKeys: String, CodingKey {
        case id
        case userName = "user_name"
        case age
        case status = "status"
        case createdAt = "created_at"
    }
}
    
// Selecting
let nameParam = "some one"
let ids: [QueryParameter] = [1, 2, 3, 4, 5, 6]
let optionalInt: Int? = nil
let rows: [User] = try conn.query("SELECT id,user_name,status,status,created_at FROM `user` WHERE (age > ? OR age is ?) OR name = ? OR id IN (?)", [50, optionalInt, nameParam, QueryArray(ids)] ])

// Inserting
let age: Int? = 26
let user = User(id: 0, userName: "novi", age: age, status: .created, createdAt: Date())
let status = try conn.query("INSERT INTO `user` SET ?", [user]) as QueryStatus
let newId = status.insertedId

// Updating
let tableName = "user"
let defaultAge = 30
try conn.query("UPDATE ?? SET age = ? WHERE age is NULL;", [tableName, defaultAge])

Requirements

  • Swift 5.0 or later
  • MariaDB or MySQL Connector/C (libmysqlclient) 2.2.3 or later

macOS

Install pkg-config .pc file in cmysql or cmysql-mariadb.

# cmysql
$ brew tap novi/tap
$ brew install novi/tap/cmysql

# cmysql-mariadb
$ brew tap novi/tap
$ brew install novi/tap/cmysqlmariadb

Ubuntu

$ sudo apt-get install libmariadbclient-dev

Installation

Swift Package Manager

  • Add mysql-swift to Package.swift of your project.
// swift-tools-version:5.2
import PackageDescription

let package = Package(
    ...,
    dependencies: [
        .package(url: "https://github.com/novi/mysql-swift.git", .upToNextMajor(from: "0.9.0"))
    ],
    targets: [
        .target(
            name: "YourAppOrLibrary",
            dependencies: [
                // add a dependency
                .product(name: "MySQL", package: "mysql-swift")
            ]
        )
    ]
)

Usage

Connection & Querying

  1. Create a pool with options (hostname, port, password,...).
  2. Use ConnectionPool.execute(). It automatically get and release a connection.
let option = Option(host: "your.mysql.host"...) // Define and create your option type
let pool = ConnectionPool(option: option) // Create a pool with the option
let rows: [User] = try pool.execute { conn in
	// The connection `conn` is held in this block
	try conn.query("SELECT * FROM users;") // And it returns result to outside execute block
}

Transaction

let wholeStaus: QueryStatus = try pool.transaction { conn in
	let status = try conn.query("INSERT INTO users SET ?;", [user]) as QueryStatus // Create a user
	let userId = status.insertedId // the user's id
	try conn.query("UPDATE info SET some_value = ? WHERE some_key = 'latest_user_id' ", [userId]) // Store user's id that we have created the above
}
wholeStaus.affectedRows == 1 // true

License

MIT

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].