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

An optional JSON-LD Context for the query. Use of a query-specific Context is rarely required, as the context is typically the local application, whose needs are specified by the local clone configuration.

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 filters for subject identities, properties and values, including inline filters.

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method
  • Protected method

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