package neo4j import ( "context" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func EstablishPostTagLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621Tag string) error { query := ` MATCH (p:e621Post {e621PostID: $e621PostID}) MATCH (t:e621Tag {e621Tag: $e621Tag}) MERGE (p)-[:HAS_TAG]->(t) ` params := map[string]interface{}{ "e621PostID": e621PostID, "e621Tag": e621Tag, } _, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer) if err != nil { return err } return nil } func EstablishPostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, sourceURL string) error { query := ` MATCH (p:e621Post {e621PostID: $e621PostID}) MATCH (s:Source {URL: $sourceURL}) MERGE (p)-[:HAS_SOURCE]->(s) ` params := map[string]interface{}{ "e621PostID": e621PostID, "sourceURL": sourceURL, } _, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer) if err != nil { return err } return nil } func EstablishUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621UserID int64) error { query := ` MATCH (p:e621Post {e621PostID: $e621PostID}) MATCH (u:e621User {e621ID: $e621ID}) MERGE (u)-[:IS_FAVORITE]->(p) ` params := map[string]interface{}{ "e621PostID": e621PostID, "e621ID": e621UserID, } _, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer) if err != nil { return err } return nil } // CheckUserToPostRelationship gives back a bool if the connection between the post and the user exists func RelationshipCheckUserToPost(ctx context.Context, driver neo4j.DriverWithContext, e621PostID int64, e621UserID int64) (bool, error) { query := ` MATCH (user:e621User {e621ID: $e621ID})-[favorite:IS_FAVORITE]->(post:e621Post {e621PostID: $e621PostID}) RETURN COUNT(favorite) > 0 AS isFavorite ` params := map[string]interface{}{ "e621PostID": e621PostID, "e621ID": e621UserID, } result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer) if err != nil { return false, err } exists, _, err := neo4j.GetRecordValue[bool](result.Records[0], "isFavorite") if err != nil { return false, err } return exists, nil }