我用这个数据集试过你的案例:
这是我班级的结构TestClass
:
正如您仅从我的结构中看到的那样name
,surname
并且timeStamp
已在模式下创建,schema-full
而是以模式插入到数据库中。nameSchemaLess1
nameSchemaLess1
schema-less
完成此操作后,您可以在 OrientDB Studio 或 Console 中创建一个Javascript 函数(如此处所述),然后您可以pyOrient
使用SQL
命令从中调用它。
以下发布的函数检索该类的所有字段名称TestClass
而不重复:
Javascript函数:
var g = orient.getGraph();
var fieldsList = [];
var query = g.command("sql", "SELECT FROM TestClass");
for (var x = 0; x < query.length; x++){
var fields = query[x].getRecord().fieldNames();
for (var y = 0; y < fields.length; y++) {
if (fieldsList == false){
fieldsList.push(fields[y]);
} else {
var fieldFound = false;
for (var z = 0; z < fieldsList.length; z++){
if (fields[y] == fieldsList[z]){
fieldFound = true;
break;
}
}
if (fieldFound != true){
fieldsList.push(fields[y]);
}
}
}
}
return fieldsList;
pyOrient 代码:
import pyorient
db_name = 'TestDatabaseName'
print("Connecting to the server...")
client = pyorient.OrientDB("localhost", 2424)
session_id = client.connect("root", "root")
print("OK - sessionID: ", session_id, "\n")
if client.db_exists(db_name, pyorient.STORAGE_TYPE_PLOCAL):
client.db_open(db_name, "root", "root")
functionCall = client.command("SELECT myFunction() UNWIND myFunction")
for idx, val in enumerate(functionCall):
print("Field name: " + val.myFunction)
client.db_close()
输出:
Connecting to the server...
OK - sessionID: 54
Field name: name
Field name: surname
Field name: timeStamp
Field name: out_testClassEdge
Field name: nameSchemaLess1
Field name: in_testClassEdge
Field name: nameSchemaLess2
如您所见,已检索到所有字段名称,包括完整模式和无模式。
希望能帮助到你