fetchr
is a command line utility that allows for querying a Core Data store using a JavaScript API.
fetchr
is in a basic usable state. You can create a fetch request, assign an entity to it, assign a predicate, set sort descriptors, set relationship paths for prefetching, and then execute it to get results. Things that still need to be implemented include setting a fetch limit, setting which properties to fetch, and setting properties to group by.
Creates a predicate with the specified format. The method mirrors +[NSPredicate predicateWithFormat:]
See Predicate Format String Syntax for more details.
var sign = isAdult ? '>=' : '<';
Predicate.format('%K %@ 18', 'age', sign);
The constructor mirrors the initializer for NSSortDescriptor
. It takes two arguments, the name of the key to sort by, and whether the sort should be ascending (true
) or descending (false
).
var sortDescriptor = new SortDescriptor('name', true);
The name of the entity as defined in the managed object model.
var request = new FetchRequest();
request.entityName = 'Person';
A Predicate
instance for filtering objects from a Core Data store.
var request = new FetchRequest();
request.entityName = 'Person';
request.predicate = Predicate.format('%K >= 18', 'age');
An array of SortDescriptor
instances to sort the fetch request by.
var request = new FetchRequest();
request.entityName = 'Person';
request.sortDescriptors = [new SortDescriptor('name', true)];
An array of strings that are key paths of relationships to fetch.
var request = new FetchRequest();
request.entityName = 'Person';
request.predicate = Predicate.format('%K.@count >= 3', 'relatives');
request.relationshipKeyPathsForPrefetching = ['relatives'];
Executes a FetchRequest
against a Core Data store, and returns the results, if any.
var request = new FetchRequest();
request.entityName = 'Person';
request.predicate = Predicate.format('%K >= 18', 'age');
var results = fetchr.executeFetchRequest(request);