https://github.com/badchoice/daikiriswift
Wrapper arround CoreData
https://github.com/badchoice/daikiriswift
Last synced: about 1 year ago
JSON representation
Wrapper arround CoreData
- Host: GitHub
- URL: https://github.com/badchoice/daikiriswift
- Owner: BadChoice
- License: mit
- Created: 2020-01-14T14:21:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-17T17:56:02.000Z (over 1 year ago)
- Last Synced: 2025-03-16T20:01:45.433Z (over 1 year ago)
- Language: Swift
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# DaikiriSwift
The new coredata wrapper to easily work with it, from json to coredata and back!
### Defining a model
You simply need o inther from `Daikiri` and conform to `DaikiriId` and `Codable` protocols.
```
class Hero : Daikiri, DaikiriId, Codable {
let id:Int
public init(id:Int){
self.id = id
}
}
```
Once you have this you can simply create an instance to the core data with
```
Hero(id:1).create()
```
And you can retrieve it with
```
let hero = Hero.find(1)
```
### Queries
You can easily fetch elements from the database with the object `query`
```
let heroes = Hero.query.whereKey("id", 1).get()
```
or you can also use another operator
```
let heroes = Hero.query.whereKey("id", ">", 4).get()
```
Other functions you can use
```
Hero.query.count()
Hero.query.max("id")
Hero.query.min("id")
Hero.query.skip(10)
Hero.query.take(4")
Hero.query.orderBy("id", ascendig: true)
```
You can combine them
```
let heroes = Hero.query
.whereKey("id", ">", 4)
.orderBy("id", ascending:false)
.skip(10)
.take(2)
.get()
```
### Relationships
```
belongsTo
hasMany
belongsToMany
morphTo
morphOne
morphMany
morphToMany
morphedByMany
```