Your first NexQL query
NexQL is a semantic query language developed for FactEngine. It expresses a question using the object types and relationship readings in a model, then supports deterministic translation to SQL or Cypher.
This walkthrough uses a cinema model to build a query step by step. To run the examples, use FactEngine with the matching model and a connected database.
1. Start with an object type
Section titled “1. Start with an object type”Ask “What films are there?”
WHICH FilmFilm is an object type in the cinema model. WHICH selects it for the results. You do not need a RETURN clause.
2. Add a relationship and a value
Section titled “2. Add a relationship and a value”Ask “What films are playing at the Rialto?”
WHICH Film is showing at (Cinema:'Rialto')Read it in three parts:
| Part | Meaning |
|---|---|
WHICH Film | Select films. |
is showing at | Follow a relationship reading defined by the model. |
(Cinema:'Rialto') | Constrain Cinema to the specified value. |
Object names and relationship readings come from your model. NexQL is close to natural language, but arbitrary English is not automatically a valid query.
3. Refine the question
Section titled “3. Refine the question”Ask “What films are playing at the Rialto on 1 April 2023 at 10am?”
WHICH Film is showing at (Cinema:'Rialto')on (DateTime:'2023-04-01 10:00')The date and time narrow the matching showings. Line breaks here make the query easier to read.
4. Choose more results
Section titled “4. Choose more results”WHICH Film is showing at WHICH Cinema at WHICH DateTimeEach WHICH selects another object type to return. For each selected object type, NexQL returns the fields of the first-found uniqueness constraint. If none is found, it returns the primary key.
Try it yourself
Section titled “Try it yourself”Using the cinema vocabulary, write a query for films showing at the Great Western Cinema.
See the query
WHICH Film is showing at (Cinema:'Great Western Cinema')Continue with choosing results or the agent workflow.