获取 Orientdb 中所有使用的模式混合类的字段名 [英] Get all used fieldnames of schema-hybrid Class in Orientdb

查看:41
本文介绍了获取 Orientdb 中所有使用的模式混合类的字段名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始研究 OrientDB 并尝试使用 OrientDB 作为数据库编写一个简单的 web 应用程序.

I started to look at OrientDB and try to code a simple webapp with OrientDB as Database.

我有一个模式混合数据库模式,其中包括类服务器.是否有可能获得所有使用过的字段,甚至是架构中未定义的字段?这样在 webapp 前端,可以向用户显示其他服务器中存在的字段列表.

I have a schema-hybrid database schema, which includes the class Server. Is there any possibility to get all used fields, even the one that are not defined in the schema? So that in the webapp frontend a list of fields existing in the other Servers can be shown to the user.

所以在以下情况下:

CREATE CLASS Server EXTENDS V
CREATE PROPERTY Server.name string
CREATE PROPERTY Server.hostnames embeddedlist string
CREATE VERTEX Server SET name = "SRV1",hostnames = ["srv1.de.test.ag","srv1.test.ag"], cpu = "3-GHZ"

我可以使用以下命令获取架构中定义的字段:

I can get the fields defined in the schema with:

select expand(properties) from (select expand(classes) from metadata:schema) where name = "Server"

但是有没有办法获取cpu-field 或者更确切地说是该类中使用的所有无模式字段?在文档中找不到内容.

But is there a way to get the cpu-field or rather all schema-less fields which are used in this class? Can't find something in the docs.

推荐答案

Schema-Hybrid 的概念是什么;

Conceptually what Schema-Hybrid means is;

  • 让你为一个类定义一个模式,这样每个记录(或实例)符合架构
  • 让每个记录(或实例)定义自己的自定义字段

因此,创建的自定义字段实际上处于单个记录级别.因此,除了从架构定义的字段之外,两个实例可以具有两组不同的自定义字段.

Therefore, the custom fields created are actually at individual record levels. Hence, two instances could have two different sets of custom fields apart from the fields defined from the schema.

由于上述原因,获取所有字段(即模式定义+自定义定义)的唯一方法是扫描所有记录,并找出每个记录在自定义中定义的内容.

Due to the above reason, the only way to get all the fields (i.e. schema defined + custom defined), is to scan through all the records, and figure out what each of the records have defined in custom.

您可以使用 API 做到这一点.以下是通过 JavaScript 调用 API 的方法.你可以用 Java 做同样的事情.

You can do that using the API. Following is how you can invoke the API via JavaScript. You can do the same with Java.

var db = orient.getGraph();

var result = db.command("sql", "SELECT FROM V WHERE @rid = #9:2");
var fields = result[0].getRecord().fieldNames();

for (var i = 0; i < fields.length; i++) {
  print(fields[i]);
}

如果您确保所有记录(即所有 Server 或 Server1 记录)都具有相同的自定义字段集,您可以使用上述代码查询一条记录并获取该记录的所有字段.这可以为您完成工作.

If you make sure that all the records (i.e. all the Server or Server1 records) will have the same set of custom fields, you can use the above code to query one record and get all the fields for that record. That'd do the job for you.

希望这会有所帮助!

这篇关于获取 Orientdb 中所有使用的模式混合类的字段名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆