修改密码

请输入密码
请输入密码 请输入8-64长度密码 和 email 地址不相同 至少包括数字、大写字母、小写字母、半角符号中的 3 个
请输入密码
提交

修改昵称

当前昵称:
提交

申请证书

证书详情

Please complete this required field.

  • Ultipa Graph V4

Standalone

Please complete this required field.

Please complete this required field.

服务器的MAC地址

Please complete this required field.

Please complete this required field.

取消
申请
ID
产品
状态
核数
申请天数
审批时间
过期时间
MAC地址
申请理由
审核信息
关闭
基础信息
  • 用户昵称:
  • 手机号:
  • 公司名称:
  • 公司邮箱:
  • 地区:
  • 语言:
修改密码
申请证书

当前未申请证书.

申请证书
Certificate Issued at Valid until Serial No. File
Serial No. Valid until File

Not having one? Apply now! >>>

ProductName CreateTime ID Price File
ProductName CreateTime ID Price File

No Invoice

v4.5
搜索
    v4.5

      Schema和属性管理

      本节为您介绍如何使用Connection对象的方法管理图集中点和边的schema与属性。

      每个示例主要展示如何使用所列方法。点击完整示例查看完整代码示例。

      Schema

      ShowSchema()

      从当前图集获取全部点、边的schema信息。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • List<Schema>:当前图集全部schema列表。

      // 获取图集UltipaTeam的所有schema并打印schema的类型和名称
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      var schemaInfo = await ultipa.ShowSchema(requestConfig);
      
      foreach (var schema in schemaInfo)
      {
          Console.WriteLine(schema.DbType + ": " + schema.Name);
      }
      

      Dbnode: default
      Dbnode: member
      Dbnode: organization
      Dbedge: default
      Dbedge: reportsTo
      Dbedge: relatesTo
      

      GetSchema()

      从当前图集获取一个点schema或一个边schema。

      参数:

      • string:schema名称
      • DBType:schema类型(点schema或边schema)。
      • RequestConfig(可选):配置请求。

      返回值:

      • Schema:目标schema。

      // 获取图集UltipaTeam中名为member的点schema和名为connectsTo的边schema,并打印其信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var schema1 = await ultipa.GetSchema("member", DBType.Dbnode, requestConfig);
      Console.WriteLine("schema1: " + JsonConvert.SerializeObject(schema1));
      
      var schema2 = await ultipa.GetSchema("connectsTo", DBType.Dbedge, requestConfig);
      Console.WriteLine("schema2: " + JsonConvert.SerializeObject(schema2));
      

      schema1: {"Name":"member","Desc":"","DbType":0,"Total":0,"Properties":[{"Name":"title","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""},{"Name":"profile","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""},{"Name":"startDate","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":8,"SubTypes":[],"Extra":"{}","Encrypt":""}]}
      schema2: null
      

      ShowNodeSchema()

      获取当前图集的全部点schema。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • List<Schema>: 当前图集全部点schema列表。

      // 获取图集UltipaTeam的全部点schema并打印其名称
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var schemaList = await ultipa.ShowNodeSchema(requestConfig);
      foreach (var schema in schemaList)
      {
          Console.WriteLine(schema.Name);
      }
      

      default
      member
      organization
      

      ShowEdgeSchema()

      获取当前图集的全部边schema。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • List<Schema>:当前图集的全部边schema列表。

      // 获取图集UltipaTeam的全部边schema并打印其名称
      
      var schemaList = await ultipa.ShowEdgeSchema(requestConfig);
      foreach (var schema in schemaList)
      {
          Console.WriteLine(schema.Name);
      }
      

      default
      reportsTo
      relatesTo
      

      GetNodeSchema()

      Retrieves a node schema from the current graphset.

      参数:

      • string:schema名称
      • RequestConfig(可选):配置请求。

      返回值:

      • Schema:目标点schema。

      // 获取图集UltipaTeam中名为member的点schema并打印其属性信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var schema = await ultipa.GetNodeSchema("member", requestConfig);
      
      foreach (var item in schema.Value.Properties)
      {
          Console.WriteLine(JsonConvert.SerializeObject(item));
      }
      

      {"Name":"title","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      {"Name":"profile","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      {"Name":"startDate","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":8,"SubTypes":[],"Extra":"{}","Encrypt":""}
      

      GetEdgeSchema()

      获取当前图集的一个边schema。

      参数:

      • string:schema名称
      • RequestConfig(可选):配置请求。

      返回值:

      • Schema:目标边schema。

      // 获取图集UltipaTeam中名为relatesTo的边schema并打印其属性信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var schema = await ultipa.GetEdgeSchema("relatesTo", requestConfig);
      
      foreach (var item in schema.Value.Properties)
      {
          Console.WriteLine(JsonConvert.SerializeObject(item));
      }
      

      {"Name":"type","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"relatesTo","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      

      CreateSchema()

      在当前图集新建一个schema。

      参数:

      • Schema: 要创建的模式;必须设置Name字段,DbType(如果不指定,默认使用 Dbnode)和Desc(描述的缩写)是可选的。
      • bool (Optional):是否创建属性,默认为false
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      // 在图集UltipaTeam中新建名为utility的点schema(包含属性),并打印其全部信息。 
      
      var new1 = await ultipa.CreateSchema(
          new Schema()
          {
              Name = "utility",
              DbType = DBType.Dbnode,
              Properties = new List<Property>()
              {
                  new Property() { Name = "name", Type = PropertyType.String },
                  new Property() { Name = "purchaseDate", Type = PropertyType.Datetime },
              },
          },
          true,
          requestConfig
      );
      Console.WriteLine(new1.Status.ErrorCode);
      Thread.Sleep(3000);
      var show1 = await ultipa.GetNodeSchema("utility", requestConfig);
      Console.WriteLine(JsonConvert.SerializeObject(show1.Value));
      
      // 在图集UltipaTeam中新建名为managedBy(不包含属性)的边schema并打印其全部信息
      
      var new2 = await ultipa.CreateSchema(
          new Schema()
          {
              Name = "managedBy",
              Desc = "office utilities",
              DbType = DBType.Dbedge,
          },
          requestConfig
      );
      Console.WriteLine(new2.Status.ErrorCode);
      Thread.Sleep(3000);
      var show2 = await ultipa.GetEdgeSchema("managedBy", requestConfig);
      Console.WriteLine(JsonConvert.SerializeObject(show2.Value));
      

      Success
      {"Name":"utility","Desc":"","DbType":0,"Total":0,"Properties":[{"Name":"name","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"utility","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""},{"Name":"purchaseDate","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"utility","Type":8,"SubTypes":[],"Extra":"{}","Encrypt":""}]}
      Success
      {"Name":"managedBy","Desc":"office utilities","DbType":1,"Total":0,"Properties":[]}
      

      CreateSchemaIfNotExist()

      在当前图集新建一个schema,若同名schema已存在,忽略报错。

      参数:

      • Schema: 待创建的schema;必须设置name字段和 dbType字段,description字段和properties字段可选。
      • bool(可选):是否创建属性,默认为false
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。
      • bool:该Schema是否已经存在。

      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      
      // 在图集UltipaTeam中新建一个schema并打印创建是否发生
      
      var new1 = await ultipa.CreateSchemaIfNotExist(
          new Schema() { Name = "utility", DbType = DBType.Dbnode },
          requestConfig
      );
      Console.WriteLine("Schema already exists: " + new1.Item2);
      Thread.Sleep(3000);
      
      // 再次创建同个schema并打印创建是否发生
      
      var new2 = await ultipa.CreateSchemaIfNotExist(
          new Schema() { Name = "utility", DbType = DBType.Dbnode },
          requestConfig
      );
      Console.WriteLine("Schema already exists: " + new2.Item2);
      

      Schema already exists: False
      Schema already exists: True
      

      AlterSchema()

      根据schema名称修改当前图集中某个schema的名称和描述。

      参数:

      • Schema:图集中待修改的schema;必须设置Name字段和DbType字段。
      • Schema:更新已有schema的配置;必须设置 NameDbType 字段。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      // 将图集UltipaTeam中的一个点schema由utility改为securityUtility并删除其描述
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var alter = await ultipa.AlterSchema(
          new Schema() { Name = "utility", DbType = DBType.Dbnode },
          new Schema()
          {
              Name = "securityUtility",
              DbType = DBType.Dbnode,
              Desc = "yyyy",
          },
          requestConfig
      );
      Console.WriteLine(alter.Status.ErrorCode);
      

      Success
      

      DropSchema()

      根据schema名称从当前图集删除某个schema。

      参数:

      • Schema:图集中待删除的schema;必须设置Name 字段和 DbType 字段。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      // 在图集UltipaTeam中删除名为utility的点schema
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.DropSchema(
          new Schema() { Name = "utility", DbType = DBType.Dbnode },
          requestConfig
      );
      Console.WriteLine(res.Status.ErrorCode);
      

      Success
      

      Property

      ShowProperty()

      获取当前图集的自定义点属性信息或边属性信息。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • string (可选):schema名称
      • RequestConfig(可选):配置请求。

      返回值:

      • List<Property>:当前图集全部目标属性列表。

      // 获取图集UltipaTeam的所有自定义点属性信息并打印其名称、类型和关联的schema
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.ShowProperty(DBType.Dbnode, requestConfig);
      foreach (var item in res)
      {
          Console.WriteLine(
              $"{item.Name}({item.Type}) is associated with schema named {item.Schema}"
          );
      }
      

      name(String) is associated with schema named member
      title(String) is associated with schema named member
      profile(String) is associated with schema named member
      name(String) is associated with schema named organization
      logo(String) is associated with schema named organization
      

      ShowNodeProperty()

      获取当前图集的自定义点属性信息。

      参数:

      • string(可选):schema名称
      • RequestConfig(可选):配置请求。

      返回值:

      • List<Property>:当前图集全部目标属性列表。

      // 获取图集UltipaTeam中名为member的点schema其关联的所有自定义点属性信息并打印属性数量
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.ShowNodeProperty("member", requestConfig);
      Console.WriteLine(res.Count);
      

      3
      

      ShowEdgeProperty()

      获取当前图集的自定义边属性信息。

      参数:

      • RequestConfig(可选):配置请求。

      返回值:

      • string(可选):schema名称
      • List<Property>:当前图集全部目标属性列表。

      // 从图集UltipaTeam中的名为relatesTo的边schema中获取所有自定义属性,并打印出它们的名称
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.ShowEdgeProperty("relatesTo", requestConfig);
      foreach (var item in res)
      {
          Console.WriteLine(item.Name);
      }
      

      type
      

      GetProperty()

      获取当前图集的一个自定义点属性或边属性。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • string:schema名称
      • string:属性名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • Property:目标属性。

      // 获取图集UltipaTeam的点属性@member.title并打印其全部信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.GetProperty(DBType.Dbnode, "member", "title", requestConfig);
      Console.WriteLine(JsonConvert.SerializeObject(res));
      

      {"Name":"title","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      

      GetNodeProperty()

      Retrieves a custom property of nodes from the current graphset.

      参数:

      • string:schema名称
      • string:属性名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • Property:目标属性。

      // 获取图集UltipaTeam的点属性@member.title并打印其全部信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.GetNodeProperty("member", "title", requestConfig);
      Console.WriteLine(JsonConvert.SerializeObject(res));
      

      {"Name":"title","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"member","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      

      GetEdgeProperty()

      获取当前图集的一个自定义边属性。

      参数:

      • string:schema名称
      • string:属性名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • Property:目标属性。

      // 获取图集UltipaTeam的边属性@relatesTo.type并打印其全部信息
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res = await ultipa.GetEdgeProperty("relatesTo", "type", requestConfig);
      Console.WriteLine(JsonConvert.SerializeObject(res));
      

      {"Name":"type","Desc":"","Lte":false,"Read":true,"Write":true,"Schema":"relatesTo","Type":7,"SubTypes":[],"Extra":"{}","Encrypt":""}
      

      CreateProperty()

      在当前图集为点schema或边schema创建一个属性。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • Property:要创建的属性;必须设置 SchemaNameType 字段;在 Schema 中写 * 表示所有模式。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      // 在图集UltipaTeam中为名为member的点schema创建两个属性并打印错误代码
      
      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      var res1 = await ultipa.CreateProperty(
          DBType.Dbnode,
          new Property()
          {
              Name = "startDate",
              Schema = "member",
              Type = PropertyType.Datetime,
          },
          requestConfig
      );
      Console.WriteLine(res1.Status.ErrorCode);
      
      var res2 = await ultipa.CreateProperty(
          DBType.Dbnode,
          new Property()
          {
              Name = "age",
              Schema = "member",
              Type = PropertyType.Int32,
          },
          requestConfig
      );
      Console.WriteLine(res2.Status.ErrorCode);
      

      Success
      Success
      

      CreatePropertyIfNotExist()

      在当前图集为某个点schema或边schema新建一个属性,若同名属性已存在,忽略报错。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • Property:待创建的属性;必须设置Name字段和Type字段。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。
      • bool:该属性是否已经存在。

      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      // 在图集UltipaTeam中为名为member的点schema新建一个属性并打印创建是否发生
      
      var res1 = await ultipa.CreatePropertyIfNotExist(
          DBType.Dbnode,
          new Property()
          {
              Name = "startDate",
              Schema = "member",
              Type = PropertyType.Datetime,
          },
          requestConfig
      );
      Console.WriteLine("Property already exists: " + res1.Item2);
      
      // 在图集UltipaTeam中再次创建同个属性并打印创建是否发生
      
      var res2 = await ultipa.CreatePropertyIfNotExist(
          DBType.Dbnode,
          new Property()
          {
              Name = "startDate",
              Schema = "member",
              Type = PropertyType.Datetime,
          },
          requestConfig
      );
      Console.WriteLine("Property already exists: " + res2.Item2);
      

      Property already exists: False
      Property already exists: True
      

      AlterProperty()

      根据属性名称修改当前图集中某个自定义属性的名称和描述。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • Property:图集中待修改的属性;必须设置name字段和schema字段(可用*指定全部schema)。
      • Property:更新已有属性的配置;对于name字段和description字段,必须至少设置其中一个字段。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      // 将图集UltipaTeam中全部点schema下的name属性改为Name
      
      var res = await ultipa.AlterProperty(
          DBType.Dbnode,
          new Property() { Name = "name", Schema = "*" },
          new Property() { Name = "Name", Schema = "*" },
          requestConfig
      );
      Console.WriteLine(res.Status.ErrorCode);
      

      Success
      

      DropProperty()

      根据属性名称和关联schema从当前图集删除某自定义属性。

      参数:

      • DBType:属性类型(点属性或边属性)。
      • string:schema名称
      • string:属性名称。
      • RequestConfig(可选):配置请求。

      返回值:

      • UqlResponse:请求的结果。

      RequestConfig requestConfig = new RequestConfig() { Graph = "UltipaTeam" };
      
      // 删除图集UltipaTeam中与全部点schema关联的startDate属性并打印错误代码
      
      var res1 = await ultipa.DropProperty(DBType.Dbnode, "*", "startDate", requestConfig);
      Console.WriteLine(res1.Status.ErrorCode);
      
      // 删除图集UltipaTeam的点属性@member.name并打印错误代码
      
      var res2 = await ultipa.DropProperty(DBType.Dbnode, "member", "name", requestConfig);
      Console.WriteLine(res2.Status.ErrorCode);
      

      Success
      Success
      

      完整示例

      using System.Security.Cryptography.X509Certificates;
      using System.Threading;
      using System.Xml.Linq;
      using Microsoft.Extensions.Logging;
      using Newtonsoft.Json;
      using UltipaService;
      using UltipaSharp;
      using UltipaSharp.api;
      using UltipaSharp.configuration;
      using UltipaSharp.connection;
      using UltipaSharp.exceptions;
      using UltipaSharp.structs;
      using UltipaSharp.utils;
      using Logger = UltipaSharp.utils.Logger;
      using Property = UltipaSharp.structs.Property;
      using Schema = UltipaSharp.structs.Schema;
      
      class Program
      {
          static async Task Main(string[] args)
          {
              // 设置连接
              //URI 示例: Hosts=new[]{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"}
              var myconfig = new UltipaConfig()
              {
                  Hosts = new[] { "192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061" },
                  Username = "***",
                  Password = "***",
              };
      
              // 建立与数据库的连接
              var ultipa = new Ultipa(myconfig);
              var isSuccess = ultipa.Test();
              Console.WriteLine(isSuccess);
             
              // 配置请求
              RequestConfig requestConfig = new RequestConfig() { UseMaster = true };
      
              // 在图集UltipaTeam中新建名为utility的点schema(同时创建属性)并打印错误代码
              var res = await ultipa.CreateSchema(
                  new Schema()
                  {
                      Name = "utility",
                      DbType = DBType.Dbnode,
                      Properties = new List<Property>()
                      {
                          new Property() { Name = "name", Type = PropertyType.String },
                          new Property() { Name = "purchaseDate", Type = PropertyType.Datetime },
                      },
                      Desc = "Office utilities",
                  },
                  true,
                  requestConfig
              );
              Console.WriteLine("Node schema creation : " + res.Status.ErrorCode);
              Console.WriteLine(
                  JsonConvert.SerializeObject(
                      (await ultipa.GetNodeSchema("utility", requestConfig)).Value
                  )
              );
      
          }
      }
      
      请完成以下信息后可下载此书
      *
      公司名称不能为空
      *
      公司邮箱必须填写
      *
      你的名字必须填写
      *
      你的电话必须填写
      *
      你的电话必须填写