Compare commits

...

3 Commits

Author SHA1 Message Date
0d5274eb27 feat: connecting to postgres now possible
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 21:31:44 +02:00
ccc6010466 chore: streamline the naming to indicate more than graph support
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 19:32:25 +02:00
5015749f70 chore: streamline the naming to indicate more than graph support
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-03 19:31:25 +02:00
12 changed files with 251 additions and 88 deletions

View File

@ -17,20 +17,20 @@ Here's a simple usage example:
package main
import (
"context"
"fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/pkg/graph"
"context"
"fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/pkg/database"
)
func main() {
client := graph.NewGraphConnection()
err := client.Connect(context.Background(), "your-endpoint", "your-username", "your-password")
if err != nil {
fmt.Println(err)
return
}
// further usage of the client...
client := graph.NewGraphConnection()
err := client.Connect(context.Background(), "your-endpoint", "your-username", "your-password")
if err != nil {
fmt.Println(err)
return
}
// further usage of the client...
}
```

13
go.mod
View File

@ -5,6 +5,17 @@ go 1.22.0
require (
github.com/neo4j/neo4j-go-driver/v5 v5.17.0
github.com/sirupsen/logrus v1.9.3
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.10
)
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
)

28
go.sum
View File

@ -1,6 +1,16 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/neo4j/neo4j-go-driver/v5 v5.17.0 h1:Bdqg1Y8Hd3uLYToXtBjysDYXTdMiP7zeUNUEwfbJkSo=
github.com/neo4j/neo4j-go-driver/v5 v5.17.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -8,10 +18,22 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"fmt"
@ -19,21 +19,21 @@ func (n graphLogger) Error(name string, id string, err error) {
log.WithFields(log.Fields{
"name": name,
"id": id,
}).Errorf("graph: %s", err)
}).Errorf("database: %s", err)
}
func (n graphLogger) Warnf(name string, id string, msg string, args ...any) {
log.WithFields(log.Fields{
"name": name,
"id": id,
}).Warnf("graph: %v", fmt.Sprintf(msg, args...))
}).Warnf("database: %v", fmt.Sprintf(msg, args...))
}
func (n graphLogger) Infof(name string, id string, msg string, args ...any) {
log.WithFields(log.Fields{
"name": name,
"id": id,
}).Infof("graph: %v", fmt.Sprintf(msg, args...))
}).Infof("database: %v", fmt.Sprintf(msg, args...))
}
func (n graphLogger) Debugf(name string, id string, msg string, args ...any) {
@ -41,6 +41,6 @@ func (n graphLogger) Debugf(name string, id string, msg string, args ...any) {
log.WithFields(log.Fields{
"name": name,
"id": id,
}).Debugf("graph: %v", fmt.Sprintf(msg, args...))
}).Debugf("database: %v", fmt.Sprintf(msg, args...))
}
}

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"context"
@ -26,7 +26,7 @@ func CreateAnthrovePostNode(ctx context.Context, driver neo4j.DriverWithContext,
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePost.PostID,
"anthrove_post_rating": anthrovePost.Rating,
}).Trace("graph: created anthrove post")
}).Trace("database: created anthrove post")
return nil
}
@ -106,7 +106,7 @@ func executeCheckQuery(ctx context.Context, driver neo4j.DriverWithContext, quer
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePost.PostID,
"anthrove_post_exists": exists,
}).Trace("graph: checked if post exists")
}).Trace("database: checked if post exists")
if !exists {
return nil, exists, nil

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"context"
@ -33,7 +33,7 @@ func EstablishAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverW
"anthrove_post_id": anthrovePostID,
"source_post_url": anthrovePostRelationship.Url,
"source_post_id": anthrovePostRelationship.PostID,
}).Trace("graph: creating anthrove post to source link")
}).Trace("database: creating anthrove post to source link")
return nil
}
@ -59,7 +59,7 @@ func EstablishUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext
log.WithFields(log.Fields{
"anthrove_post_id": anthrovePost.PostID,
"anthrove_user_id": anthroveUser.UserID,
}).Trace("graph: created user to post link")
}).Trace("database: created user to post link")
return nil
}
@ -94,7 +94,7 @@ func CheckUserToPostLink(ctx context.Context, driver neo4j.DriverWithContext, an
"relationship_exists": exists,
"relationship_anthrove_user_id": anthroveUserID,
"relationship_e621_post_id": "",
}).Trace("graph: checked user post relationship")
}).Trace("database: checked user post relationship")
return exists, nil
}

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"context"
@ -22,14 +22,14 @@ func CreateSourceNode(ctx context.Context, driver neo4j.DriverWithContext, anthr
_, err := neo4j.ExecuteQuery(ctx, driver, query, params, neo4j.EagerResultTransformer)
if err != nil {
return fmt.Errorf("graph: %w", err)
return fmt.Errorf("database: %w", err)
}
log.WithFields(log.Fields{
"node_source_url": anthroveSource.Domain,
"node_source_displayName": anthroveSource.DisplayName,
"node_source_icon": anthroveSource.Icon,
}).Trace("graph: created source node")
}).Trace("database: created source node")
return nil
}
@ -70,7 +70,7 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
log.WithFields(log.Fields{
"tag_amount": len(sources),
}).Trace("graph: created tag node")
}).Trace("database: created tag node")
return sources, nil
}
@ -107,7 +107,7 @@ func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, so
log.WithFields(log.Fields{
"source_url": sourceUrl,
}).Trace("graph: got source node")
}).Trace("database: got source node")
return &source, nil
}

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"context"
@ -29,7 +29,7 @@ func CreateTagNodeWitRelation(ctx context.Context, driver neo4j.DriverWithContex
"anthrove_post_id": anthrovePostID,
"tag_name": anthroveTag.Name,
"tag_type": anthroveTag.Type,
}).Trace("graph: created tag node")
}).Trace("database: created tag node")
return nil
}
@ -78,7 +78,7 @@ func GetTags(ctx context.Context, driver neo4j.DriverWithContext) ([]models.Tags
log.WithFields(log.Fields{
"tag_amount": len(userTags),
}).Trace("graph: created tag node")
}).Trace("database: created tag node")
return userTags, nil
}

View File

@ -1,4 +1,4 @@
package internal
package graph
import (
"context"
@ -46,7 +46,7 @@ func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWi
"source_user_id": userID,
"source_user_name": username,
"source_domain": sourceDomain,
}).Trace("graph: crated user with relationship")
}).Trace("database: crated user with relationship")
return nil
}
@ -85,7 +85,7 @@ func GetUserFavoritesCount(ctx context.Context, driver neo4j.DriverWithContext,
log.WithFields(log.Fields{
"anthrove_user_id": anthroveUserID,
"anthrove_user_fav_count": userFavoriteCount,
}).Trace("graph: got user favorite count")
}).Trace("database: got user favorite count")
return userFavoriteCount, nil
}
@ -145,7 +145,7 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
log.WithFields(log.Fields{
"anthrove_user_id": anthroveUserID,
"anthrove_data": userSource,
}).Trace("graph: got user favorite count")
}).Trace("database: got user favorite count")
return userSource, nil
}
@ -206,7 +206,7 @@ func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithCont
log.WithFields(log.Fields{
"anthrove_user_id": anthroveUserID,
"anthrove_data": userSource,
}).Trace("graph: got user favorite count")
}).Trace("database: got user favorite count")
return userSource, nil
}
@ -273,7 +273,7 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro
log.WithFields(log.Fields{
"anthrove_user_id": anthroveUserID,
}).Trace("graph: got anthrove user")
}).Trace("database: got anthrove user")
return &anthroveUser, nil
@ -310,7 +310,7 @@ func GetAllAnthroveUserIDs(ctx context.Context, driver neo4j.DriverWithContext)
log.WithFields(log.Fields{
"anthrove_user_id_count": len(anthroveUsers),
}).Trace("graph: got al anthrove user IDs")
}).Trace("database: got al anthrove user IDs")
return anthroveUsers, nil
@ -396,7 +396,7 @@ func GetUserFavoriteNodeWithPagination(ctx context.Context, driver neo4j.DriverW
log.WithFields(log.Fields{
"anthrove_user_fav_count": len(favoritePosts),
}).Trace("graph: got al anthrove user favorites")
}).Trace("database: got al anthrove user favorites")
return &models.FavoriteList{Posts: favoritePosts}, nil
@ -448,7 +448,7 @@ func GetUserTagNodeWitRelationToFavedPosts(ctx context.Context, driver neo4j.Dri
log.WithFields(log.Fields{
"tag_amount": len(userTags),
}).Trace("graph: created tag node")
}).Trace("database: created tag node")
return userTags, nil
}

View File

@ -1,4 +1,4 @@
// Package graph provides a client for using the OtterSpace API.
// Package database provides a client for using the OtterSpace API.
//
// This package provides a client to interact with the OtterSpace API. It includes
// methods for all API endpoints, and convenience methods for common tasks.
@ -11,11 +11,11 @@
// "context"
// "fmt"
// "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
// "git.dragse.it/anthrove/otter-space-sdk/pkg/graph"
// "git.dragse.it/anthrove/otter-space-sdk/pkg/database"
// )
//
// func main() {
// client := graph.NewGraphConnection()
// client := database.NewGraphConnection()
// err := client.Connect(context.Background(), "your-endpoint", "your-username", "your-password")
// if err != nil {
// fmt.Println(err)
@ -23,7 +23,7 @@
// }
// // further usage of the client...
// }
package graph
package database
import (
"context"
@ -37,65 +37,65 @@ import (
type OtterSpace interface {
// Connect sets up a connection to the OtterSpace API endpoint using the provided username and password.
// It returns an error if the connection cannot be established.
Connect(ctx context.Context, endpoint string, username string, password string) error
Connect(ctx context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error
// AddUserWithRelationToSource adds a new user to the OtterSpace graph and associates them with a source.
// AddUserWithRelationToSource adds a new user to the OtterSpace database and associates them with a source.
// It returns the newly created user and an error if the operation fails.
AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error
// AddSource adds a new source to the OtterSpace graph.
// AddSource adds a new source to the OtterSpace database.
// It returns an error if the operation fails.
AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
// AddPost adds a new post to the OtterSpace graph.
// AddPost adds a new post to the OtterSpace database.
// It returns an error if the operation fails.
AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error
// AddTagWithRelationToPost adds a new tag to the OtterSpace graph and associates it with a post.
// AddTagWithRelationToPost adds a new tag to the OtterSpace database and associates it with a post.
// It returns an error if the operation fails.
AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace database.
// It returns an error if the operation fails.
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error
// LinkUserWithPost establishes a link between a user and a post in the OtterSpace graph.
// LinkUserWithPost establishes a link between a user and a post in the OtterSpace database.
// It returns an error if the operation fails.
LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error
// CheckUserPostLink checks if a link between a user and a post exists in the OtterSpace graph.
// CheckUserPostLink checks if a link between a user and a post exists in the OtterSpace database.
// It returns true if the link exists, false otherwise, and an error if the operation fails.
CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error)
// CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace graph by its Anthrove ID.
// CheckPostNodeExistsByAnthroveID checks if a post node exists in the OtterSpace database by its Anthrove ID.
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error)
// CheckPostNodeExistsBySourceURL checks if a post node exists in the OtterSpace graph by its source URL.
// CheckPostNodeExistsBySourceURL checks if a post node exists in the OtterSpace database by its source URL.
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error)
// CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace graph by its source ID.
// CheckPostNodeExistsBySourceID checks if a post node exists in the OtterSpace database by its source ID.
// It returns the post if it exists, a boolean indicating whether the post was found, and an error if the operation fails.
CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error)
// GetUserFavoriteCount retrieves the count of a user's favorite posts from the OtterSpace graph.
// GetUserFavoriteCount retrieves the count of a user's favorite posts from the OtterSpace database.
// It returns the count and an error if the operation fails.
GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error)
// GetUserSourceLinks retrieves the links between a user and sources in the OtterSpace graph.
// GetUserSourceLinks retrieves the links between a user and sources in the OtterSpace database.
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error)
// GetSpecifiedUserSourceLink GetUserSourceLinks retrieves the links between a user and a specific source in the OtterSpace graph.
// GetSpecifiedUserSourceLink GetUserSourceLinks retrieves the links between a user and a specific source in the OtterSpace database.
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error)
// GetAnthroveUser retrieves a user from the OtterSpace graph by their ID.
// GetAnthroveUser retrieves a user from the OtterSpace database by their ID.
// It returns the user and an error if the operation fails.
GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error)
// GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace graph.
// GetAllAnthroveUserIDs retrieves all user IDs from the OtterSpace database.
// It returns a slice of user IDs and an error if the operation fails.
GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error)

View File

@ -1,9 +1,9 @@
package graph
package database
import (
"context"
"git.dragse.it/anthrove/otter-space-sdk/internal/graph"
"git.dragse.it/anthrove/otter-space-sdk/internal"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
@ -21,7 +21,7 @@ func NewGraphConnection(graphDebug bool) OtterSpace {
}
}
func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error {
func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string, _ string, _ int, _ string, _ string) error {
driver, err := neo4j.NewDriverWithContext(endpoint, neo4j.BasicAuth(username, password, ""),
logger(g.graphDebug))
@ -37,87 +37,87 @@ func (g *graphConnection) Connect(ctx context.Context, endpoint string, username
}
func (g *graphConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
return graph.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
}
func (g *graphConnection) AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
return internal.CreateSourceNode(ctx, g.driver, anthroveSource)
return graph.CreateSourceNode(ctx, g.driver, anthroveSource)
}
func (g *graphConnection) AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
return graph.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
}
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
return graph.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
}
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
return internal.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
return graph.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
}
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
return graph.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
}
func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
return graph.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
}
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
return internal.CheckIfAnthrovePostNodeExistsByAnthroveID(ctx, g.driver, anthrovePost)
return graph.CheckIfAnthrovePostNodeExistsByAnthroveID(ctx, g.driver, anthrovePost)
}
func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) {
return internal.CheckIfAnthrovePostNodeExistsBySourceURl(ctx, g.driver, sourceUrl)
return graph.CheckIfAnthrovePostNodeExistsBySourceURl(ctx, g.driver, sourceUrl)
}
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
return internal.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID)
return graph.CheckIfAnthrovePostNodeExistsBySourceID(ctx, g.driver, sourcePostID)
}
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
return internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
return graph.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
}
func (g *graphConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID)
return graph.GetUserSourceLink(ctx, g.driver, anthroveUserID)
}
func (g *graphConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
return graph.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
}
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID)
return graph.GetAnthroveUser(ctx, g.driver, anthroveUserID)
}
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
return internal.GetAllAnthroveUserIDs(ctx, g.driver)
return graph.GetAllAnthroveUserIDs(ctx, g.driver)
}
func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) {
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
return graph.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
}
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
return graph.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
}
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
return internal.GetTags(ctx, g.driver)
return graph.GetTags(ctx, g.driver)
}
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
return internal.GetAllSourceNodes(ctx, g.driver)
return graph.GetAllSourceNodes(ctx, g.driver)
}
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
return internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
return graph.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
}
func logger(graphDebug bool) func(config *config.Config) {
return func(config *config.Config) {
config.Log = internal.NewGraphLogger(graphDebug)
config.Log = graph.NewGraphLogger(graphDebug)
}
}

View File

@ -0,0 +1,130 @@
package database
import (
"context"
"fmt"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type postgresqlConnection struct {
db *gorm.DB
}
func NewPostgresqlConnection() OtterSpace {
return &postgresqlConnection{
db: nil,
}
}
func (p postgresqlConnection) Connect(ctx context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error {
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", endpoint, username, password, database, port, ssl, timezone)
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
p.db = db
if err != nil {
return err
}
return nil
}
func (p postgresqlConnection) AddUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) AddSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) AddPost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetSpecifiedUserSourceLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
//TODO implement me
panic("implement me")
}
func (p postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
//TODO implement me
panic("implement me")
}