Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meniny/sqlable
Swift ORM framework.
https://github.com/meniny/sqlable
databse orm sqlite
Last synced: about 1 month ago
JSON representation
Swift ORM framework.
- Host: GitHub
- URL: https://github.com/meniny/sqlable
- Owner: Meniny
- License: mit
- Created: 2018-03-16T07:32:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-16T04:14:19.000Z (over 5 years ago)
- Last Synced: 2024-09-18T06:11:40.213Z (about 2 months ago)
- Topics: databse, orm, sqlite
- Language: Swift
- Size: 33.2 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## 🏵 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](https://cocoapods.org):
```ruby
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:
```swift
struct User {
var name: String
}
```then, extend the model to confirm `Sqlable` protocol:
```swift
extension User: Sqlable {}
```and, we need to create the database columns:
```swift
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:
```swift
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:
```swift
try database.create(table: User.self)
```do your work, let's `insert` for example:
```swift
try user.insert(into: database)
```
query:```swift
try User.query(in: database)
```