Skip to content

Queries Definition

An EdgeQL query that can be parsed using edgeql-queries has some limitations:

  1. Query must be named.
  2. The query's name must not contain characters that cannot be used in Python identifiers (except for the - character, since it will be converted to _).
  3. They can have special symbols after their names that will change how this queries will be executed:
    • *: query will be executed as script with using .execute method from driver.
    • +: query will return a single object or None and executed with .query_single method from driver.
    • !: query will always return a single object and executed with .query_required_single method from driver.
    • empty: common query that will return a set of objects and will be executed with .query method from driver.

Names

The query name must be a valid Python identifier, but it can contain a - character, which will be converted to _. An example of valid query names:

  • Example 1:

    # name: get-persons-by-age
    SELECT Person {
        first_name
    }
    FILTER .age = <int64>$age
    

  • Example 2:

    # name: get-person-by-full-name!
    SELECT Person {
        first_name,
        last_name,
        age
    }
    FILTER .first_name = <str>$first_name AND .last_name = <str>$last_name
    

  • Example 3:

    # name: create-test-users*
    FOR x IN {
        (name := 'Alice', theme := 'fire'),
        (name := 'Bob', theme := 'rain'),
        (name := 'Carol', theme := 'clouds'),
        (name := 'Dave', theme := 'forest')
    }
    UNION (
        INSERT
            User {
                name := x.name,
                theme := x.theme,
            }
    );