michaellperry / jinaga

Universal web back-end, offering an application-agnostic API, real-time collaboration, and conflict resolution.
http://jinaga.com
MIT License
35 stars 3 forks source link

Existential query conditions #20

Closed michaellperry closed 8 years ago

michaellperry commented 9 years ago

Add steps to a query to recursively test for the existence or absence of facts satisfying another query.

Create a "where" method in the Jinaga class that operates on a query specification. For example:

function uncompletedTasksInList(l) {
  return j.where({
    type: "Task",
    list: l
  }, [taskIsNotCompleted]);
}

This will append an existential condition to the query. The condition will only be satisfied if the subquery returns at least one result.

Create a "not" method in the Jinaga class that operates on a query specification. For example:

function taskIsNotCompleted(t) {
  return j.not({
    type: "TaskCompleted",
    task: t,
    completed: true
  });
}

This template function can only be used as a condition. When used, it negates the existential condition so that it only is satisfied when the subquery returns no results.

The "not" method can take an array of functions. In this usage, it is being applied at the point of usage:

function uncompletedTasksInList(l) {
  return j.where({
    type: "Task",
    list: l
  }, j.not([taskIsCompleted]));
}