db

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package db implements database interactions.

Package db implements database interactions.

Package db implements database interactions.

Index

Constants

View Source
const (

	// EnvDBTestURI holds test database URI. Needs to be in format: mongodb://user:password@address
	EnvDBTestURI = "DBTEST_ISTADIFF"
)

Variables

View Source
var ErrNoData = errors.New("no data in collection")

ErrNoData returned when no data found in collection.

Functions

func BuildCollectionName added in v1.2.0

func BuildCollectionName(s string) string

BuildCollectionName constructs collection name.

func SetUpMongoContainer added in v1.1.0

func SetUpMongoContainer(ctx context.Context, m *testing.M, tag string, p ContainerParams) func()

SetUpMongoContainer starts up mongoDB docker container and returns reset closure func, that should be run after m.Run().

Types

type ContainerParams added in v1.1.0

type ContainerParams struct {
	User          string
	UserPassword  string
	ExpireSeconds uint
}

ContainerParams holds mongo container parameters.

type DB

type DB interface {
	// InsertUsersBatch creates record in database with passed users batch.
	InsertUsersBatch(ctx context.Context, users models.UsersBatch) error
	// GetLastUsersBatchByType returns last created users batch by passed batch type.
	GetLastUsersBatchByType(ctx context.Context, batchType models.UsersBatchType) (models.UsersBatch, error)
	// GetAllUsersBatchByType returns all users batches by passed batch type.
	GetAllUsersBatchByType(ctx context.Context, batchType models.UsersBatchType) ([]models.UsersBatch, error)
	// Close closes connections.
	Close(ctx context.Context) error
}

DB represents database interaction contract.

func Connect

func Connect(ctx context.Context, params Params) (DB, error)

Connect returns specific database connection. MongoDB if mongo is enabled. LocalMemory in other case.

func ConnectForTesting added in v1.1.0

func ConnectForTesting(tb testing.TB, dbname, collection string) DB

ConnectForTesting returns a connection to a newly created database Test cleanup automatically drops the database and closes underlying connections.

type MongoParams

type MongoParams struct {
	URL        string
	Database   string
	Collection string
}

MongoParams represents mongo db configuration parameters.

type Params

type Params struct {
	LocalDB     bool
	MongoParams MongoParams
}

Params used for DB constructor.

Jump to

Keyboard shortcuts

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