name
and
predicate value is the string “Alice”.knows
with the
node representing Alice. The value of this predicate would be the
UID of the node representing Bob. In that case,
knows
is a relationship.strict
mode, you must declare the predicates
(Update Dgraph types ) before you can run a
mutation using those predicates.flexible
mode (which is the default behavior), you can run a mutation
without declaring the predicate in the DQL Schema.strict
mode, the mutation returns an error if the predicates aren’t present
in the Dgraph types schema.
In flexible
mode, Dgraph executes the mutation and adds the predicates
character_name
and has_for_child
to the Dgraph types.
flexible
and the
predicate used isn’t yet declared.
If a predicate type isn’t declared in the schema, then the type is inferred
from the first mutation and added to the schema.
If the mutation is using RDF format with an RDF type, Dgraph
uses this information to infer the predicate type.
If no type can be inferred, the predicate type is set to default
.
Dgraph Type | Go type |
---|---|
default | string |
int | int64 |
float | float |
string | string |
bool | bool |
dateTime | time.Time (RFC3339 format [Optional timezone] eg: 2006-01-02T15:04:05.999999999+10:00 or 2006-01-02T15:04:05.999999999) |
geo | go-geom |
password | string (encrypted) |
dateTime
scalar type only if they
are RFC 3339 compatible which is different from ISO 8601(as defined in the RDF
spec). You should convert your values to RFC 3339 format before sending them
to Dgraph.float32vector
type denotes a vector of floating point numbers, i.e an
ordered array of float32. A node type can contain more than one vector
predicate.
Vectors are normally used to store embeddings obtained from other information
through an ML model. When a float32vector
is indexed,
the DQL similar_to
function can be
used for similarity search.
uid
type denotes a relationship. Internally each node is identified by
it’s UID which is a uint64
.
dgraph.
, it’s reserved as the
namespace for Dgraph’s internal types/predicates. For example, defining
dgraph.Student
as a type is invalid.<>
when executing the schema mutation.
Schema syntax:
@lang
directive and enter values using your language tag.
Schema:
Data Type | Index |
---|---|
string | hash, exact |
int | int |
@upsert
directive in the schema.
When committing transactions involving predicates with the @upsert
directive,
Dgraph checks index keys for conflicts, helping to enforce uniqueness
constraints when running concurrent upserts.
This is how you specify the upsert directive for a predicate.
@noconflict
directive for a predicate.
age
predicate. Given the mutation
int
, as implied by the first triple,"13"
to int
on storage,"14"
can be converted to int
, but stores as string
,"14.5"
can’t be
converted to int
.password
. Passwords can’t be queried directly, only checked for a
match using the checkpwd
function. The passwords are encrypted using
bcrypt
.
For example: to set a password, first set schema, then the password:
~children
inverse relationship.
dgraph.type
predicate value to the type
name.
A node may be given many types, dgraph.type
is an array of strings.
dgraph.type
predicate.delete { <uid> * * . }
mutation.delete all predicates
mutation or the expand all
query, Dgraph checks if the
node has a dgraph.type
predicate. If so, the engine is using the declared type
to find the list of predicates and apply the delete or the expand on all of
them.
When nodes have a type (i.e have a dgraph.type
predicate), then you can use
the function type()
in queries.
delete { <uid> * * . }
only deletes the
predicates declared in the type. You may have added other predicates by running
DQL mutation on this node: the node may still exist after the operation if it
holds predicates not declared in the node type.