简体   繁体   English

如何使用orientjs查询构建器插入具有链接类型属性的顶点?

[英]How to insert a vertex with link type property with the orientjs query builder?

I am trying to insert a vertex with orientjs(previously oriento) query builder. 我正在尝试使用orientjs(以前是oriento)查询生成器插入一个顶点。 My class has a link type property pointing to another class. 我的班级有一个指向另一个班级的链接类型属性。

I know I can get it to work with a raw query string but I would love to use the query builder. 我知道我可以使它与原始查询字符串一起使用,但是我很想使用查询生成器。

Here is what I've tried so far : 到目前为止,这是我尝试过的:

db.insert()
.into('VertexClassName')
.set({"prop":"value", "linkProperty":"33:1289287"})

db.insert()
.into('VertexClassName')
.set({"prop":"value", "linkProperty":"#33:1289287"})

I get the following error : 我收到以下错误:

Error on saving record in cluster #13

Am I setting properties in the right way ? 我是否以正确的方式设置属性? Could the error be related to somtehing else ? 错误可能与其他错误有关吗? I have sucessfully ran an insert query in the cluster #13 with a raw query string in the studio... 我已经在演播室#13中成功运行了带有原始查询字符串的插入查询...

According to the official documentation it seems that the problem might be at the end of your statement 根据官方文档,问题可能出在声明的结尾。

db.insert().into('VertexClassName')
    .set({"prop":"value", "linkProperty":"33:1289287"}).one()
    .then(function (data) {
       // callback
});

Check if your code works adding one() to the pipe line 检查您的代码是否可以在管道上添加one()

EDITED : I found this method in orientjs. 编辑 :我在orientjs中发现了此方法。

db.create('VERTEX', 'V')
.set({
  key: 'value',
  foo: 'bar'
})
.one()
.then(function (vertex) {
  console.log('created vertex', vertex);
});

When using Tinkerpop API they recommend using createVertex instead of insert, because createVertex is intended for graphs and insert for Documents... Could you try with the create() method instead? 当使用Tinkerpop API时,他们建议使用createVertex而不是insert,因为createVertex是用于图形的,而用于Documents的插入...您可以尝试使用create()方法吗?

I am using SQL and it worked. 我正在使用SQL,它起作用了。

sql = "INSERT INTO Station set linked = (select from LinkedClass where LinkedProb = 'value'), prop = 'value'"

OrientVertex vertex = new OrientVertex();
vertex = graph.command(new OCommandSQL(sql)).execute();

I don't think that's possible unless you've added a proper field with the right type 'Link' in your schema. 我认为这是不可能的,除非您在架构中添加了正确类型为“链接”的正确字段。 (which I rarely do). (我很少这样做)。

Now instead of having the right 'link' type inserted you can do the opposite, store is as a String, and leverage the query functions to use it correctly: 现在,您可以执行相反的操作,而不是插入正确的“链接”类型,将其存储为字符串,并利用查询函数正确使用它:

db.insert().into('table').set({prop: '#15:14'}).one();

And it will be converted as String (which is a bit sad) but then you can use that in your queries: 它将被转换为String(这有点令人遗憾),但是您可以在查询中使用它:

SELECT eval(prop) FROM table; 

And it will be 'eval'-ed to a Node RecordID that you can directly use and call functions like expand() on. 它将被“评估”为可以直接使用的Node RecordID,并调用诸如expand()之类的函数。

For example: 例如:

SELECT name FROM (SELECT expand(eval(prop)) FROM table); 

Will eval the node stored in the insert(), grab the node, expand it and collect its name property. 将评估存储在insert()中的节点,抓取该节点,展开它并收集其name属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM