database

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 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
	Drop(table string) error
	Aggregate(table string, pipeline []map[string]interface{}) ([]map[string]interface{}, error)
	MonitorConnection(heartbeat time.Duration, health HealthCheckInterface)
}

type DatabaseUpdateActions

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

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) 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) 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) 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) 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