GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - QueryKit/querykit-cli: QueryKit command line tool to produce type-safe accessors

This repository was archived by the owner on Mar 1, 2020. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

27 Commits
27 Commits

Folders and files

NameName
Last commit message
Last commit date
Sources/querykit-cli
Sources/querykit-cli
 
 
share/querykit
share/querykit
 
 
.gitignore
.gitignore
 
 
.swift-version
.swift-version
 
 
.travis.yml
.travis.yml
 
 
Makefile
Makefile
 
 
Package.resolved
Package.resolved
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 

Repository files navigation

QueryKit Logo

DEPRECATED: QueryKit CLI is no longer needed, QueryKit 0.14.0 works with KeyPath, see QueryKit/QueryKit#55.

QueryKit CLI

A command line tool to generate extensions for your Core Data models including QueryKit attributes for type-safe Core Data querying. Allowing you to use Xcode generated managed object classes with QueryKit.

Installation

Installation can be done via Homebrew as follows:

$ brew install querykit/formulae/querykit-cli

Alternatively, you can build it yourself with the Swift package manager.

$ git clone https://github.com/QueryKit/querykit-cli
$ cd querykit-cli
$ make install

Usage

You can run QueryKit against your model providing the directory to save the extensions.

$ querykit <modelfile> <directory-to-output>

Example

We've provided an example application using QueryKit's CLI tool.

$ querykit Todo/Model.xcdatamodeld Todo/Model
-> Generated 'Task' 'Todo/Model/Task+QueryKit.swift'
-> Generated 'User' 'Todo/Model/User+QueryKit.swift'

QueryKit CLI will generate a QueryKit extension for each of your managed object subclasses that you can add to Xcode, in this case Task and User.

These extensions provide you with properties on your model for type-safe filtering and ordering.

Task+QueryKit.swift

import QueryKit

extension Task {
  static var createdAt:Attribute<NSDate> { return Attribute("createdAt") }
  static var creator:Attribute<User> { return Attribute("creator") }
  static var name:Attribute<String> { return Attribute("name") }
  static var complete:Attribute<Bool> { return Attribute("complete") }
}

extension Attribute where AttributeType: Task {
  var creator:Attribute<User> { return attribute(AttributeType.creator) }
  var createdAt:Attribute<NSDate> { return attribute(AttributeType.createdAt) }
  var name:Attribute<String> { return attribute(AttributeType.name) }
  var complete:Attribute<Bool> { return attribute(AttributeType.complete) }
}

User+QueryKit.swift

import QueryKit

extension User {
  static var name:Attribute<String> { return Attribute("name") }
}

extension Attribute where AttributeType: User {
  var name:Attribute<String> { return attribute(AttributeType.name) }
}

We can use these properties in conjunction with QueryKit to build type-safe queries. For example, here we are querying for all the Tasks which are created by a user with the name Kyle which are completed, ordered by their created date.

Task.queryset(context)
  .filter { $0.user.name == "Kyle" }
  .exclude { $0.completed == true }
  .orderBy { $0.createdAt.ascending }

Customising

You may pass a custom template to the QueryKit tool, please see the standard template for more information on the syntax.

$ querykit Todo/Model.xcdatamodeld Todo/Model --template share/querykit/template.swift

About

QueryKit command line tool to produce type-safe accessors

Resources

Readme
Activity
Custom properties

Stars

65 stars

Watchers

1 watching

Forks

10 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.