Created
May 13, 2014 13:16
-
-
Save r0mdau/34757332ade7862a3e82 to your computer and use it in GitHub Desktop.
ArangoDb GoT exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getSons = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 && p.destination.gender == 'm' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getDaughters = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 && p.destination.gender == 'f' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getBrothers = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == 'gameOfThrone/Eddard_Stark' && LENGTH(p.edges) == 1 FOR q IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER q.source._id == p.destination._id && LENGTH(q.edges) == 1 && q.destination.gender == 'm' && q.destination._id != 'gameOfThrone/Eddard_Stark' RETURN q.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getSisters = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == 'gameOfThrone/Eddard_Stark' && LENGTH(p.edges) == 1 FOR q IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER q.source._id == p.destination._id && LENGTH(q.edges) == 1 && q.destination.gender == 'f' && q.destination._id != 'gameOfThrone/Eddard_Stark' RETURN q.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getFather = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 && p.destination.gender == 'm' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getMother = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 && p.destination.gender == 'f' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getChildren = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER p.source._id == @id && LENGTH(p.edges) == 1 RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getUncles = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : " FOR a IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER a.source._id == @id && LENGTH(a.edges) == 1 FOR b IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER b.source._id == a.destination._id && LENGTH(b.edges) == 1 FOR c IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER c.source._id == b.destination._id && LENGTH(c.edges) == 1 && c.destination._id != a.destination._id && c.destination.gender == 'm' RETURN c.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getAunts = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : " FOR a IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER a.source._id == @id && LENGTH(a.edges) == 1 FOR b IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER b.source._id == a.destination._id && LENGTH(b.edges) == 1 FOR c IN PATHS(gameOfThrone, parentOf, 'outbound') FILTER c.source._id == b.destination._id && LENGTH(c.edges) == 1 && c.destination._id != a.destination._id && c.destination.gender == 'f' RETURN c.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getGrandFathers = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == @id && LENGTH(p.edges) == 2 && p.destination.gender == 'm' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; | |
var getGrandMothers = function(personnage) { | |
dbStatement = db._createStatement({ | |
"query" : "FOR p IN PATHS(gameOfThrone, parentOf, 'inbound') FILTER p.source._id == @id && LENGTH(p.edges) == 2 && p.destination.gender == 'f' RETURN p.destination" | |
}); | |
dbStatement.bind("id", personnage); | |
return dbStatement.execute(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment