From ebc7fcc571f0d1b629089a8884931ce309cafa53 Mon Sep 17 00:00:00 2001 From: SoXX Date: Mon, 3 Jun 2024 22:14:50 +0200 Subject: [PATCH] feat(sources): get all source nodes Signed-off-by: SoXX --- internal/postgres/source.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 internal/postgres/source.go diff --git a/internal/postgres/source.go b/internal/postgres/source.go new file mode 100644 index 0000000..6871f45 --- /dev/null +++ b/internal/postgres/source.go @@ -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 +}