ListSchema()
方法及相关类:
ListSchema(DBType ultipa.DBType, config *configuration.RequestConfig) ([]*structs.Schema, error)
示例:获取test图集的点、边schema列表
func TestMisc(t *testing.T) {
// 创建名为conn的连接并使用default图集,此部分代码省略
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
nodeSchemas, _ := conn.ListSchema(ultipa.DBType_DBNODE, requestConfig)
printers.PrintSchema(nodeSchemas)
edgeSchemas, _ := conn.ListSchema(ultipa.DBType_DBEDGE, requestConfig)
printers.PrintSchema(edgeSchemas)
}
GetSchema()
方法及相关类:
GetSchema(schemaName string,
DBType ultipa.DBType,
config *configuration.RequestConfig
) (*structs.Schema, error)
示例:获取test图集的点schema account和边schema transfer的信息
func TestMisc(t *testing.T) {
// 创建名为conn的连接并使用default图集,此部分代码省略
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
nodeSchema, _ := conn.GetSchema("client", ultipa.DBType_DBNODE, requestConfig)
fmt.Println(*nodeSchema)
edgeSchema, _ := conn.GetSchema("transfer", ultipa.DBType_DBEDGE, requestConfig)
fmt.Println(*edgeSchema)
}
GetNodeSchema() | GetEdgeSchema()
方法及相关类:
GetNodeSchema(schemaName string, config *configuration.RequestConfig) (*structs.Schema, error)
GetEdgeSchema(schemaName string, config *configuration.RequestConfig) (*structs.Schema, error)
示例:获取test图集的点schema account和边schema transfer的信息
func TestMisc(t *testing.T) {
// 创建名为conn的连接并使用default图集,此部分代码省略
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
nodeSchema, _ := conn.GetNodeSchema("client", requestConfig)
fmt.Println(*nodeSchema)
edgeSchema, _ := conn.GetEdgeSchema("transfer", requestConfig)
fmt.Println(*edgeSchema)
}
CreateSchema()
方法及相关类:
CreateSchema(schema *structs.Schema,
isCreateProperties bool,
conf *configuration.RequestConfig
) (*http.UQLResponse, error)
Schema struct {
Name string
Properties []*Property
Desc string
Type string
DBType ultipa.DBType
Total int
}
Property struct {
Name string
Desc string
Lte bool
Schema string
Type ultipa.PropertyType
}
示例:为图集test创建一个有属性的点schema card1,再创建一个无属性的点schema card2
func TestMisc(t *testing.T) {
// 创建名为conn的连接并使用default图集,此部分代码省略
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
schema := &structs.Schema{
Name: "card1",
Desc: "card with 2 properties",
DBType: ultipa.DBType_DBNODE,
Properties: []*structs.Property{
{
Name: "balance",
Type: ultipa.PropertyType_FLOAT,
},
{
Name: "level",
Type: ultipa.PropertyType_INT32,
},
},
}
resp1, _ := conn.CreateSchema(schema, true, requestConfig)
log.Println(resp1.Status.Code)
schema.Name = "card2"
schema.Desc = "card with no property"
resp2, _ := conn.CreateSchema(schema, false, requestConfig) // 第二个参数 false 表示不创建属性
log.Println(resp2.Status.Code)
}
CreateSchemaIfNotExist()
方法及相关类:
CreateSchemaIfNotExist(schema *structs.Schema, config *configuration.RequestConfig) (exist bool, err error)
Schema struct {
Name string
Properties []*Property
Desc string
Type string
DBType ultipa.DBType
Total int
}
Property struct {
Name string
Desc string
Lte bool
Schema string
Type ultipa.PropertyType
}
示例:创建schema时,如果该schema已存在则返回true,否则返回false并创建
func TestMisc(t *testing.T) {
// 创建名为conn的连接并使用default图集,此部分代码省略
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
schema := &structs.Schema{
Name: "card1",
DBType: ultipa.DBType_DBNODE,
}
isExist, _ := conn.CreateSchemaIfNotExist(schema, requestConfig)
log.Println(isExist)
}