db

package
v0.0.0-...-f6a86e4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	//DefaultDb is the database set for the microservice
	DefaultDb Database
	//DBTypes is a map of DB interfaces that can be used for this service
	DBTypes = map[string]Database{}
	//ErrNoDatabaseFound error returnes when database interface does not exists in DBTypes
	ErrNoDatabaseFound = "No database with name %v registered"
	//ErrNoDatabaseSelected is returned when no database was designated in the flag or env
	ErrNoDatabaseSelected = errors.New("No DB selected")
)

Functions

func CreateAddress

func CreateAddress(a *users.Address, userid string) error

CreateAddress invokes DefaultDb method

func CreateCard

func CreateCard(c *users.Card, userid string) error

CreateCard invokes DefaultDb method

func CreateUser

func CreateUser(u *users.User) error

CreateUser invokes DefaultDb method

func Delete

func Delete(entity, id string) error

Delete invokes DefaultDb method

func GetAddress

func GetAddress(n string) (users.Address, error)

GetAddress invokes DefaultDb method

func GetAddresses

func GetAddresses() ([]users.Address, error)

GetAddresses invokes DefaultDb method

func GetCard

func GetCard(n string) (users.Card, error)

GetCard invokes DefaultDb method

func GetCards

func GetCards() ([]users.Card, error)

GetCards invokes DefaultDb method

func GetUser

func GetUser(n string) (users.User, error)

GetUser invokes DefaultDb method

func GetUserAttributes

func GetUserAttributes(u *users.User) error

GetUserAttributes invokes DefaultDb method

func GetUserByName

func GetUserByName(n string) (users.User, error)

GetUserByName invokes DefaultDb method

func GetUsers

func GetUsers() ([]users.User, error)

GetUsers invokes DefaultDb method

func Init

func Init() error

Init inits the selected DB in DefaultDb

func Ping

func Ping() error

Ping invokes DefaultDB method

func Register

func Register(name string, db Database)

Register registers the database interface in the DBTypes

func Set

func Set() error

Set the DefaultDb

Types

type Database

type Database interface {
	Init() error
	GetUserByName(string) (users.User, error)
	GetUser(string) (users.User, error)
	GetUsers() ([]users.User, error)
	CreateUser(*users.User) error
	GetUserAttributes(*users.User) error
	GetAddress(string) (users.Address, error)
	GetAddresses() ([]users.Address, error)
	CreateAddress(*users.Address, string) error
	GetCard(string) (users.Card, error)
	GetCards() ([]users.Card, error)
	Delete(string, string) error
	CreateCard(*users.Card, string) error
	Ping() error
}

Database represents a simple interface so we can switch to a new system easily this is just basic and specific to this microservice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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