Schema represents a certain structural definition of data, restores the real world to graph more intuitively and completely, so that the graph data can be managed clearly and conveniently. In Ultipa Graph system, schema describes a type of entity (node) in real world, such as Natural Person, Bank Card, Account; or a kind of behavioral relation (edge), such as Follow, Transaction, Own.
A default node schema and a default edge schema (both non-deletable) are created automatically along with a GraphSet. Each GraphSet may contain multiple node schemas and edge schemas.
Schema is indicated with the symbol @
in UQL:
- the form of
@<value>
is a filter condition, e.g. @account is interpreted as the nodes/edges of schema account - the form of
@
alone is a call, e.g. @ or <alias>.@, which calls the schema of the metadata
Naming Conventions
Schemas are named by developers. In a graphset, a same name can be shared between a node schema and an edge schema, but not between node schemas, or edge schemas.
- 2 ~ 64 characters
- Not allow to start with wave line '~'
- Not allow to contain back quote '`'
- Not allow to use Reserved Words listed in Basic Concepts
Show Schema
Returned table name: _nodeSchema
, _edgeSchema
Returned table header: name
| description
| properties
| totalNodes
or totalEdges
(the name, description, list of properties, number of nodes or edges of the schema)
Syntax:
// To show all schemas in the current graphset (node schemas and edges schemas in separated tables)
show().schema()
// To show all node schemas in the current graphset
show().node_schema()
// To show all edge schemas in the current graphset
show().edge_schema()
// To show a certain node schema in the current graphset
show().node_schema(@<schema>)
// To show a certain edge schema in the current graphset
show().edge_schema(@<schema>)
Create Schema
Syntax:
// To create a node schema in the current graphset
create().node_schema("<name>", "<desc?>")
// To create an edge schema in the current graphset
create().edge_schema("<name>", "<desc?>")
// To create multiple node/edge schemas by using the two methods above
create()
.node_schema("<name>", "<desc?>")
.edge_schema("<name>", "<desc?>")
...
Example: Using one UQL to create node schemas for entities "Bank Card" and "Bank Account"
create().node_schema("card", "Bank Card").node_schema("account", "Bank Account")
Example: Using one UQL to create edge schemas for relations "Own" and "Transaction"
create().edge_schema("own").edge_schema("transaction")
Example: Using one UQL to create node schema for entity "Bank Card" and edge schema for relation "Own"
create().node_schema("card", "Bank Card").edge_schema("own")
Alter Schema (Name, Description)
Syntax:
// To modify the name, description of a certain node schema in the current graphset
alter().node_schema(@<schema>)
.set({name: "<new_name?>", description: "<new_desc?>"})
// To modify the name, description of a certain edge schema in the current graphset
alter().edge_schema(@<schema>)
.set({name: "<new_name?>", description: "<new_desc?>"})
Drop Schema
Except for the default node schema and edge schema @default
, which are not allowed to be deleted, all the other schemas in the current GraphSet can be deleted.
Syntax:
// To delete a certain node schema from the current graphset
drop().node_schema(@<schema>)
// To delete a certain edge schema from the current graphset
drop().edge_schema(@<schema>)
// To delete multiple node/edge schemas by using the two methods above
drop()
.node_schema(@<schema>)
.edge_schema(@<schema>)