mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 06:19:05 +02:00
implement family tree query
This commit is contained in:
@@ -125,3 +125,17 @@ var GetProfileAdminsCypherQuery string
|
||||
//
|
||||
//go:embed queries/get_managed_profiles.cypher
|
||||
var GetManagedProfilesCypherQuery string
|
||||
|
||||
// Requires id parameter.
|
||||
//
|
||||
// returns people, relationships
|
||||
//
|
||||
//go:embed queries/get_blood_relations_by_id.cypher
|
||||
var GetBloodRelativesCypherQuery string
|
||||
|
||||
// Requires id parameter.
|
||||
//
|
||||
// returns people, relationships
|
||||
//
|
||||
//go:embed queries/get_family_tree_with_spouses.cypher
|
||||
var GetFamilyTreeWithSpousesCypherQuery string
|
||||
|
@@ -1,4 +1,19 @@
|
||||
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
|
||||
MATCH (n:Person)
|
||||
WHERE id(n) = $id
|
||||
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
|
||||
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
|
||||
RETURN collect(family) + collect(children) + collect(n), collect(c) + collect(p)
|
||||
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
|
||||
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
|
||||
WITH collections.to_set(collect(n)+collect(family)+collect(children)+collect(direct_siblings)) as people,
|
||||
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds)) as relationships
|
||||
UNWIND people as ppl
|
||||
RETURN collect({
|
||||
id: id(ppl),
|
||||
first_name: ppl.first_name,
|
||||
middle_name: ppl.middle_name,
|
||||
last_name: ppl.last_name,
|
||||
born: ppl.born,
|
||||
died: ppl.died,
|
||||
profile_picture: ppl.profile_picture
|
||||
}) as people,
|
||||
relationships;
|
@@ -1,8 +0,0 @@
|
||||
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
|
||||
WHERE id(n) = $id
|
||||
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
|
||||
WITH family, p, children, c, n
|
||||
OPTIONAL MATCH (children)<-[p2:Parent]-(OtherParents:Person)
|
||||
WITH family, p, children, c, OtherParents, p2, n
|
||||
OPTIONAL MATCH (family)-[s:Spouse]-(spouse:Person)
|
||||
RETURN family, p, children, c, OtherParents, p2, spouse, s, n;
|
@@ -0,0 +1,22 @@
|
||||
MATCH (n:Person)
|
||||
WHERE id(n) = $id
|
||||
OPTIONAL MATCH (n)-[p:Parent*..]->(family:Person)
|
||||
OPTIONAL MATCH (family)-[c:Child*1..4]->(children:Person)
|
||||
OPTIONAL MATCH (family)-[s:Sibling]->(siblings:Person)
|
||||
OPTIONAL MATCH (n)-[ds:Sibling]->(direct_siblings:Person)
|
||||
OPTIONAL MATCH (family)-[fsp:Spouse]->(fspouse:Person)
|
||||
OPTIONAL MATCH (children)-[csp:Spouse]->(cspouse:Person)
|
||||
OPTIONAL MATCH (n)-[sp:Spouse]->(spouse:Person)
|
||||
WITH collections.to_set(collect(n) + collect(family) + collect(children) + collect(direct_siblings) + collect(fspouse) + collect(cspouse) + collect(spouse)) as people,
|
||||
collections.to_set(collect(c) + collect(p) + collect(s) + collect(ds) + collect(fsp) + collect(csp) + collect(sp)) as relationships
|
||||
UNWIND people as ppl
|
||||
RETURN collect({
|
||||
id: id(ppl),
|
||||
first_name: ppl.first_name,
|
||||
middle_name: ppl.middle_name,
|
||||
last_name: ppl.last_name,
|
||||
born: ppl.born,
|
||||
died: ppl.died,
|
||||
profile_picture: ppl.profile_picture
|
||||
}) as people,
|
||||
relationships;
|
@@ -1,4 +0,0 @@
|
||||
MATCH (n:Person)-[p:Parent*1..]->(family:Person)
|
||||
WHERE id(n) = $id
|
||||
OPTIONAL MATCH (family)-[c:Child*..4]->(children:Person)
|
||||
RETURN family, p, children, c, n
|
Reference in New Issue
Block a user