Management
In this section we'll learn how to create and manage a DGraph Schema
#
Create a schemaThe 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.
#
PredicatesLet's start adding some predicates to our schema
#
TypesWhen you create a type with dqlx all the predicates will be automatically prefixed with {Type}.
#
Global predicate on a TypeIf you want to reference a predicate that is globally available, you'll need to use the Predicate
method
on a type
#
RelationsDefining 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
#
IndexesYou 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 schemaIn 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