database

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DBName = "checkout"
View Source
const InMemoryDSN = ":memory:"

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	HealthChecker
	InventoryStore
	OrderStore
}

type GormDB

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

func NewGormDB

func NewGormDB(d gorm.Dialector, recreateSchema bool) (*GormDB, error)

func NewPostgresDB

func NewPostgresDB(host, user, password string, port int) (*GormDB, error)

NewPostgresDB returns a new GormDB with PostgreSQL engine.

func NewSQLiteDB

func NewSQLiteDB(databaseDSN string, recreateSchema bool) (*GormDB, error)

NewSQLiteDB returns a new GormDB with SQLite engine.

func (*GormDB) AddOrder

func (g *GormDB) AddOrder(ctx context.Context, o *model.Order) error

func (*GormDB) GetItemByName

func (g *GormDB) GetItemByName(ctx context.Context, name string) (*model.Item, error)

func (*GormDB) GetItemBySKU

func (g *GormDB) GetItemBySKU(ctx context.Context, sku string) (*model.Item, error)

func (*GormDB) GetItemsBySKU

func (g *GormDB) GetItemsBySKU(ctx context.Context, skus []string) ([]*model.Item, error)

func (*GormDB) GetOrders

func (g *GormDB) GetOrders(ctx context.Context) ([]*model.Order, error)

func (*GormDB) Ping

func (g *GormDB) Ping(ctx context.Context) error

func (*GormDB) UpsertItems

func (g *GormDB) UpsertItems(ctx context.Context, items []*model.Item) ([]*model.Item, error)

type HealthChecker

type HealthChecker interface {
	Ping(ctx context.Context) error
}

type InventoryStore

type InventoryStore interface {
	UpsertItems(ctx context.Context, items []*model.Item) ([]*model.Item, error)
	GetItemByName(ctx context.Context, name string) (*model.Item, error)
	GetItemBySKU(ctx context.Context, sku string) (*model.Item, error)
	GetItemsBySKU(ctx context.Context, sku []string) ([]*model.Item, error)
}

type OrderStore

type OrderStore interface {
	AddOrder(ctx context.Context, o *model.Order) error
	GetOrders(ctx context.Context) ([]*model.Order, error)
}

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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