mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 22:39:06 +02:00
implement relationship delete
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
MATCH (a:Person)-[r]-(b:Person)
|
||||
WHERE id(a) = $id1 AND id(b) = $id2 AND type(r) != Admin
|
||||
DELETE r;
|
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||
"github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter/pkg/api"
|
||||
)
|
||||
|
||||
func GetRelationship(ctx context.Context, id1, id2 int) neo4j.ManagedTransactionWork {
|
||||
@@ -16,25 +17,6 @@ func GetRelationship(ctx context.Context, id1, id2 int) neo4j.ManagedTransaction
|
||||
return nil, err
|
||||
}
|
||||
|
||||
records, err := result.Collect(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return records, nil
|
||||
}
|
||||
}
|
||||
|
||||
func CreateChildParentRelationship(ctx context.Context, childId, parentId int) neo4j.ManagedTransactionWork {
|
||||
return func(tx neo4j.ManagedTransaction) (any, error) {
|
||||
result, err := tx.Run(ctx, CreateChildParentRelationshipCypherQuery, map[string]any{
|
||||
"childId": childId,
|
||||
"parentId": parentId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
record, err := result.Single(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -43,3 +25,65 @@ func CreateChildParentRelationship(ctx context.Context, childId, parentId int) n
|
||||
return record.AsMap(), nil
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteRelationship(ctx context.Context, id1, id2 int) neo4j.ManagedTransactionWork {
|
||||
return func(tx neo4j.ManagedTransaction) (any, error) {
|
||||
result, err := tx.Run(ctx, DeleteRelationshipCypherQuery, map[string]any{
|
||||
"id1": id1,
|
||||
"id2": id2,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return !result.Peek(ctx), nil
|
||||
}
|
||||
}
|
||||
|
||||
func CreateChildParentRelationship(ctx context.Context, childId, parentId int) neo4j.ManagedTransactionWork {
|
||||
return func(tx neo4j.ManagedTransaction) (any, error) {
|
||||
result, err := tx.Run(ctx, CreateChildParentRelationshipCypherQuery, map[string]any{
|
||||
"childId": childId,
|
||||
"parentId": parentId,
|
||||
"childRelationship": api.FamilyRelationship{},
|
||||
"parentRelationship": api.FamilyRelationship{},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Single(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSiblingRelationship(ctx context.Context, siblingId1, siblingId2 int) neo4j.ManagedTransactionWork {
|
||||
return func(tx neo4j.ManagedTransaction) (any, error) {
|
||||
result, err := tx.Run(ctx, CreateSiblingRelationshipCypherQuery, map[string]any{
|
||||
"id1": siblingId1,
|
||||
"id2": siblingId2,
|
||||
"Relationship1": api.FamilyRelationship{},
|
||||
"Relationship2": api.FamilyRelationship{},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Collect(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSpouseRelationship(ctx context.Context, spouseId1, spouseId2 int) neo4j.ManagedTransactionWork {
|
||||
return func(tx neo4j.ManagedTransaction) (any, error) {
|
||||
result, err := tx.Run(ctx, CreateSpouseRelationshipCypherQuery, map[string]any{
|
||||
"id1": spouseId1,
|
||||
"id2": spouseId2,
|
||||
"Relationship1": api.FamilyRelationship{},
|
||||
"Relationship2": api.FamilyRelationship{},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result.Collect(ctx)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user