Maps

Cypher® maps can be constructed with Cypher Builder by using the Cypher.Map class, and passing an object with the fields and corresponding Cypher expressions:

const map = new Cypher.Map({
    foo: new Cypher.Literal("barr"),
    var: new Cypher.Variable(),
    param: new Cypher.Param("test"),
});

This map can be used wherever an expression is accepted to translate to the literal maps in Cypher:

{ foo: "barr", var: var0, param: $param0 }

The Cypher.Map class provides the following methods:

  • size: returns the current size of the map.

  • set: adds more fields to the Map. This method supports either two parameters (key, value) or an object with the fields to be added.

Map projection

Map projections can be created in Cypher Builder in a similar fashion to maps, by using the class Cypher.MapProjection with the target variable and the projection fields:

const mapProjection = new Cypher.MapProjection(new Cypher.Variable(), ["name", "title"]);

This map can be used wherever an expression is accepted to translate to the literal map in Cypher:

var0 { .name, .title }

Map projection with .*

The syntax {.*} allows for the creation of a map projection containing all elements in the projection target. This can be achieved by passing \* in the projection fields:

const mapProjection = new Cypher.MapProjection(new Cypher.Variable(), "*");

This map can be used wherever an expression is accepted to translate to the literal map in Cypher:

var0 { .* }

Using a "*" string within the projection fields array will have a different effect, as it will be interpreted as a field named * and be escaped accordingly:

const mapProjection = new Cypher.MapProjection(new Cypher.Variable(), ["*"]);
var0 { .`*` }

Setting extra fields to a map projection

A map projection may also contain extra fields that do not exist in the target variable, but which are set in the projection. This can be achieved by passing a third parameter to Cypher.MapProjection:

const mapProjection = new Cypher.MapProjection(new Cypher.Variable(), ["name", "title"], {
    anotherField: new Cypher.Literal("Another Field")
});
var0 { .name, .title, anotherField: "Another Field" }