Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #55 from vapor-community/swift4
Browse files Browse the repository at this point in the history
Updates for Swift 4
  • Loading branch information
sroebert authored Sep 5, 2017
2 parents a175cc3 + 8888afc commit cfbfa12
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Packages
Database
*.xcodeproj
Package.pins

Package.resolved
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ matrix:
include:
- os: osx
osx_image: xcode8.3
- os: osx
osx_image: xcode9

before_install:
- gem install xcpretty
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// swift-tools-version:3.1
import PackageDescription

let package = Package(
Expand Down
23 changes: 23 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "PostgreSQL",
products: [
.library(name: "PostgreSQL", targets: ["PostgreSQL"]),
],
dependencies: [
// Module map for `libpq`
.package(url: "https://github.com/vapor-community/cpostgresql.git", .upToNextMajor(from: "2.1.0")),

// Data structure for converting between multiple representations
.package(url: "https://github.com/vapor/node.git", .upToNextMajor(from: "2.1.0")),

// Core extensions, type-aliases, and functions that facilitate common tasks
.package(url: "https://github.com/vapor/core.git", .upToNextMajor(from: "2.1.2"))
],
targets: [
.target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]),
.testTarget(name: "PostgreSQLTests", dependencies: ["PostgreSQL"]),
]
)
20 changes: 16 additions & 4 deletions Sources/PostgreSQL/Bind/BinaryUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,16 @@ struct BinaryUtils {
digitIndex += 1
}

let endIndex = string.index(decimalIndex, offsetBy: dscale + 1)
string = string.substring(to: endIndex)
return string
#if swift(>=3.2)
let maxOffset = string.distance(from: decimalIndex, to: string.endIndex)
let offset = min(maxOffset, dscale)
let endIndex = string.index(decimalIndex, offsetBy: offset)

return String(string[..<endIndex])
#else
let endIndex = string.index(decimalIndex, offsetBy: dscale + 1)
return string.substring(to: endIndex)
#endif
}
}

Expand Down Expand Up @@ -552,6 +559,11 @@ struct BinaryUtils {
.joined()

// Limit the bitString to the bitLength
return bitString.substring(to: bitString.index(bitString.startIndex, offsetBy: Int(bitLength)))
let toIndex = bitString.index(bitString.startIndex, offsetBy: Int(bitLength))
#if swift(>=4.0)
return String(bitString[..<toIndex])
#else
return bitString.substring(to: toIndex)
#endif
}
}
2 changes: 1 addition & 1 deletion Sources/PostgreSQL/Bind/Bind+Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension Bind {
case .array(let supportedArrayType):
return Bind.parse(type: supportedArrayType, configuration: configuration, value: value, length: length)

case .unsupported(let oid):
case .unsupported(_):
// Unsupported Oid type for PostgreSQL binding.

// Fallback to simply passing on the bytes
Expand Down
14 changes: 12 additions & 2 deletions Tests/PostgreSQLTests/BinaryUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ class BinaryUtilsTests: XCTestCase {
for (hexString, timestamp) in integerTimestampTests {
var bytes = hexString.hexStringBytes
let parsedDate = BinaryUtils.parseTimetamp(value: &bytes, isInteger: true)
XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)

#if swift(>=3.2)
XCTAssertEqual(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)
#else
XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)
#endif
}
}

Expand All @@ -231,7 +236,12 @@ class BinaryUtilsTests: XCTestCase {
for (hexString, timestamp) in floatTimestampTests {
var bytes = hexString.hexStringBytes
let parsedDate = BinaryUtils.parseTimetamp(value: &bytes, isInteger: false)
XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)

#if swift(>=3.2)
XCTAssertEqual(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)
#else
XCTAssertEqualWithAccuracy(timestamp.timeIntervalSince1970, parsedDate.timeIntervalSince1970, accuracy: 0.001)
#endif
}
}

Expand Down

0 comments on commit cfbfa12

Please sign in to comment.