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 #32 from JuanjoArreola/master
Browse files Browse the repository at this point in the history
Add connect with params test, simpler connect string creation
  • Loading branch information
natebird authored Apr 5, 2017
2 parents fda088e + 8ef2aaa commit ff6bd68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
14 changes: 4 additions & 10 deletions Sources/PostgreSQL/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ public final class Connection: ConnInfoInitializable {
let string: String

switch conninfo {
case .raw(let ci):
string = ci
case .raw(let info):
string = info
case .params(let params):
var ci = ""

params.forEach { (key, value) in
ci += "\(key)='\(value)'"
}

string = ci
case .basic(host: let host, port: let port, database: let database, user: let user, password: let password):
string = params.map({ "\($0)='\($1)'" }).joined()
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'"
}

Expand Down
18 changes: 18 additions & 0 deletions Tests/PostgreSQLTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import XCTest
import PostgreSQL

class ConnectionTests: XCTestCase {

func testConnInfoParams() {
do {
let postgreSQL = try PostgreSQL.Database(params: ["host": "127.0.0.1",
"port": "5432",
"dbname": "test",
"user": "postgres",
"password": ""])
try postgreSQL.execute("SELECT version()")
} catch {
XCTFail("Could not connect to database")
}
}
}

0 comments on commit ff6bd68

Please sign in to comment.