infrastructure

package
v3.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectMongoDB

func ConnectMongoDB(ctx context.Context, dsn string) (*mongo.Database, error)

ConnectMongoDB opens a connection to the MongoDB and ensures that the db is reachable

func ConnectPostgresDB

func ConnectPostgresDB(ctx context.Context, dsn string) (*sql.DB, error)

ConnectPostgresDB opens a connection to the PostgresDB and ensures that the db is reachable

func MigratePostgresDB added in v3.6.0

func MigratePostgresDB(db *sql.DB, migrationsDir string) error

MigratePostgresDB runs all migrations found in the given directory against the db

Types

type MongoRepository

type MongoRepository struct {
	DB         *mongo.Database
	Collection *mongo.Collection
	Target     interface{}
}

MongoRepository struct of a mongo repository Implements the Repository interface

func (*MongoRepository) Create

func (r *MongoRepository) Create(ctx context.Context, entity interface{}) (string, error)

Create creates an entity in the repository's collection

func (*MongoRepository) Delete

func (r *MongoRepository) Delete(ctx context.Context, ID string) error

Delete deletes the document with the specified ID in the repository's collection

func (*MongoRepository) Get

func (r *MongoRepository) Get(ctx context.Context, filter map[string]interface{}, skip, take *int) ([]interface{}, error)

Get gets the documents mathing the filter in the repository's collection

func (*MongoRepository) GetByID

func (r *MongoRepository) GetByID(ctx context.Context, ID string) (interface{}, error)

GetByID get the document with the specified ID in the repository's collection

func (*MongoRepository) Update

func (r *MongoRepository) Update(ctx context.Context, ID string, entity interface{}) error

Update updates the document with the specified ID in the repository's collection

type PostgresRepository

type PostgresRepository struct {
	DB *sql.DB
}

PostgresRepository struct of a mongo repository Needs a specific implementation of the Repository interface for every entity

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL