Management
In this section we'll learn how to create and manage a DGraph Schema
Create a schema#
The schema builder allows you to define Types and Predicates in an easier way.
It will handle all the syntax complexities to define direct and reverse relations.
Predicates#
Let's start adding some predicates to our schema
Types#
When you create a type with dqlx all the predicates will be automatically prefixed with {Type}.
Global predicate on a Type#
If you want to reference a predicate that is globally available, you'll need to use the Predicate method
on a type
Relations#
Defining relations with the Schema Builder have never been easier.
Imagine the scenario of User have many Posts and Posts have many Comments, here is how the schema might look like
Indexes#
You can set specific index by chaining the Index{Type} method on the predicate
Available indexes#
- exact
- hash
- term
- fulltext
- trigram
- year
- month
- day
- hour
Altering the schema#
In order to alter the schema you must call the Alter method.
This method will not drop any fields by default. You can specify WithDropAll to force recreating
the schema from scratch
By default, indexing is set to run In the background if you prefer it on the main process you can disable it
with the WithRunInBackground(false) method