62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package neo4j
|
|
|
|
import (
|
|
"context"
|
|
"e621_to_neo4j/database/neo4j/models"
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
|
)
|
|
|
|
func CreateTagNode(ctx context.Context, driver neo4j.DriverWithContext, name string, tagType string) error {
|
|
query := `
|
|
MERGE (u:e621Tag {e621Tag: $name, e621TagType: $tagType})
|
|
RETURN u
|
|
`
|
|
params := map[string]interface{}{
|
|
"name": name,
|
|
"tagType": tagType,
|
|
}
|
|
|
|
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func GetTagNode(ctx context.Context, driver neo4j.DriverWithContext, name string) (models.DBTag, bool, error) {
|
|
|
|
var tag models.DBTag
|
|
|
|
query := `
|
|
MATCH (u:e621Tag {e621Tag: $name})
|
|
RETURN u.e621Tag as e621Tag, u.e621TagType as e621TagType
|
|
`
|
|
|
|
params := map[string]interface{}{
|
|
"name": name,
|
|
}
|
|
|
|
result, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
|
|
if err != nil {
|
|
return tag, false, err
|
|
}
|
|
|
|
if len(result.Records) > 0 {
|
|
record := result.Records[0]
|
|
|
|
e621Tag, _, _ := neo4j.GetRecordValue[string](record, "e621Tag")
|
|
e621TagType, _, _ := neo4j.GetRecordValue[string](record, "e621TagType")
|
|
|
|
tag = models.DBTag{
|
|
Tag: e621Tag,
|
|
TagType: e621TagType,
|
|
}
|
|
if e621Tag != name {
|
|
return tag, false, nil
|
|
}
|
|
return tag, true, nil
|
|
}
|
|
return tag, false, err
|
|
}
|