Latest1.0.0
Homepagehttps://github.com/Meniny/Sqlable
LicenseMIT
Platformsios 8.0, tvos 9.1, osx 10.10, watchos 2.2
Authors




VersionAuthorBuild PassingSwift
PlatformsMIT
CocoapodsCarthageSPM

🏵 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.create(table: User.self)

do your work, let’s insert for example:

try user.insert(into: database)

query:

try User.query(in: database)

Latest podspec

{
    "name": "Sqlable",
    "version": "1.0.0",
    "summary": "Swift ORM framework.",
    "description": "Sqlable is a Swift ORM framework.",
    "homepage": "https://github.com/Meniny/Sqlable",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Elias Abel": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Meniny/Sqlable.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://meniny.cn/",
    "module_name": "Sqlable",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.1",
        "osx": "10.10",
        "watchos": "2.2"
    },
    "swift_version": "4.0",
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "Sqlable/**/*.{swift}",
    "libraries": "sqlite3",
    "xcconfig": {
        "OTHER_SWIFT_FLAGS": "$(inherited) -DSQLITE_SWIFT_STANDALONE"
    }
}

Pin It on Pinterest

Share This