Skip to content

Commit 6657349

Browse files
authored
Merge pull request #43 from tuken/swift4
Swift4
2 parents 758026a + 8cdb47b commit 6657349

File tree

10 files changed

+64
-27
lines changed

10 files changed

+64
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.build
33
/Packages
44
/*.xcodeproj
5+
Package.resolved

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
language: generic
55
sudo: required
66
dist: trusty
7-
osx_image: xcode8
7+
osx_image: xcode9
88

99
before_install:
1010
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh Scripts/install-mysql-5.7.sh; fi

Package.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
// swift-tools-version:4.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
14
import PackageDescription
25

36
let package = Package(
47
name: "SwiftKnex",
5-
targets: [
6-
Target(name: "Mysql"),
7-
Target(name: "SwiftKnex", dependencies: ["Mysql"]),
8-
Target(name: "SwiftKnexMigration", dependencies: ["SwiftKnex", "Mysql"])
8+
products: [
9+
.library(name: "SwiftKnex", targets: ["SwiftKnex"]),
10+
.executable(name: "SwiftKnexMigration", targets: ["SwiftKnexMigration"]),
911
],
1012
dependencies: [
11-
.Package(url: "https://github.com/noppoMan/Prorsum.git", majorVersion: 0, minor: 1)
13+
.package(url: "https://github.com/noppoMan/Prorsum.git", from: "0.3.0")
14+
],
15+
targets: [
16+
.target(name: "Mysql", dependencies: ["Prorsum"]),
17+
.target(name: "SwiftKnex", dependencies: ["Mysql"]),
18+
.target(name: "SwiftKnexMigration", dependencies: ["SwiftKnex", "Mysql"]),
19+
.testTarget(name: "SwiftKnexTests", dependencies: ["SwiftKnex", "Mysql"]),
1220
]
1321
)

Scripts/install-mysql-5.7.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
sudo service mysql stop || echo "mysql not stopped"
44
sudo stop mysql-5.6 || echo "mysql-5.6 not stopped"
55
echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
6-
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
7-
sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
6+
wget http://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
7+
sudo dpkg --install mysql-apt-config_0.8.9-1_all.deb
88
sudo apt-get update -q
99
sudo apt-get install -q -y -o Dpkg::Options::=--force-confnew mysql-server
1010
sudo mysql_upgrade
@@ -13,7 +13,7 @@ set -x
1313
set -e
1414
sudo mysqld_safe --skip-grant-tables &
1515
sleep 4
16-
sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
16+
sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where user='root'; update user set plugin='mysql_native_password'; FLUSH PRIVILEGES;"
1717
sudo kill -9 `sudo cat /var/lib/mysql/mysqld_safe.pid`
1818
sudo kill -9 `sudo cat /var/run/mysqld/mysqld.pid`
1919
sudo service mysql restart

Scripts/install-swift.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
VERSION="3.0.1"
3+
VERSION="4.0.3"
44

55
# Determine OS
66
UNAME=`uname`;
@@ -11,11 +11,16 @@ else
1111
if [[ $UNAME == "Linux" ]];
1212
then
1313
UBUNTU_RELEASE=`lsb_release -a 2>/dev/null`;
14-
if [[ $UBUNTU_RELEASE == *"15.10"* ]];
14+
if [[ $UBUNTU_RELEASE == *"16.10"* ]];
1515
then
16-
OS="ubuntu1510";
16+
OS="ubuntu1610";
1717
else
18-
OS="ubuntu1404";
18+
if [[ $UBUNTU_RELEASE == *"16.04"* ]];
19+
then
20+
OS="ubuntu1604";
21+
else
22+
OS="ubuntu1404";
23+
fi
1924
fi
2025
fi
2126
fi
@@ -24,11 +29,16 @@ if [[ $OS != "macos" ]];
2429
then
2530
sudo apt-get install -y clang libicu-dev uuid-dev
2631

27-
if [[ $OS == "ubuntu1510" ]];
32+
if [[ $OS == "ubuntu1610" ]];
2833
then
29-
SWIFTFILE="swift-$VERSION-RELEASE-ubuntu15.10";
34+
SWIFTFILE="swift-$VERSION-RELEASE-ubuntu16.10";
3035
else
31-
SWIFTFILE="swift-$VERSION-RELEASE-ubuntu14.04";
36+
if [[ $OS == "ubuntu1604" ]];
37+
then
38+
SWIFTFILE="swift-$VERSION-RELEASE-ubuntu16.04";
39+
else
40+
SWIFTFILE="swift-$VERSION-RELEASE-ubuntu14.04";
41+
fi
3242
fi
3343
wget https://swift.org/builds/swift-$VERSION-release/$OS/swift-$VERSION-RELEASE/$SWIFTFILE.tar.gz
3444
tar -zxf $SWIFTFILE.tar.gz

Sources/Mysql/Extensions/Bytes.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import Foundation
4444

45-
func arrayOfBytes<T: Integer>(_ value: T, length totalBytes: Int = MemoryLayout<T>.size) -> Array<UInt8> {
45+
func arrayOfBytes<T: BinaryInteger>(_ value: T, length totalBytes: Int = MemoryLayout<T>.size) -> Array<UInt8> {
4646
let valuePointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
4747
valuePointer.pointee = value
4848

@@ -137,7 +137,11 @@ extension Int {
137137
res |= Int(arr[arr.startIndex + i]) << Int(i*8)
138138
}
139139
//self = res
140-
self = Int(arr[arr.startIndex + 3])<<24 | Int(arr[arr.startIndex + 2])<<16 | Int(arr[arr.startIndex + 1])<<8 | Int(arr[arr.startIndex])
140+
let i4 = Int(arr[arr.startIndex + 3])<<24
141+
let i3 = Int(arr[arr.startIndex + 2])<<16
142+
let i2 = Int(arr[arr.startIndex + 1])<<8
143+
let i1 = Int(arr[arr.startIndex])
144+
self = i4 | i3 | i2 | i1
141145
}
142146

143147
func array() ->[UInt8] {
@@ -216,15 +220,23 @@ extension Sequence where Iterator.Element == UInt8 {
216220
return elem
217221
}
218222

219-
return Int32(arr[3])<<24 | Int32(arr[2])<<16 | Int32(arr[1])<<8 | Int32(arr[0])
223+
let i4 = Int32(arr[3])<<24
224+
let i3 = Int32(arr[2])<<16
225+
let i2 = Int32(arr[1])<<8
226+
let i1 = Int32(arr[0])
227+
return i4 | i3 | i2 | i1
220228
}
221229

222230
func uInt32() -> UInt32 {
223231
let arr = self.map { (elem) -> UInt8 in
224232
return elem
225233
}
226234

227-
return UInt32(arr[3])<<24 | UInt32(arr[2])<<16 | UInt32(arr[1])<<8 | UInt32(arr[0])
235+
let u4 = UInt32(arr[3])<<24
236+
let u3 = UInt32(arr[2])<<16
237+
let u2 = UInt32(arr[1])<<8
238+
let u1 = UInt32(arr[0])
239+
return u4 | u3 | u2 | u1
228240
}
229241

230242
func uInt64() -> UInt64 {

Sources/Mysql/Mysql.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,15 @@ func lenEncInt(_ b: [UInt8]) -> (UInt64?, Int) {
249249

250250
// 254: value of following 8
251251
case 0xfe:
252-
return (UInt64(b[1]) | UInt64(b[2])<<8 | UInt64(b[3])<<16 |
253-
UInt64(b[4])<<24 | UInt64(b[5])<<32 | UInt64(b[6])<<40 |
254-
UInt64(b[7])<<48 | UInt64(b[8])<<56, 9)
252+
let u1 = UInt64(b[1])
253+
let u2 = UInt64(b[2])<<8
254+
let u3 = UInt64(b[3])<<16
255+
let u4 = UInt64(b[4])<<24
256+
let u5 = UInt64(b[5])<<32
257+
let u6 = UInt64(b[6])<<40
258+
let u7 = UInt64(b[7])<<48
259+
let u8 = UInt64(b[8])<<56
260+
return (u1 | u2 | u3 | u4 | u5 | u6 | u7 | u8, 9)
255261
default:
256262
break
257263
}

Sources/SwiftKnex/Migration/Migrator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func validateMigration(name: String) throws -> String {
6060
}
6161

6262
let ts = segments[1]
63-
if ts.characters.count != 14 {
63+
if ts.count != 14 {
6464
throw MigrationError.timestampFormatShouldBe("yyyyMMddHHmmss")
6565
}
6666

67-
let year = ts.substring(to: ts.index(ts.startIndex, offsetBy: 4))
67+
let year = ts[ts.startIndex...ts.index(ts.startIndex, offsetBy: 4)]
6868
let month = ts[ts.index(ts.startIndex, offsetBy: 4)..<ts.index(ts.startIndex, offsetBy: 6)]
6969
let day = ts[ts.index(ts.startIndex, offsetBy: 6)..<ts.index(ts.startIndex, offsetBy: 8)]
7070
let hour = ts[ts.index(ts.startIndex, offsetBy: 8)..<ts.index(ts.startIndex, offsetBy:10)]

Sources/SwiftKnex/QueryBuilder/BatchInsertQueryBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct BatchInsertQueryBuilder: QueryBuildable {
2121

2222
func build() throws -> (String, [Any]) {
2323
// TODO should throws Error
24-
guard let fields = collection.max(by: { $0.0.count < $0.1.count }) else {
24+
guard let fields = collection.max(by: { $0.count < $1.count }) else {
2525
throw QueryBuilderError.emptyValues
2626
}
2727

Sources/SwiftKnexMigration/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ case "create":
7373
let now = Date().toMigrationFileDateTimeString()
7474
let fileName = "\(now)_\(CommandLine.arguments[2])"
7575

76-
let root = #file.characters
76+
let root = #file
7777
.split(separator: "/", omittingEmptySubsequences: false)
7878
.dropLast(3)
7979
.map { String($0) }

0 commit comments

Comments
 (0)