Skip to content

Commit e942086

Browse files
authored
Merge pull request #52 from vapor/1.0
1.0
2 parents cffa4b2 + 30922db commit e942086

File tree

4 files changed

+10
-151
lines changed

4 files changed

+10
-151
lines changed

.swift-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ install:
1717
sudo mysql_install_db;
1818
fi
1919
- mysql -u root --password="" -e 'create database test;'
20-
- eval "$(curl -sL swift.vapor.sh/travis)"
20+
- eval "$(curl -sL https://swift.vapor.sh/swift-install)"
2121
script:
2222
# Build MySQL
2323
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ let package = Package(
44
name: "MySQL",
55
dependencies: [
66
// Module map for `libmysql`
7-
.Package(url: "https://github.com/vapor/cmysql.git", majorVersion: 0, minor: 3),
7+
.Package(url: "https://github.com/vapor/cmysql.git", majorVersion: 1),
88

99
// Data structure for converting between multiple representations
10-
.Package(url: "https://github.com/vapor/node.git", majorVersion: 0, minor: 6),
10+
.Package(url: "https://github.com/vapor/node.git", majorVersion: 1),
1111

1212
// Core extensions, type-aliases, and functions that facilitate common tasks
13-
.Package(url: "https://github.com/vapor/core.git", majorVersion: 0, minor: 5),
13+
.Package(url: "https://github.com/vapor/core.git", majorVersion: 1),
1414

1515
// JSON parsing and serialization for storing arrays and objects in MySQL
16-
.Package(url: "https://github.com/vapor/json.git", majorVersion: 0, minor: 7)
16+
.Package(url: "https://github.com/vapor/json.git", majorVersion: 1)
1717
]
1818
)

README.md

Lines changed: 5 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,23 @@
11
# MySQL for Swift
22

3+
![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)
34
![Swift](https://camo.githubusercontent.com/0727f3687a1e263cac101c5387df41048641339c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53776966742d332e302d6f72616e67652e7376673f7374796c653d666c6174)
45
[![Build Status](https://travis-ci.org/vapor/mysql.svg?branch=master)](https://travis-ci.org/vapor/mysql)
56

6-
A Swift wrapper for MySQL.
7-
8-
- [x] Thread-Safe
9-
- [x] Prepared Statements
10-
- [x] Tested
11-
12-
This wrapper uses the latest MySQL fetch API to enable performant prepared statements and output bindings. Data is sent to and received from the MySQL server in its native data type without converting to and from strings.
7+
This wrapper uses the latest MySQL fetch API to enable performant prepared statements and output bindings. Data is sent to and received from the MySQL server in its native data type without converting to and from strings.
138

149
The Swift wrappers around the MySQL's C structs and pointers automatically manage closing connections and deallocating memeory. Additionally, the MySQL library API is used to perform thread safe, performant queries to the database.
1510

1611
~40 assertions tested on Ubuntu 14.04 and macOS 10.11 on every push.
1712

18-
## 📖 Examples
19-
20-
### Connecting to the Database
21-
22-
```swift
23-
import MySQL
24-
25-
let mysql = try MySQL.Database(
26-
host: "127.0.0.1",
27-
user: "root",
28-
password: "",
29-
database: "test"
30-
)
31-
```
32-
33-
### Select
34-
35-
```swift
36-
let version = try mysql.execute("SELECT @@version")
37-
```
38-
39-
### Prepared Statement
40-
41-
The second parameter to `execute()` is an array of `MySQL.Value`s.
42-
43-
```swift
44-
let results = try mysql.execute("SELECT * FROM users WHERE age >= ?", [.int(21)])
45-
```
46-
47-
```swift
48-
public enum Value {
49-
case string(String)
50-
case int(Int)
51-
case uint(UInt)
52-
case double(Double)
53-
case null
54-
}
55-
```
56-
57-
### Connection
58-
59-
Each call to `execute()` creates a new connection to the MySQL database. This ensures thread safety since a single connection cannot be used on more than one thread.
60-
61-
If you would like to re-use a connection between calls to execute, create a reusable connection and pass it as the third parameter to `execute()`.
62-
63-
```swift
64-
let connection = msyql.makeConnection()
65-
let result = try mysql.execute("SELECT LAST_INSERTED_ID() as id", [], connection)
66-
```
67-
68-
No need to worry about closing the connection.
69-
70-
## 🚀 Building
71-
72-
### macOS
73-
74-
#### Using brew
75-
76-
Install MySQL
77-
78-
```shell
79-
brew install mysql
80-
brew link mysql
81-
mysql.server start
82-
```
83-
84-
Link MySQL during `swift build`
85-
86-
```shell
87-
swift build -Xswiftc -I/usr/local/include/mysql -Xlinker -L/usr/local/lib
88-
```
89-
90-
`-I` tells the compiler where to find the MySQL header files, and `-L` tells the linker where to find the library. This is required to compile and run on macOS.
91-
92-
#### Using macports
93-
94-
Install MySQL
95-
96-
```shell
97-
sudo port install mysql57
98-
sudo port select mysql mysql57
99-
```
100-
101-
Link MySQL during `swift build`
102-
103-
```shell
104-
swift build -Xswiftc -I/opt/local/include/mysql57/mysql/mysql -Xlinker -L/opt/local/lib/mysql57/mysql
105-
```
106-
107-
`-I` tells the compiler where to find the MySQL header files, and `-L` tells the linker where to find the library. This is required to compile and run on macOS.
108-
109-
### Linux
110-
111-
Install MySQL
112-
113-
```shell
114-
sudo apt-get update
115-
sudo apt-get install -y mysql-server libmysqlclient-dev
116-
sudo mysql_install_db
117-
sudo service mysql start
118-
```
119-
120-
`swift build` should work normally.
121-
122-
### Travis
123-
124-
Travis builds Swift MySQL on both Ubuntu 14.04 and macOS 10.11. Check out the `.travis.yml` file to see how this package is built and compiled during testing.
125-
126-
### Heroku
127-
128-
If you're deploying a Vapor app to heroku with MySQL, you need to set the buildpack to `https://github.com/loganwright/heroku-buildpack-swift`.
129-
130-
You can do this by going to `https://dashboard.heroku.com/apps/<#your-app-here#>/settings`
131-
and adding the buildpack or from command line in your app directory by running
132-
`heroku buildpacks:set https://github.com/loganwright/heroku-buildpack-swift`.
133-
134-
## * Fluent
135-
136-
This wrapper was created to power [Fluent](https://github.com/qutheory/fluent), an ORM for Swift.
137-
138-
## 🌏 Environment
139-
140-
|MySQL|Xcode|Swift|
141-
|:-:|:-:|:-:|
142-
|0.6.x|8.0 GM|DEVELOPMENT-SNAPSHOT-2016-09-06-a|
143-
|0.5.x|8.0 Beta **6**|DEVELOPMENT-SNAPSHOT-2016-08-18-a|
144-
|0.4.x|8.0 Beta **3**|DEVELOPMENT-SNAPSHOT-2016-07-25-a|
145-
|0.3.x|8.0 Beta **3**|DEVELOPMENT-SNAPSHOT-2016-07-25-a|
146-
|0.2.x|7.3.x|DEVELOPMENT-SNAPSHOT-2016-06-20-a|
147-
|0.1.x|7.3.x|DEVELOPMENT-SNAPSHOT-2016-06-06-a|
148-
14913
## 📖 Documentation
15014

151-
Visit the Vapor web framework's [documentation](http://docs.qutheory.io) for instructions on how to install Swift 3.
15+
Visit the Vapor web framework's [documentation](http://docs.vapor.codes) for instructions on how to use this package.
15216

15317
## 💧 Community
15418

155-
We pride ourselves on providing a diverse and welcoming community. Join your fellow Vapor developers in [our slack](slack.qutheory.io) and take part in the conversation.
19+
Join the welcoming community of fellow Vapor developers in [slack](http://vapor.team).
15620

15721
## 🔧 Compatibility
15822

159-
Node has been tested on OS X 10.11, Ubuntu 14.04, and Ubuntu 15.10.
160-
161-
## 👥 Author
162-
163-
Created by [Tanner Nelson](https://github.com/tannernelson).
23+
This package has been tested on macOS and Ubuntu.

0 commit comments

Comments
 (0)