diff --git a/.travis.yml b/.travis.yml index 64d80cf..906acbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,15 @@ matrix: - os: linux dist: trusty sudo: required - services: - - postgresql addons: - postgresql: "9.5" + postgresql: 9.5 - os: osx - osx_image: xcode8 + osx_image: xcode8.3 install: - - "[ $TRAVIS_OS_NAME = osx ] && pg_ctl -D /usr/local/var/postgres start && sleep 3 || true" - - "[ $TRAVIS_OS_NAME = osx ] && createuser -s postgres || true" - - psql -U postgres -c 'CREATE DATABASE test;' - + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pg_ctl -D /usr/local/var/postgres start && sleep 3 || true; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo -u travis createuser -s -p 5432 postgres; fi + - psql -U postgres -c 'create database test;' script: - - eval "$(curl -sL swift.vapor.sh/ci)" - - eval "$(curl -sL swift.vapor.sh/codecov)" + - eval "$(curl -sL https://swift.vapor.sh/ci-3.1)" + - eval "$(curl -sL https://swift.vapor.sh/codecov)" diff --git a/Package.swift b/Package.swift index 8ee2770..7c083bc 100644 --- a/Package.swift +++ b/Package.swift @@ -3,8 +3,13 @@ import PackageDescription let package = Package( name: "PostgreSQL", dependencies: [ - .Package(url: "https://github.com/vapor/cpostgresql.git", majorVersion: 1), - .Package(url: "https://github.com/vapor/node.git", majorVersion: 1), - .Package(url: "https://github.com/vapor/core.git", majorVersion: 1), + // Module map for `libpq` + .Package(url: "https://github.com/vapor/cpostgresql.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"])), + + // Data structure for converting between multiple representations + .Package(url: "https://github.com/vapor/node.git", Version(2,0,0, prereleaseIdentifiers: ["beta"])), + + // Core extensions, type-aliases, and functions that facilitate common tasks + .Package(url: "https://github.com/vapor/core.git", Version(2,0,0, prereleaseIdentifiers: ["beta"])), ] ) diff --git a/README.md b/README.md index 751fac3..6cae47c 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ # PostgreSQL for Swift +[![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)](https://swift.org) +[![Build Status](https://travis-ci.org/vapor/postgresql.svg?branch=master)](https://travis-ci.org/vapor/postgresql) + A Swift wrapper for PostgreSQL. - [x] Thread-Safe - [x] Prepared Statements - [x] Tested -This wrapper uses the latest PostgreSQL fetch API to enable performant prepared statements and output bindings. - -The Swift wrappers around the PostgreSQL's C structs and pointers automatically manage closing connections and deallocating memeory. Additionally, the PostgreSQL library API is used to perform thread safe, performant queries to the database. +This wrapper uses the latest PostgreSQL fetch API to enable performant prepared statements and output bindings. Data is sent to and received from the PostgreSQL server in its native data type without converting to and from strings. +The Swift wrappers around the PostgreSQL's C structs and pointers automatically manage closing connections and deallocating memory. Additionally, the PostgreSQL library API is used to perform thread safe, performant queries to the database. -## Examples +## 📖 Examples ### Connecting to the Database @@ -62,7 +64,7 @@ let result = try postgreSQL.execute("SELECT LAST_INSERTED_ID() as id", [], conne No need to worry about closing the connection. -## Building +## 🚀 Building ### macOS @@ -72,9 +74,6 @@ Install PostgreSQL brew install postgresql brew link postgresql brew services start postgresql - -// to stop -brew services stop postgresql ``` ### Linux @@ -87,14 +86,12 @@ sudo apt-get install postgresql postgresql-contrib libpq-dev psql -h dbhost -U username dbname ``` -`swift build` should work normally. +Use `vapor build` or `swift build`. ## Fluent -This wrapper was created to power [Fluent](https://github.com/qutheory/fluent), an ORM for Swift. - -## 👥 Authors - -Made by [Prince Ugwuh](https://twitter.com/Prince2k3) a member of Qutheory community. +This wrapper was created to power [Fluent](https://github.com/qutheory/fluent), an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping) for Swift. +## 👥 Contributors +Maintained by [Steven Roebert](https://github.com/sroebert), [Nate Bird](https://twitter.com/natesbird), [Prince Ugwuh](https://twitter.com/Prince2k3), and other members of the Vapor community. diff --git a/Sources/PostgreSQL/Connection.swift b/Sources/PostgreSQL/Connection.swift index b56803a..e073b1d 100644 --- a/Sources/PostgreSQL/Connection.swift +++ b/Sources/PostgreSQL/Connection.swift @@ -1,10 +1,4 @@ -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif - - +import CPostgreSQL public final class Connection: ConnInfoInitializable { public typealias ConnectionPointer = OpaquePointer @@ -20,7 +14,7 @@ public final class Connection: ConnInfoInitializable { public init(conninfo: ConnInfo) throws { let string: String - + switch conninfo { case .raw(let info): string = info @@ -29,33 +23,33 @@ public final class Connection: ConnInfoInitializable { case .basic(let host, let port, let database, let user, let password): string = "host='\(host)' port='\(port)' dbname='\(database)' user='\(user)' password='\(password)' client_encoding='UTF8'" } - + self.connection = PQconnectdb(string) if !self.connected { throw DatabaseError.cannotEstablishConnection(error) } } - + @discardableResult public func execute(_ query: String, _ values: [Node]? = []) throws -> [[String: Node]] { guard !query.isEmpty else { throw DatabaseError.noQuery } - + let values = values ?? [] - + var types: [Oid] = [] types.reserveCapacity(values.count) - + var paramValues: [[Int8]?] = [] paramValues.reserveCapacity(values.count) - + var lengths: [Int32] = [] lengths.reserveCapacity(values.count) - + var formats: [Int32] = [] formats.reserveCapacity(values.count) - + for value in values { let (bytes, oid, format) = value.postgresBindingData paramValues.append(bytes) @@ -63,7 +57,7 @@ public final class Connection: ConnInfoInitializable { lengths.append(Int32(bytes?.count ?? 0)) formats.append(format.rawValue) } - + let res: Result.Pointer = PQexecParams( connection, query, Int32(values.count), @@ -74,11 +68,11 @@ public final class Connection: ConnInfoInitializable { formats, DataFormat.binary.rawValue ) - + defer { PQclear(res) } - + switch Database.Status(result: res) { case .nonFatalError, .fatalError, .unknown: throw DatabaseError.invalidSQL(message: String(cString: PQresultErrorMessage(res))) @@ -110,28 +104,28 @@ public final class Connection: ConnInfoInitializable { guard let s = PQerrorMessage(connection) else { return "" } - return String(cString: s) + return String(cString: s) } deinit { try? close() } - + // MARK: - Load Configuration - + private func getConfiguration() throws -> Configuration { if let configuration = self.configuration { return configuration } - + let hasIntegerDatetimes = getBooleanParameterStatus(key: "integer_datetimes", default: true) - + let configuration = Configuration(hasIntegerDatetimes: hasIntegerDatetimes) self.configuration = configuration - + return configuration } - + private func getBooleanParameterStatus(key: String, `default` defaultValue: Bool = false) -> Bool { guard let value = PQparameterStatus(connection, "integer_datetimes") else { return defaultValue diff --git a/Sources/PostgreSQL/ConnectionInfo.swift b/Sources/PostgreSQL/ConnectionInfo.swift index bb914ae..831c202 100644 --- a/Sources/PostgreSQL/ConnectionInfo.swift +++ b/Sources/PostgreSQL/ConnectionInfo.swift @@ -1,8 +1,4 @@ -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif +import CPostgreSQL public enum ConnInfo { case raw(String) diff --git a/Sources/PostgreSQL/Database.swift b/Sources/PostgreSQL/Database.swift index adcccd7..17e069f 100644 --- a/Sources/PostgreSQL/Database.swift +++ b/Sources/PostgreSQL/Database.swift @@ -1,8 +1,4 @@ -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif +import CPostgreSQL public enum DatabaseError: Error { case cannotEstablishConnection(String) diff --git a/Sources/PostgreSQL/Node+Binding.swift b/Sources/PostgreSQL/Node+Binding.swift index bc41fb8..c25b4e1 100644 --- a/Sources/PostgreSQL/Node+Binding.swift +++ b/Sources/PostgreSQL/Node+Binding.swift @@ -7,7 +7,7 @@ protocol Bindable { extension Node: Bindable { var postgresBindingData: ([Int8]?, OID?, DataFormat) { - switch self { + switch wrapped { case .null: // PQexecParams converts nil pointer to NULL. // see: https://www.postgresql.org/docs/9.1/static/libpq-exec.html @@ -38,9 +38,14 @@ extension Node: Bindable { case .object(_): print("Unsupported Node type for PostgreSQL binding, everything except for .object is supported.") return (nil, nil, .string) + + default: + return (nil, nil, .string) } } - +} + +extension StructuredData { var postgresArrayElementString: String { switch self { case .null: @@ -69,6 +74,9 @@ extension Node: Bindable { case .object(_): print("Unsupported Node array type for PostgreSQL binding, everything except for .object is supported.") return "NULL" + + default: + return "" } } } diff --git a/Sources/PostgreSQL/Node+Oid.swift b/Sources/PostgreSQL/Node+Oid.swift index 1c79521..be36f0d 100644 --- a/Sources/PostgreSQL/Node+Oid.swift +++ b/Sources/PostgreSQL/Node+Oid.swift @@ -1,8 +1,4 @@ -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif +import CPostgreSQL import Foundation /// Oid values can be found in the following file: diff --git a/Sources/PostgreSQL/Result.swift b/Sources/PostgreSQL/Result.swift index 4e430fe..7178033 100644 --- a/Sources/PostgreSQL/Result.swift +++ b/Sources/PostgreSQL/Result.swift @@ -1,8 +1,4 @@ -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif +import CPostgreSQL class Result { typealias Pointer = OpaquePointer diff --git a/Sources/PostgreSQL/Status.swift b/Sources/PostgreSQL/Status.swift index 0bcacca..c8bbe37 100644 --- a/Sources/PostgreSQL/Status.swift +++ b/Sources/PostgreSQL/Status.swift @@ -1,10 +1,4 @@ - -#if os(Linux) - import CPostgreSQLLinux -#else - import CPostgreSQLMac -#endif - +import CPostgreSQL extension Database { public enum Status { diff --git a/Tests/PostgreSQLTests/ArrayTests.swift b/Tests/PostgreSQLTests/ArrayTests.swift index 5c374a1..7746a72 100644 --- a/Tests/PostgreSQLTests/ArrayTests.swift +++ b/Tests/PostgreSQLTests/ArrayTests.swift @@ -30,15 +30,15 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, int_array int[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let intArray = resultRow["int_array"] - XCTAssertNotNil(intArray?.nodeArray) - XCTAssertEqual(intArray!.nodeArray!.flatMap { $0.int }, rows[i]) + XCTAssertNotNil(intArray?.array) + XCTAssertEqual(intArray!.array!.flatMap { $0.int }, rows[i]) } } @@ -54,15 +54,15 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, string_array text[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let stringArray = resultRow["string_array"] - XCTAssertNotNil(stringArray?.nodeArray) - XCTAssertEqual(stringArray!.nodeArray!.flatMap { $0.string }, rows[i]) + XCTAssertNotNil(stringArray?.array) + XCTAssertEqual(stringArray!.array!.flatMap { $0.string }, rows[i]) } } @@ -79,15 +79,15 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, bool_array bool[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let boolArray = resultRow["bool_array"] - XCTAssertNotNil(boolArray?.nodeArray) - XCTAssertEqual(boolArray!.nodeArray!.flatMap { $0.bool }, rows[i]) + XCTAssertNotNil(boolArray?.array) + XCTAssertEqual(boolArray!.array!.flatMap { $0.bool }, rows[i]) } } @@ -103,18 +103,15 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, byte_array bytea[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let byteArray = resultRow["byte_array"] - XCTAssertNotNil(byteArray?.nodeArray) - XCTAssertEqual(byteArray!.nodeArray!.flatMap { node in - guard case .bytes(_) = node else { - return nil - } + XCTAssertNotNil(byteArray?.array) + XCTAssertEqual(byteArray!.array!.flatMap { node in return node }, rows[i]) } @@ -132,17 +129,17 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, int_array int[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.map { try $0.makeNode() }.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.map { try $0.makeNode(in: nil) }.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let intArray = resultRow["int_array"] - XCTAssertNotNil(intArray?.nodeArray) - XCTAssertEqual(intArray!.nodeArray!.count, rows[i].count) - XCTAssertEqual(intArray!.nodeArray!.flatMap { $0.int }, []) - XCTAssertEqual(intArray!.nodeArray!.flatMap { $0.isNull ? Node.null : nil }.count, rows[i].count) + XCTAssertNotNil(intArray?.array) + XCTAssertEqual(intArray!.array!.count, rows[i].count) + XCTAssertEqual(intArray!.array!.flatMap { $0.int }, []) + XCTAssertEqual(intArray!.array!.flatMap { $0.isNull ? Node.null : nil }.count, rows[i].count) } } @@ -158,7 +155,7 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, int_array int[][])") for row in rows { - let node = try Node.array(row.map { try $0.makeNode() }) + let node = try Node.array(row.map { try $0.makeNode(in: nil) }) try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [node]) } @@ -166,9 +163,9 @@ class ArrayTests: XCTestCase { XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let intArray = resultRow["int_array"] - XCTAssertNotNil(intArray?.nodeArray) + XCTAssertNotNil(intArray?.array) - let result = intArray!.nodeArray!.flatMap { $0.nodeArray?.flatMap { $0.int } } + let result = intArray!.array!.flatMap { $0.array?.flatMap { $0.int } } for (i, rowArray) in rows[i].enumerated() { XCTAssertEqual(result[i], rowArray) } @@ -188,15 +185,15 @@ class ArrayTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, int_array int[])") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") XCTAssertEqual(result.count, rows.count) for (i, resultRow) in result.enumerated() { let intArray = resultRow["int_array"] - XCTAssertNotNil(intArray?.nodeArray) - XCTAssertEqual(intArray!.nodeArray!, rows[i]) + XCTAssertNotNil(intArray?.array) + XCTAssertEqual(intArray!.array!, rows[i]) } } } diff --git a/Tests/PostgreSQLTests/PostgreSQLTests.swift b/Tests/PostgreSQLTests/PostgreSQLTests.swift index c59011f..ad97848 100644 --- a/Tests/PostgreSQLTests/PostgreSQLTests.swift +++ b/Tests/PostgreSQLTests/PostgreSQLTests.swift @@ -123,7 +123,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS parameterization") try postgreSQL.execute("CREATE TABLE parameterization (d FLOAT8, i INT, s VARCHAR(16), u INT)") - try postgreSQL.execute("INSERT INTO parameterization VALUES ($1, $2, $3, $4)", [.null, .null, "life".makeNode(), .null], on: nil) + try postgreSQL.execute("INSERT INTO parameterization VALUES ($1, $2, $3, $4)", [.null, .null, "life".makeNode(in: nil), .null], on: nil) try postgreSQL.execute("INSERT INTO parameterization VALUES (3.14, NULL, 'pi', NULL)") try postgreSQL.execute("INSERT INTO parameterization VALUES (NULL, NULL, 'life', 42)") @@ -210,7 +210,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, int2 int2, int4 int4, int8 int8)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2, $3)", [row.0.makeNode(), row.1.makeNode(), row.2.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2, $3)", [row.0.makeNode(in: nil), row.1.makeNode(in: nil), row.2.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -223,7 +223,7 @@ class PostgreSQLTests: XCTestCase { let int4 = resultRow["int4"] XCTAssertNotNil(int4?.int) XCTAssertEqual(int4!.int!, Int(rows[i].1)) - + let int8 = resultRow["int8"] XCTAssertNotNil(int8?.double) XCTAssertEqual(int8!.double!, Double(rows[i].2)) @@ -243,7 +243,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, float4 float4, float8 float8)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2)", [row.0.makeNode(), row.1.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2)", [row.0.makeNode(in: nil), row.1.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -275,7 +275,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, numeric numeric)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -301,7 +301,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, json json, jsonb jsonb)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2)", [row.makeNode(), row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1, $2)", [row.makeNode(in: nil), row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -337,7 +337,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, interval interval)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row[0].makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row[0].makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -359,7 +359,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, point point)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -381,7 +381,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, lseg lseg)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -404,7 +404,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, path path)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -426,7 +426,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, box box)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -449,7 +449,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, polygon polygon)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -471,7 +471,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, circle circle)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -497,7 +497,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, inet inet)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -523,7 +523,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, cidr cidr)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -552,7 +552,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, macaddr macaddr)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -580,7 +580,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, bits bit(5))") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -610,7 +610,7 @@ class PostgreSQLTests: XCTestCase { try postgreSQL.execute("DROP TABLE IF EXISTS foo") try postgreSQL.execute("CREATE TABLE foo (id serial, bits bit varying)") for row in rows { - try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode()]) + try postgreSQL.execute("INSERT INTO foo VALUES (DEFAULT, $1)", [row.makeNode(in: nil)]) } let result = try postgreSQL.execute("SELECT * FROM foo ORDER BY id ASC") @@ -658,11 +658,6 @@ class PostgreSQLTests: XCTestCase { for resultRow in result { let value = resultRow["oid"] XCTAssertNotNil(value) - - guard case .bytes(_) = value! else { - XCTFail("Result should be in bytes") - return - } } } } diff --git a/circle.yml b/circle.yml index c9b6510..3f7be70 100644 --- a/circle.yml +++ b/circle.yml @@ -1,8 +1,8 @@ dependencies: pre: - - sudo -u postgres createuser user_testing + - sudo -u postgres createuser user_testing - createdb test test: override: - - eval "$(curl -sL swift.vapor.sh/ci)" + - eval "$(curl -sL https://swift.vapor.sh/ci-3.1)"