Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/naoty/anyquery
Soft-typed query for anything
https://github.com/naoty/anyquery
Last synced: 3 months ago
JSON representation
Soft-typed query for anything
- Host: GitHub
- URL: https://github.com/naoty/anyquery
- Owner: naoty
- License: mit
- Created: 2016-02-23T15:04:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-11T05:25:45.000Z (almost 8 years ago)
- Last Synced: 2024-10-07T18:17:50.316Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 34.2 KB
- Stars: 17
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AnyQuery
[![Build Status](https://travis-ci.org/naoty/AnyQuery.svg?branch=master)](https://travis-ci.org/naoty/AnyQuery)
## Usage
### AnyQuery
`AnyQuery` is a representation of queries for anything. A `AnyQuery` can be transformed into a `NSPredicate` and a `Dictionary`.
```swift
let query = AnyQuery.equal(key: "id", value: 1)
query.predicate //=> NSPredicate(format: "id == 1")
query.dictionary //=> ["id": 1]
````AnyQuery` has below types. Each types can be transformed into proper objects
* `equal(key:value:)`
* `notEqual(key:value:)`
* `greaterThan(key:value:)`
* `greaterThanOrEqual(key:value:)`
* `lessThan(key:value:)`
* `lessThanOrEqual(key:value:)`
* `in(key:values:)`
* `between(key:lhs:rhs:)``AnyQuery` also can be combined with another one with `&&` or `||` operator.
```swift
let query: AnyQuery = .equal(key: "id", value: 1) && .equal(key: "name", value: "naoty")
query.predicate //=> NSPredicate(format: "id == 1 AND name == naoty")
query.dictionary //=> ["id": 1, "name": "naoty"]
```### AnySort
`AnySort` is a representation of sorts for anything. A `AnySort` can be transformed into `[NSSortDescriptor]` and a dictionary.
```swift
let sort = AnySort.ascending(key: "id")
sort.sortDescriptors //=> [NSSortDescriptor(key: "id", ascending: true)]
sort.dictionary //=> ["sort": ["id"]]
```Like `AnyQuery`, `AnySort` also can be combined with another one with `>` operator.
```swift
let sort: AnySort = .ascending(key: "name") > .descending(key: "age")
sort.sortDescriptors //=> [NSSortDescriptor(key: "name", ascending: true), NSSortDescriptor(key: "age", ascending: false)]
sort.dictionary //=> ["sort": ["name", "-age"]]
```## Installation
### Carthage
```rb
github "naoty/AnyQuery"
```### CocoaPods
```rb
pod "AnyQuery"
```## Author
[naoty](https://github.com/naoty)