Kuery

A type-safe Core Data query API using Swift 4's Smart KeyPaths

  • Owner: kishikawakatsumi/Kuery
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Kuery

Kuery, a type-safe Core Data query API using Swift 4's Smart KeyPaths. Inspired and borrowed a lot of things from QueryKit and RealmEx.

Requirements

Kuery is written in Swift 4.

Installation

CocoaPods

Kuery is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Kuery'

Carthage

For Carthage, add the following to your Cartfile:

github "kishikawakatsumi/Kuery"

Description

Kuery provides type safety, code completion and avoidance of typos against NSPredicate queries.

Before

NSPredicate(format: "name == %@", "Katsumi")
NSPredicate(format: "age > %@", 20)

After

Query(Person.self).filter(\Person.name == "Katsumi")
Query(Person.self).filter(\Person.age > 20)

The following code should be a compile error.

Query(Person.self).filter(\Person.name > 20) // Compile error
Query(Person.self).filter(\Dog.name == "John") // Compile error

Usage

context.perform {
    let results = try Query(Person.self)
        .filter(\Person.name == "Katsumi")
        .execute()
}
context.perform {
    let results = try Query(Person.self)
        .filter(\Person.age == 36)
        .execute()
}
context.perform {
    let results = try Query(Person.self)
        .filter(\Person.age > 20)
        .execute()
}
context.perform {
    let results = try Query(Person.self)
        .filter(\Person.name == "Katsumi")
        .filter(\Person.age == 36)
        .execute()
}
context.perform {
    let results = try Query(Dog.self)
        .filter(\Dog.owner == person)
        .execute()
}

Feature request for Swift Standard Library

It requires a string representation of KeyPath to construct NSPredicate from KeyPath. However, the API is not officially visible currently. The feature request is tracked at SR-5220.

[SR-5220] Expose API to retrieve string representation of KeyPath - Swift

Main metrics

Overview
Name With Ownerkishikawakatsumi/Kuery
Primary LanguageSwift
Program languageSwift (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2017-06-14 09:55:58
Pushed At2018-10-07 06:40:25
Last Commit At2018-10-07 15:40:24
Release Count2
Last Release Namev0.3.0 (Posted on )
First Release Namev0.2.0 (Posted on )
用户参与
Stargazers Count615
Watchers Count17
Fork Count13
Commits Count25
Has Issues Enabled
Issues Count1
Issue Open Count1
Pull Requests Count5
Pull Requests Open Count1
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private