db

package
v0.0.0-...-95a4c08 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefConnectionTimeOut = 10 * time.Second
	DefDatabase          = "ecommerce"
)
View Source
const (
	OrdersCollection = "purchaseOrders"
	DefaultPageSize  = 100
)
View Source
const DefaultMongoDBSidecar string = "/secrets/db.json"

Variables

View Source
var (
	ErrInvalidConnURL      = errors.New("failed to connect to DB:as the connection string is invalid")
	ErrConnectionEstablish = errors.New("failed to establish connection to DB")
	ErrClientInit          = errors.New("failed to initialize db client")
	ErrConnectionLeak      = errors.New("unable to disconnect from DB, connection leak")
	ErrPingDB              = errors.New("failed to ping DB")
)
View Source
var (
	ErrSideCarFileFormat = errors.New("mongo side car file is in invalid format")
	ErrSideCarFileRead   = errors.New("failed to read mongo side car file")
)
View Source
var (
	ErrInvalidInitialization = errors.New("invalid initialization")
	ErrInvalidPOIDCreate     = errors.New("order id should be empty")
	ErrInvalidPOIDUpdate     = errors.New("invalid order id")
	ErrUnexpectedUpdateOrder = errors.New("unexpected error occurred while updating order")
	ErrPOIDNotFound          = errors.New("purchase order doesn't exist with given id")
	ErrFailedToCreateOrder   = errors.New("faild to create order")
	ErrUnexpectedDeleteOrder = errors.New("unexpected error occurred while deleting orfer")
)

Functions

func MaskedMongoConnectionURL

func MaskedMongoConnectionURL(mc *MongoDBCredentials) string

func MongoConnectionURL

func MongoConnectionURL(mc *MongoDBCredentials) string

Types

type ConnectionManager

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

func (*ConnectionManager) Database

func (c *ConnectionManager) Database() MongoDatabase

func (*ConnectionManager) Disconnect

func (c *ConnectionManager) Disconnect() error

func (*ConnectionManager) NewClient

func (c *ConnectionManager) NewClient(connOpts *ConnectionOpts) (*mongo.Client, error)

func (*ConnectionManager) Ping

func (c *ConnectionManager) Ping() error

type ConnectionOpts

type ConnectionOpts struct {
	ConnectionTimeout time.Duration
	PrintQueries      bool
	Database          string
}

func FillConnectionOpts

func FillConnectionOpts(opts *ConnectionOpts) *ConnectionOpts

type MongoDBCredentials

type MongoDBCredentials struct {
	User       string `json:"user"`
	Port       string `json:"port"`
	HostName   string `json:"hostname"`
	ReplicaSet string `json:"replicaset"`
	Password   string `json:"password"`
}

func MongoDBCredentialFromSideCar

func MongoDBCredentialFromSideCar(sideCarFile string) (*MongoDBCredentials, error)

type MongoDatabase

type MongoDatabase interface {
	Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection
}

type MongoManager

type MongoManager interface {
	Database() MongoDatabase
	Ping() error
	Disconnect() error
}

type OrdersDataService

type OrdersDataService interface {
	Create(ctx context.Context, purchaseOrder *data.Order) (string, error)
	Update(ctx context.Context, purchaseOrder *data.Order) error
	GetAll(ctx context.Context, limit int64) (*[]data.Order, error)
	GetByID(ctx context.Context, id primitive.ObjectID) (*data.Order, error)
	DeleteByID(ctx context.Context, id primitive.ObjectID) error
}

type OrdersRepo

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

func NewOrderRepo

func NewOrderRepo(db MongoDatabase, lgr *logger.AppLogger) *OrdersRepo

func (*OrdersRepo) Create

func (o *OrdersRepo) Create(ctx context.Context, po *data.Order) (string, error)

func (*OrdersRepo) DeleteByID

func (o *OrdersRepo) DeleteByID(ctx context.Context, id primitive.ObjectID) error

func (*OrdersRepo) GetAll

func (o *OrdersRepo) GetAll(ctx context.Context, limit int64) (*[]data.Order, error)

func (*OrdersRepo) GetByID

func (o *OrdersRepo) GetByID(ctx context.Context, oID primitive.ObjectID) (*data.Order, error)

func (*OrdersRepo) Update

func (o *OrdersRepo) Update(ctx context.Context, po *data.Order) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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