Created
October 12, 2016 10:47
-
-
Save coolmenu/9011f504043faaf84a25a372c104adf9 to your computer and use it in GitHub Desktop.
Swift 3 postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swift Package.swift | |
import PackageDescription | |
let package = Package( | |
name: "demo-pgsql", | |
dependencies: [ | |
.Package(url: "https://github.com/PerfectlySoft/Perfect-PostgreSQL.git", majorVersion: 2, minor: 0) | |
] | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PostgreSQL | |
import Core | |
do { | |
let p = PGConnection() | |
let status = p.connectdb("host=localhost dbname=swift_test") | |
print("status is \(status)\n") | |
let result = p.exec( | |
statement: " select name from test1 ") | |
let num = result.numTuples() | |
print("num is \(num)\n") | |
for x in 0..<num { | |
// let c1 = res.getFieldString(tupleIndex: x, fieldIndex: 0 | |
let name = result.getFieldString(tupleIndex: x, fieldIndex: 0)! | |
print("name is \(name)\n") | |
} | |
defer { | |
result.clear() | |
p.close() // close the connection | |
} | |
} catch { | |
print("\(error)\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment