List Schema
Get detail of all schema with property info
// show node schemas
nodeSchemas, _ := client.ListSchema(ultipa.DBType_DBNODE, nil)
log.Println(nodeSchemas)
// show edge schemas
edgeSchemas, _ := client.ListSchema(ultipa.DBType_DBEDGE, nil)
log.Println(edgeSchemas)
Get Schema
Get detail of one schema with property info
//get node schema
nodeSchema, _ := client.GetSchema("my_node_schema", ultipa.DBType_DBNODE, nil)
log.Println(nodeSchema)
//get edge schema
edgeSchema, _ := client.GetSchema("my_edge_schema", ultipa.DBType_DBEDGE, nil)
log.Println(edgeSchema)
Create Schema
// create schema without properties
newSchema := &structs.Schema{
Name: "new_node_schema",
DBType: ultipa.DBType_DBNODE,
}
resp, _ := client.CreateSchema(newSchema, false, nil) // the 2nd parameter 'false' means 'do not create properties'
log.Println(resp.Status.Code)
// create schema with properties
newSchemaWithProperties := &structs.Schema{
Name: "my_node_schema_prop",
Desc: "A Schema with 2 properties",
Properties: []*structs.Property{
{
Name: "username",
Type: ultipa.PropertyType_STRING,
},
{
Name: "password",
Type: ultipa.PropertyType_STRING,
},
},
}
resp2, _ := client.CreateSchema(newSchemaWithProperties, true, nil) // the 2nd parameter 'true' means 'create properties'
log.Println(resp2)
Create Schema If Not Exist
Same function as 'Create Schema', return false if the schema already exists
schema := structs.Schema{
Name: "new_schema",
}
resp, _ := client.CreateSchemaIfNotExist(&schema, nil)
log.Println(resp)