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.
The symbol
@
in a UQL always represents the operations related with schema. The@<schema>
that appears in this article filters a specific schema in a graph model, which is different than the@<schema>
that appears in an Ultipa filter which filters the metadata of a specific schema. Please read Filter | Operator - Conditional Operator - Schema Checker for more information.
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
- (When containing characters other than letters, numbers and underscore, the schema name should be wrapped with backquote '`' when being used in the UQL)
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 edge 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: Create schemas card and account for node and own for edge in one UQL
create()
.node_schema("card", "Bank_Card")
.node_schema("account", "Bank_Account")
.edge_schema("own")
Example: Create node schema card, given that this schema already exists
create().node_schema("card")
Schema already exists!
Analysis: This query will give no return if using prefix TRY try create().node_schema("card")
.
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. Deleting a schema will also delete all its metedata.
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>)