This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/internal/source.go

36 lines
1.0 KiB
Go
Raw Normal View History

2024-02-16 14:54:36 +00:00
package internal
2024-02-16 15:00:14 +00:00
import (
"context"
"fmt"
2024-02-16 20:51:09 +00:00
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
2024-02-16 15:00:14 +00:00
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
log "github.com/sirupsen/logrus"
)
func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthroveSource *models.AnthroveSource) error {
query := `
MERGE (sourceNode:Source {domain: $source_url})
ON CREATE SET sourceNode.domain = $source_url, sourceNode.display_name = $source_display_name, sourceNode.icon = $source_icon
`
params := map[string]any{
"source_url": anthroveSource.Domain,
"source_display_name": anthroveSource.DisplayName,
"source_icon": anthroveSource.Icon,
}
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
if err != nil {
return fmt.Errorf("graph: %w", err)
}
log.WithFields(log.Fields{
"node_source_url": anthroveSource.Domain,
"node_source_displayName": anthroveSource.DisplayName,
"node_source_icon": anthroveSource.Icon,
2024-02-16 15:05:24 +00:00
}).Trace("graph: created source node")
2024-02-16 15:00:14 +00:00
return nil
}