54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"app-cloudep-tweeting-service/internal/config"
|
|
"app-cloudep-tweeting-service/internal/domain/repository"
|
|
client4J "app-cloudep-tweeting-service/internal/lib/neo4j"
|
|
"context"
|
|
"fmt"
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
n4 "github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
|
)
|
|
|
|
type SocialNetworkParam struct {
|
|
Config config.Config
|
|
Neo4jClient *client4J.Client
|
|
}
|
|
|
|
type SocialNetworkRepository struct {
|
|
cfg config.Config
|
|
neo4jClient *client4J.Client
|
|
}
|
|
|
|
func MustSocialNetworkRepository(param SocialNetworkParam) repository.SocialNetworkRepository {
|
|
return &SocialNetworkRepository{
|
|
cfg: param.Config,
|
|
neo4jClient: param.Neo4jClient,
|
|
}
|
|
}
|
|
|
|
func (s SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error {
|
|
// 執行 Cypher
|
|
conn, err := s.neo4jClient.Conn()
|
|
if err != nil {
|
|
return ers.DBError("failed to connect to node4j", err.Error())
|
|
}
|
|
|
|
insert := map[string]any{
|
|
"uid": uid,
|
|
}
|
|
|
|
result, err := conn.NewSession(ctx, n4.SessionConfig{
|
|
AccessMode: n4.AccessModeWrite,
|
|
}).Run(ctx, "CREATE (n:Person {name: $name}) RETURN n", insert)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(result.Keys())
|
|
|
|
return nil
|
|
|
|
}
|