database

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: LGPL-3.0 Imports: 9 Imported by: 0

README

What does this directory DO?

This package provides basic database handlers for a testing mock database (PLEASE don't use in prod!) and a MongoDB handler. The database.go file also defines DatabaseAccessor which can be extended upon for custom implementations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseAccessor

type DatabaseAccessor interface {
	InsertOne(table string, body map[string]interface{}) (interface{}, error)
	UpdateOne(table string, query map[string]interface{}, body map[DatabaseUpdateActions]map[string]interface{}) (interface{}, error)
	FindOne(table string, query map[string]interface{}) (interface{}, bool)
	Find(table string, query map[string]interface{}) ([]interface{}, bool)
	FindPaginated(table string, query map[string]interface{}, maxPages int64, lastID string) ([]map[string]interface{}, bool)
	DeleteOne(table string, query map[string]interface{}) (bool, error)
	CreateTextIndex(table string, keys []string) error
	CreateRegularIndex(table string, keys map[string]Direction, unique bool) error
	Drop(table string) error
	Aggregate(table string, pipeline []map[string]interface{}) ([]map[string]interface{}, error)
	GetUTCTimestampFromID(dbID primitive.ObjectID) (time.Time, error)
	MonitorConnection(heartbeat time.Duration, health HealthCheckInterface)
}

type DatabaseUpdateActions

type DatabaseUpdateActions string
const (
	SET  DatabaseUpdateActions = "set"
	PUSH DatabaseUpdateActions = "push"
)

type Direction added in v0.6.0

type Direction int

Direction type to specify the index direction

const (
	Ascending  Direction = 1  // Ascending order
	Descending Direction = -1 // Descending order
)

type HealthCheckInterface added in v0.4.1

type HealthCheckInterface interface {
	SetMongoDown()
	SetMongoUp()
	IsMongoUp() bool
}

type MongoDatabase

type MongoDatabase struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func (MongoDatabase) Aggregate added in v0.4.0

func (db MongoDatabase) Aggregate(table string, pipeline []map[string]interface{}) ([]map[string]interface{}, error)

func (MongoDatabase) Count added in v0.3.8

func (db MongoDatabase) Count(table string, filter map[string]interface{}) (int64, error)

func (MongoDatabase) CreateRegularIndex added in v0.6.0

func (db MongoDatabase) CreateRegularIndex(table string, keys map[string]Direction, unique bool) error

func (MongoDatabase) CreateTextIndex added in v0.3.8

func (db MongoDatabase) CreateTextIndex(table string, keys []string) error

func (MongoDatabase) DeleteOne

func (db MongoDatabase) DeleteOne(table string, query map[string]interface{}) (bool, error)

func (MongoDatabase) Drop added in v0.2.3

func (db MongoDatabase) Drop(table string) error

func (MongoDatabase) Find

func (db MongoDatabase) Find(table string, query map[string]interface{}) ([]interface{}, bool)

func (MongoDatabase) FindOne

func (db MongoDatabase) FindOne(table string, query map[string]interface{}) (interface{}, bool)

func (MongoDatabase) FindPaginated added in v0.3.8

func (db MongoDatabase) FindPaginated(table string, query map[string]interface{}, maxPages int64, lastID string) ([]map[string]interface{}, bool)

func (MongoDatabase) GetUTCTimestampFromID added in v0.6.2

func (db MongoDatabase) GetUTCTimestampFromID(dbID primitive.ObjectID) (time.Time, error)

func (*MongoDatabase) Initialize

func (db *MongoDatabase) Initialize(uri string, database string) error

func (MongoDatabase) InsertOne

func (db MongoDatabase) InsertOne(table string, body map[string]interface{}) (interface{}, error)

func (MongoDatabase) MonitorConnection added in v0.4.1

func (db MongoDatabase) MonitorConnection(heartbeat time.Duration, health HealthCheckInterface)

func (MongoDatabase) UpdateOne

func (db MongoDatabase) UpdateOne(table string, query map[string]interface{}, body map[DatabaseUpdateActions]map[string]interface{}) (interface{}, error)

type TestDatabase

type TestDatabase struct {
	Tables map[string]map[string]interface{}
}

func (TestDatabase) Aggregate added in v0.4.0

func (db TestDatabase) Aggregate(table string, pipeline []map[string]interface{}) ([]map[string]interface{}, error)

func (TestDatabase) CreateRegularIndex added in v0.6.0

func (db TestDatabase) CreateRegularIndex(table string, keys map[string]Direction, unique bool) error

func (TestDatabase) CreateTextIndex added in v0.3.8

func (db TestDatabase) CreateTextIndex(table string, keys []string) error

func (TestDatabase) DeleteOne

func (db TestDatabase) DeleteOne(table string, query map[string]interface{}) (bool, error)

func (TestDatabase) Drop added in v0.2.3

func (db TestDatabase) Drop(table string) error

func (TestDatabase) Find

func (db TestDatabase) Find(table string, query map[string]interface{}) ([]interface{}, bool)

func (TestDatabase) FindOne

func (db TestDatabase) FindOne(table string, query map[string]interface{}) (interface{}, bool)

func (TestDatabase) FindPaginated added in v0.3.8

func (db TestDatabase) FindPaginated(table string, query map[string]interface{}, maxPages int64, lastID string) ([]map[string]interface{}, bool)

func (TestDatabase) GetUTCTimestampFromID added in v0.6.2

func (db TestDatabase) GetUTCTimestampFromID(dbID primitive.ObjectID) (time.Time, error)

func (TestDatabase) InsertOne

func (db TestDatabase) InsertOne(table string, body map[string]interface{}) (interface{}, error)

func (TestDatabase) MonitorConnection added in v0.4.1

func (db TestDatabase) MonitorConnection(heartbeat time.Duration, health HealthCheckInterface)

func (TestDatabase) UpdateOne

func (db TestDatabase) UpdateOne(table string, query map[string]interface{}, body map[DatabaseUpdateActions]map[string]interface{}) (interface{}, error)

Jump to

Keyboard shortcuts

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