Swifty PostgreSQL

Swifty-PostgreSQL driver, written by Swift 3.0

2
0
Swift

Mad labTitanSwifty PostgreSQLFeSpinner
  iOS Awesome Starter KitFeSlideFilter

Swifty PostgreSQL

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.


Carthage compatible
License
Platform

Roadmap

  • [x] Sketch
  • [x] Base Foundation (50%)
  • [ ] Fully Common PostgreSQL
  • [ ] Prefix searching - implement by Prefix Tree
  • [ ] Smart Query
  • [ ] Write Test

Installation

  • OSX
$ brew install postgresql
  • Carthage
github "NghiaTranUIT/Swifty-PostgreSQL" ~> 0.1

Documentation

  • Connection Database
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()
  • Public tables
let connection = result.connection!
let tables: [Table] = connection.publicTables
  • Query
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)
  • Data type
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
}
  • Access data
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

Run Test

(Progessing)
Will implement Docker for testing purpose. Currently, The test only passed in my laptop.

Contact

Vinh Nghia Tran

http://github.com/NghiaTranUIT
http://www.nghiatran.me
[email protected]

Contributor

It would be greatly appreciated when you make a pull-quest 🤗

License

Swifty PostgreSQL is available under the MIT license. See the LICENSE file for more info.