mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
delete relationship
This commit is contained in:
36
backend/memgraph/deleteRelationship.go
Normal file
36
backend/memgraph/deleteRelationship.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package memgraph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func (r *Relationship) DeleteRelationship(driver neo4j.DriverWithContext) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
session := driver.NewSession(ctx, neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead})
|
||||
defer session.Close(ctx)
|
||||
|
||||
if err := r.Verify(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
query := ""
|
||||
if r.Direction == "->" {
|
||||
query = fmt.Sprintf(`MATCH (a)-[r:%s]->(b)`, r.Relationship)
|
||||
} else if r.Direction == "<-" {
|
||||
query = fmt.Sprintf(`MATCH (a)<-[r:%s]-(b)`, r.Relationship)
|
||||
} else {
|
||||
query = fmt.Sprintf(`MATCH (a)-[r:%s]-(b)`, r.Relationship)
|
||||
}
|
||||
|
||||
query = fmt.Sprintf(`%s WHERE a.ID = %s AND b.ID = %s DELETE r;`, query, r.FirstPersonID, r.SecondPersonID)
|
||||
|
||||
_, err := session.Run(ctx, query, nil)
|
||||
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user