Delegating 1.0.0

Delegating 1.0.0

Maintained by Meniny.




Version Author Build Passing Swift
Platforms MIT
Cocoapods Carthage SPM

🏵 Introduction

Sqlable is a tiny library for ORM written in Swift.

📋 Requirements

  • iOS 8.0+
  • macOS 10.10+
  • tvOS 9.1+
  • watchOS 2.2+
  • Xcode 9.0+ with Swift 4.0+

📲 Installation

Sqlable is available on CocoaPods:

use_frameworks!
pod 'Sqlable'

❤️ Contribution

You are welcome to fork and submit pull requests.

🔖 License

Sqlable is open-sourced software, licensed under the MIT license.

💫 Usage

First, create a model:

struct User {
  var name: String
}

then, extend the model to confirm Sqlable protocol:

extension User: Sqlable {

}

and, we need to create the database columns:

extension User: Sqlable {
    // create your columns:

    static let id = SQLColumn("id", .integer, PrimaryKey(autoincrement: true))
    static let name = SQLColumn("name", .text)
    static var tableLayout: [SQLColumn] = [id, name]

    // implement there two functions:

    func valueForColumn(_ column: SQLColumn) -> SQLValue? {
        switch column {
        case User.name:
            return self.name
        default:
            return nil
        }
    }

    init(row: SQLReadRow) throws {
        name = try row.get(User.name)
    }
}

now, get your database:

let doc = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let database = try SQLiteDatabase.init(filepath: doc.appendingPathComponent("User.db").path)

create table if not exists:

try database.createTable(User.self)

do your work, let's insert for example:

try user.insert(into: database)

query:

try User.query(in: database)