Compare commits
3 Commits
0d5274eb27
...
ea2958b27d
Author | SHA1 | Date | |
---|---|---|---|
ea2958b27d | |||
ebc7fcc571 | |||
c1df01d113 |
25
internal/postgres/source.go
Normal file
25
internal/postgres/source.go
Normal file
@ -0,0 +1,25 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// GetAllSourceNodes returns a list of all models.AnthroveSource
|
||||
func GetAllSourceNodes(ctx context.Context, db *gorm.DB) ([]models.AnthroveSource, error) {
|
||||
var sources []models.AnthroveSource
|
||||
|
||||
result := db.WithContext(ctx).Find(&sources)
|
||||
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tag_amount": result.RowsAffected,
|
||||
}).Trace("database: get all source nodes")
|
||||
|
||||
return sources, nil
|
||||
}
|
@ -3,7 +3,6 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/internal/graph"
|
||||
|
||||
"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"
|
@ -3,8 +3,9 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/internal/postgres"
|
||||
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
|
||||
"gorm.io/driver/postgres"
|
||||
gormPostgres "gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -21,7 +22,7 @@ func NewPostgresqlConnection() OtterSpace {
|
||||
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{})
|
||||
db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
||||
p.db = db
|
||||
if err != nil {
|
||||
return err
|
||||
@ -120,8 +121,7 @@ func (p postgresqlConnection) GetAllTags(ctx context.Context) ([]models.TagsWith
|
||||
}
|
||||
|
||||
func (p postgresqlConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return postgres.GetAllSourceNodes(ctx, p.db)
|
||||
}
|
||||
|
||||
func (p postgresqlConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
|
Reference in New Issue
Block a user