Overview
In Ultipa Graph, a schema represents a node or edge type. When modeling a real-world scenario into a graph, node schemas are generally used to depict different types of entities (such as Account, Company, Card), and edge schemas represent types of relations between entities (such as Follow, Hold, TransferTo).
The definition of schemas is a prerequisite for creating any node or edge data. Each node or edge is designated to one and only one schema. A graphset usually contains multiple node schemas and edge schemas.
A node schema and an edge schema both named default are automatically created during the creation of a graphset. They can be freely utilized. However, the two default schemas are not allowed to be dropped.
The symbol @
is used in UQL to denote a schema, and the expression @<schema>
specifies a certain schema, such as @user
.
Show Schema
// Show all schemas in the graphset
show().schema()
// Show all node schemas in the graphset
show().node_schema()
// Show all edge schemas in the graphset
show().edge_schema()
// Show the node schema named user in the graphset
show().node_schema(@user)
// Show the edge schema named likes in the graphset
show().edge_schema(@likes)
Example result:
nodeSchema
name |
totalNodes |
description |
properties |
---|---|---|---|
default | 0 | default schema | [] |
movie | 92 | [{name: "name", type: "string", description: "", lte: "true", extra: "{}"}, {name: "genre", type: "string", description: "", lte: "false", extra: "{}"}, {name: "rating", type: "double", description: "", lte: "false", extra: "{}"}] |
|
country | 78 | [{name: "name", type: "string", description: "", lte: "false", extra: "{}"}] |
edgeSchema
name |
totalEdges |
description |
properties |
---|---|---|---|
default | 0 | default schema | [] |
filmedIn | 192 | [{name: "time", type: "timestamp", description: "", lte: "false", extra: "{}"}] |
The properties
only contains custom propeties; system properties are not included in the results.
Create Schema
// Create a node schema named account in the current graphset, and provide description
create().node_schema("movie", "The movies added by the admin")
// Create an edge schema named filmedIn in the current graphset
create().edge_schema("filmedIn")
// Create multiple node/edge schemas at one time
create()
.node_schema("movie", "The movies added by the admin")
.node_schema("country")
.edge_schema("filmedIn")
Naming Conventions
Here are the naming conventions for schemas:
- Contains 2 to 64 characters.
- Not allowed to start with a tilde symbol
~
. - Not allowed to contain backslash symbol
\
. - Not allowed to use any reserved words
You cannot have two node schemas with the same name, or two edge schemas with the same name. However, you may have a node schema and an edge schema share the same name.
When the schema name contains characters other than letters (A-Z, a-z), numbers (0-9) and underscores (_
), the schema name must be wrapped with two backslashes (\
) when being used. For example,
find().nodes({@`movie*`}) as n
return n
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>)