ORIENTDB:使用属性遍历/边缘

时间:2016-06-23 12:43:56

标签: orientdb

我在图表数据库中有一个与应用程序权限相关的问题。结构如下......我必须阅读与节点相关的用户的角色。节点按层次结构组织,角色以包含类型属性的Edges和User - >的关系提供。 UserRole {type:xyz} - >节点

create class User extends V    
create class Node extends V  
create class has_father extends E
create class UserRole extends E

create vertex User set name = 'u1'
create vertex User set name = 'u2'
create vertex User set name = 'u3'   



create vertex Node set name = 'n1'
create vertex Node set name = 'n11'
create vertex Node set name = 'n12'
create vertex Node set name = 'n111'    
create vertex Node set name = 'n112'
create vertex Node set name = 'n1111'
create vertex Node set name = 'n1112'
create vertex Node set name = 'n11111'
create vertex Node set name = 'n11112'

create edge has_father from (select from Node where name = 'n11') to (select from Node where name = 'n1')
create edge has_father from (select from Node where name = 'n12') to (select from Node where name = 'n1')
create edge has_father from (select from Node where name = 'n111') to (select from Node where name = 'n11')
create edge has_father from (select from Node where name = 'n112') to (select from Node where name = 'n11')
create edge has_father from (select from Node where name = 'n1111') to (select from Node where name = 'n111')
create edge has_father from (select from Node where name = 'n1112') to (select from Node where name = 'n111')
create edge has_father from (select from Node where name = 'n11111') to (select from Node where name = 'n1111')
create edge has_father from (select from Node where name = 'n11112') to (select from Node where name = 'n1111')

create edge UserRole from (select from User where name = 'u1') to (select from Node where name = 'n1') set type = 'admin'
create edge UserRole from (select from User where name = 'u1') to (select from Node where name = 'n11') set type = 'read'
create edge UserRole from (select from User where name = 'u2') to (select from Node where name = 'n111') set type = 'write'
create edge UserRole from (select from User where name = 'u1') to (select from Node where name = 'n11111') set type = 'test'

实际上我现在必须阅读“n”中的所有孩子并获得用户“u1”的Node和UserRole:

要求“u1”和“n1”:

n11 read
n12 admin

要求“u1”和“n1111”:

n11111 test
n11112 read

表示分配了最多1个UserRole,并且该值可能会在树中被覆盖。用户可能是 管理员的根级别,只读取级别n11。

如何读取传递父亲@rid(或过滤器)的子节点和特殊用户的计算角色?

1 个答案:

答案 0 :(得分:2)

尝试使用此SQL作为第二个示例:

u1

其中#21:0是var Promise = require('bluebird'); var timer = function(name) { var start = new Date(); return { stop: function() { var end = new Date(); var time = end.getTime() - start.getTime(); console.log('Function:', name, 'finished in', time, 'ms'); } }; }; function regular (a, cb) { if (a % 2 === 0) return cb(null, a); return cb(a); } function promise (a) { return new Promise (function (resolve, reject) { if (a % 2 === 0) resolve(a); else reject(a); }); } var t = timer('regular'); var g = 0; for (var i = 1; i < 10001; i++) { regular(i, function(odd, even) { if (odd) g = g + (odd * 2); else g = g + (even * 3); }); } console.log('g:', g); // g: 125015000 t.stop(); var t2 = timer('promise'); var h = 0; for (var i = 1; i < 10001; i++) { promise(i).then(function(x) {h = h + (x*3);}).catch(function(x) {h = h + (x*2);}); } console.log('h:', h); // h: 0 t2.stop(); @rid。

只要这不是那么漂亮,你可以在JS函数中插入它并对其进行参数化。

enter image description here enter image description here