Options
All
  • Public
  • Public/Protected
  • All
Menu

A query pattern that returns a specified JSON structure with variable substitutions. This is useful to query all information needed for some domain entity, including nested information.

The @construct member defines a JSON template, with placeholder variables for the data to be filled by the query. The returned subjects will have the given template structure, with a few exceptions:

  • If there is no value for a subject property, the property will be omitted.
  • If there are multiple values for a subject property, the property will be an array.
  • @list contents are always returned as an array, even if the query uses an object (see examples).
  • Returned subjects always have an @id. If no @id is given in the template (as a fixed IRI or variable), a generated placeholder will be used (starting with _:).

A @construct can be used by itself as a straightforward pattern match to data already in the domain, or with a @where clause to create new data structures.

Examples:


Pattern match an identified subject with nested content

{
  "@construct": {
    "@id": "fred",
    "children": {
      "@id": "?child", "name": "?childName"
    }
  }
}

might return:

{
  "@id": "fred",
  "children": [
    { "@id": "pebbles", "name": "Pebbles" },
    { "@id": "stony", "name": "Stony" }
  ]
}

Pattern match list content

{
  "@construct": {
    "@id": "fred",
    "appearsIn": {
      "@list": { "1": "?" }
    }
  }
}

might return (note sparse array containing only the requested index):

{
  "@id": "fred",
  "appearsIn": {
    "@list": [
      null,
      { "@id": "hotLipsHannigan" }
    ]
  }
}

Construct new information based on existing information

{
  "@construct": {
    "@id": "?parent",
    "grandchildren": {
      "@id": "?grandchild"
    }
  },
  "@where": {
    "@id": "?parent",
    "children": {
      "children": {
        "@id": "?grandchild"
      }
    }
  }
}

might return:

{
  "@id": "fred",
  "grandchildren": [
    { "@id": "roxy" },
    { "@id": "chip" }
  ]
}
see

json-rql construct

Hierarchy

Index

Properties

@construct

@construct: Subject | Subject[]

Specifies a Subject for the requested data, using variables to place-hold variables matched by the @where clause.

Optional @context

@context: Context

A JSON-LD Context for the query. In an API, this will frequently be implicit. For example, using json-rql as the body of a POST to http://example.com/my-api/v1/person/query might have the implicit context of a Person (possibly found at http://example.com/my-api/v1/person).

see

examples

Optional @where

@where: Subject | Subject[] | Group

The data pattern to match, as a set of subjects or a group. Variables are used as placeholders to capture matching properties and values in the domain.

Examples:


Match a subject by its @id

{
  ...
  "@where": { "@id": "fred" }
}

Match a subject where any property has a given value

{
  ...
  "@where": {
    "@id": "?id",
    "?prop": "Bedrock"
  }
}

Match a subject with a given property, having any value

{
  ...
  "@where": {
    "@id": "?id",
    "name": "?name"
  }
}

The Javascript engine supports exact-matches for subject identities, properties and values. Inline filters will be available in future.

Legend

  • Property
  • Method
  • Constructor

Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.7.0 Source code licensed MIT. Privacy policy