dataservice

package
v0.0.0-...-760f05f Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Shutdown(context.Context)
	GetEvents(queryParams url.Values) (*model.Events, error)
	GetEvent(id primitive.ObjectID) (*model.Event, error)
	AddEvent(event *model.Event) error
	UpdateEvent(id primitive.ObjectID, event *model.Event) error
	DeleteEvent(id primitive.ObjectID) error
}

Database is an interface representing data base service with all CRUD operations

func NewDatabase

func NewDatabase(config *utils.Config) (Database, error)

NewDatabase is a factory method for creating database service according to configuration

type Filters

type Filters struct {
	// contains filtered or unexported fields
}

Filters is a struct containing all settings for filtering DB data

func NewFilters

func NewFilters(config *utils.ConfigServer) *Filters

NewFilters is a factory method for creating Filters structure

func (Filters) GetAvailable

func (filters Filters) GetAvailable() []string

GetAvailable returns list of available filter names

func (Filters) GetFilters

func (filters Filters) GetFilters(queryParams url.Values) (interface{}, error)

GetFilters is used to update bson interface to filter MongoDB results

func (Filters) GetOptions

func (filters Filters) GetOptions(queryParams url.Values) (*options.FindOptions, error)

GetOptions is used to specify find request MongoDB options

type InMemory

type InMemory struct {
	// contains filtered or unexported fields
}

InMemory is a test data base service with elements stored in RAM

func NewInMemory

func NewInMemory(filters *Filters) (*InMemory, error)

NewInMemory is a factory method to create an in memory data base service

func (*InMemory) AddEvent

func (memory *InMemory) AddEvent(event *model.Event) error

AddEvent adds passed event item to DB

func (*InMemory) DeleteEvent

func (memory *InMemory) DeleteEvent(id primitive.ObjectID) error

DeleteEvent deletes a event with specified ID from the database

func (*InMemory) GetEvent

func (memory *InMemory) GetEvent(id primitive.ObjectID) (*model.Event, error)

GetEvent returns event with specified ID (or error if not found)

func (*InMemory) GetEvents

func (memory *InMemory) GetEvents(queryParams url.Values) (*model.Events, error)

GetEvents returns all events stored in DB

func (*InMemory) Shutdown

func (memory *InMemory) Shutdown(ctx context.Context)

Shutdown clears internal events list

func (*InMemory) UpdateEvent

func (memory *InMemory) UpdateEvent(id primitive.ObjectID, event *model.Event) error

UpdateEvent updates an event with specified ID

type MongoDB

type MongoDB struct {
	// contains filtered or unexported fields
}

MongoDB is a data base service with elements are stored with use of MongoDB

func NewMongoDB

func NewMongoDB(config *utils.ConfigMongo, filters *Filters) (*MongoDB, error)

NewMongoDB is a factory method to create a Mongo DB service

func (MongoDB) AddEvent

func (mongo MongoDB) AddEvent(event *model.Event) error

AddEvent adds passed event item to DB

func (MongoDB) DeleteEvent

func (mongo MongoDB) DeleteEvent(id primitive.ObjectID) error

DeleteEvent deletes a event with specified ID from the database

func (MongoDB) GetEvent

func (mongo MongoDB) GetEvent(id primitive.ObjectID) (*model.Event, error)

GetEvent returns event with specified ID (or error if not found)

func (MongoDB) GetEvents

func (mongo MongoDB) GetEvents(queryParams url.Values) (*model.Events, error)

GetEvents returns all events stored in DB

func (MongoDB) Shutdown

func (mongo MongoDB) Shutdown(ctx context.Context)

Shutdown closes active database connection

func (MongoDB) UpdateEvent

func (mongo MongoDB) UpdateEvent(id primitive.ObjectID, event *model.Event) error

UpdateEvent updates an event with specified ID

Jump to

Keyboard shortcuts

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