Select

The types used in these queries are defined here.

Select a Movie with associated actors and reviews with their authors:

Copy
SELECT Movie {
    id,
    title,
    year,
    description,

    actors: {
        id,
        full_name,
    },

    reviews := .<movie[IS Review] {
        id,
        body,
        rating,
        author: {
            id,
            name,
        }
    },
}
FILTER .id = <uuid>'09c34154-4148-11ea-9c68-5375ca908326'

Select movies with Keanu Reeves:

Copy
SELECT Movie {
    id,
    title,
    year,
    description,
}
FILTER .actors.full_name = 'Keanu Reeves'

Select all actors that share the last name with other actors and include the same-last-name actor list as well:

Copy
SELECT Person {
    id,
    full_name,
    same_last_name := (
        WITH
            P := DETACHED Person
        SELECT P {
            id,
            full_name,
        }
        FILTER
            # same last name
            P.last_name = Person.last_name
            AND
            # not the same person
            P != Person
    ),
}
FILTER EXISTS .same_last_name

The same query can be refactored moving the WITH block to the top-level:

Copy
WITH
    # don't need DETACHED at top-level
    P := Person
SELECT Person {
    id,
    full_name,
    same_last_name := (
        SELECT P {
            id,
            full_name,
        }
        FILTER
            # same last name
            P.last_name = Person.last_name
            AND
            # not the same person
            P != Person
    ),
}
FILTER EXISTS .same_last_name

Select user names and the number of reviews they have:

Copy
SELECT (
    User.name,
    count(User.<author[IS Review])
)

For every user and movie combination, select whether the user has reviewed the movie (beware, in practice this maybe a very large result):

Copy
SELECT (
    User.name,
    Movie.title,
    Movie IN User.<author[IS Review].movie
)

Perform a set intersection of all actors with all directors:

Copy
WITH
    # get the set of actors and set of directors
    Actor := Movie.actors,
    Director := Movie.director,
# set intersection is done via the FILTER clause
SELECT Actor FILTER Actor IN Director;

To order a set of scalars first assign the set to a variable and use the variable in the ORDER BY clause.

Copy
SELECT numbers := {3, 1, 2} ORDER BY numbers;

# alternativly
WITH numbers := {3, 1, 2}
SELECT numbers ORDER BY numbers;
Light
Dark
System