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.
e621-sdk-go/database/dgraph/impl.go
2023-06-20 10:38:36 +02:00

80 lines
2.1 KiB
Go

package dgraph
import (
"context"
"e621_to_neo4j/database"
"e621_to_neo4j/e621/models"
"github.com/dgraph-io/dgo/v210"
"github.com/dgraph-io/dgo/v210/protos/api"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"log"
)
type dgraphConnection struct {
driver dgo.Dgraph
}
func (d *dgraphConnection) UploadUser(ctx context.Context, user models.E621User) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) UploadSource(ctx context.Context, SourceURL string) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) UploadPost(ctx context.Context, e621ID int64) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) UploadTag(ctx context.Context, name string, tagType string) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) EstablishPostTagLink(ctx context.Context, e621PostID int64, e621Tag string) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) EstablishPostToSourceLink(ctx context.Context, e621PostID int64, sourceURL string) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) EstablishUserToPostLink(ctx context.Context, e621PostID int64, e621UserID int64) error {
//TODO implement me
panic("implement me")
}
func (d *dgraphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error {
// Dial a gRPC connection. The address to dial to can be configured when
// setting up the dgraph cluster.
dialOpts := append([]grpc.DialOption{},
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))
conn, err := grpc.Dial(endpoint, dialOpts...)
if err != nil {
log.Fatal(err)
}
defer func(conn *grpc.ClientConn) {
err := conn.Close()
if err != nil {
return
}
}(conn)
d.driver = *dgo.NewDgraphClient(api.NewDgraphClient(conn))
return nil
}
func NewDGraphConnection() database.GraphConnection {
return &dgraphConnection{}
}