Swifty-PostgreSQL driver, written by Swift 3.0
Mad lab •
Titan •
Swifty PostgreSQL •
FeSpinner
iOS Awesome Starter Kit •
FeSlideFilter
Swifty-PostgreSQL driver, written by Swift 3.0, and using in TitanKit.
The Swifty warpper PostgreSQL’s pointer and C functions, and handle allocate/dellocate memory automatically.
Offer ability to connect many database simultaneously, modeling all PostgreSQL’s enum and constants.
Field model adopt Presentable protocol, so you can get rawString or realData depend on kind of data eaiser, all expensive operations are lazy computed as well.
$ brew install postgresql
github "NghiaTranUIT/Swifty-PostgreSQL" ~> 0.1
let param = ConnectionParam(host: "localhost", port: "5432", options: "",
databaseName: "my-database", user: "nghiatran", password: "mypassword")
let database = Database()
// Connection
let result = database.connectDatabase(withParam: param)
// Check result
guard result.status == .CONNECTION_OK else {return}
let connection = result.connection!
// Disconnection
database.closeConnection()
let connection = result.connection!
let tables: [Table] = connection.publicTables
let query: Query = "SELECT id, first_name, last_name, email FROM users ORDER BY id DESC LIMIT 10"
let result = connection.execute(query: query)
guard result == .PGRES_TUPLES_OK else {return}
print(result.rows) // [Row]
print(result.columns) // [Columns]
print(result.numberOfColumns)
print(result.numberOfRows)
print(result.rowsAffected)
public enum ColumnType: UInt32 {
case boolean = 16
case int64 = 20
case int16 = 21
case int32 = 23
case text = 25
case singleFloat = 700
case doubleFloat = 701
case varchar = 1043
case byte = 17
case char = 18
case json = 114
case date = 1082
case time = 1083
case timestamp = 1114
case unsupport = 0
}
let firstRow = selfrows.first!
// Id
let field_id = firstRow!.field(with: "id")
print(field_id.rawData) // String
print(field_id.isNull) // Check if it's NULL
print(field_id.realData)// Real data, lazy computed, auto mapping data to json or NSDate, ...
print(field_id.colType) // Int32
(Progessing)
Will implement Docker for testing purpose. Currently, The test only passed in my laptop.
Vinh Nghia Tran
http://github.com/NghiaTranUIT
http://www.nghiatran.me
[email protected]
It would be greatly appreciated when you make a pull-quest 🤗
Swifty PostgreSQL is available under the MIT license. See the LICENSE file for more info.