https://github.com/nghiatranuit/swifty-postgresql
Swifty-PostgreSQL driver, written by Swift 3.0
https://github.com/nghiatranuit/swifty-postgresql
macos opensource postgresql swift3
Last synced: 3 months ago
JSON representation
Swifty-PostgreSQL driver, written by Swift 3.0
- Host: GitHub
- URL: https://github.com/nghiatranuit/swifty-postgresql
- Owner: NghiaTranUIT
- License: mit
- Created: 2017-02-27T14:48:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-29T05:40:17.000Z (about 9 years ago)
- Last Synced: 2025-10-04T19:37:20.603Z (9 months ago)
- Topics: macos, opensource, postgresql, swift3
- Language: Swift
- Size: 1.67 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mad lab •
Titan •
Swifty PostgreSQL •
FeSpinner
iOS Awesome Starter Kit •
FeSlideFilter
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.

[](https://github.com/Carthage/Carthage)


Roadmap
------------
- [x] Sketch
- [x] Base Foundation (50%)
- [ ] Fully Common PostgreSQL
- [ ] Prefix searching - implement by Prefix Tree
- [ ] Smart Query
- [ ] Write Test
Installation
------------
- OSX
```bash
$ brew install postgresql
```
- Carthage
```swift
github "NghiaTranUIT/Swifty-PostgreSQL" ~> 0.1
```
Documentation
------------
- Connection Database
```swift
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
```swift
let connection = result.connection!
let tables: [Table] = connection.publicTables
```
- Query
```swift
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
```swift
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
```swift
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
vinhnghiatran@gmail.com
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.