Officially out now: The TypeDB 3.0 Roadmap >>

Patterns overview

What is a pattern?

A pattern is a set of declarative constraints. TypeQL uses patterns in its queries and clauses.

  • In data queries, patterns are used to specify constraints on concepts to be retrieved or processed.

  • In schema queries, we use schema-specific patterns without any variables to define or undefine type definitions.

Patterns are built from statements using pattern operations.

Pattern operations

Combine statements in a pattern with conjunction.

Create alternative branches in a pattern with disjunction.

Exclude results with a negation pattern.

Pattern usage

Pattern-based matching of concepts in a database.

Patterns are used in queries in various ways.

Composing patterns

You can combine two patterns by joining their statements together in a new pattern. All semicolon-separated statements are combined with an implicit conjunction. That makes the order of statements irrelevant. Hence, it’s easy to change the results by adding new constraints to the pattern.

For example, in the following pattern the $u variable is specified to be a user with a full-name attribute, which value is equal to Kevin Morrison, the $f variable is a file with a path equal to zlckt.ts. Finally, there are two relations that specify a connection between the $u and the $f.

Composable pattern example
$u isa user, has full-name "Kevin Morrison";
$f isa file, has path "zlckt.ts";
$acc ($f, $act) isa access;
$per ($u, $acc) isa permission;