db

package
v0.0.0-...-e0d82eb Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const OrdersCollection = "orders"

OrdersCollection is the name of the MongoDB collection to use for Orders.

View Source
const ShipmentCollection = "shipments"

ShipmentCollection is the name of the MongoDB collection to use for Shipment data.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Connect(ctx context.Context) error
	Setup() error
	Close() error
	InsertOrder(context.Context, *OrderStatus) error
	UpdateOrderStatus(context.Context, string, string) error
	GetOrders(context.Context, *[]OrderStatus) error
	UpdateShipmentStatus(context.Context, string, string) error
	GetShipments(context.Context, *[]ShipmentStatus) error
}

DB is an interface that defines the methods that a database driver must implement

func CreateDB

func CreateDB(config config.AppConfig) DB

CreateDB creates a new DB instance based on the configuration

type MongoDB

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

MongoDB is a struct that implements the DB interface for MongoDB

func (*MongoDB) Close

func (m *MongoDB) Close() error

Close closes the connection to the MongoDB instance

func (*MongoDB) Connect

func (m *MongoDB) Connect(ctx context.Context) error

Connect connects to a MongoDB instance

func (*MongoDB) GetOrders

func (m *MongoDB) GetOrders(ctx context.Context, result *[]OrderStatus) error

GetOrders returns a list of Orders from the MongoDB instance

func (*MongoDB) GetShipments

func (m *MongoDB) GetShipments(ctx context.Context, result *[]ShipmentStatus) error

GetShipments returns a list of Shipments from the MongoDB instance

func (*MongoDB) InsertOrder

func (m *MongoDB) InsertOrder(ctx context.Context, order *OrderStatus) error

InsertOrder inserts an Order into the MongoDB instance

func (*MongoDB) Setup

func (m *MongoDB) Setup() error

Setup sets up the MongoDB instance

func (*MongoDB) UpdateOrderStatus

func (m *MongoDB) UpdateOrderStatus(ctx context.Context, id string, status string) error

UpdateOrderStatus updates an Order in the MongoDB instance

func (*MongoDB) UpdateShipmentStatus

func (m *MongoDB) UpdateShipmentStatus(ctx context.Context, id string, status string) error

UpdateShipmentStatus updates a Shipment in the MongoDB instance

type OrderStatus

type OrderStatus struct {
	ID         string `db:"id" bson:"id"`
	CustomerID string `db:"customer_id" bson:"customer_id"`
	Status     string `db:"status" bson:"status"`

	ReceivedAt time.Time `db:"received_at" bson:"received_at"`
}

OrderStatus is a struct that represents the status of an Order

type SQLiteDB

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

SQLiteDB is a struct that implements the DB interface for SQLite

func (*SQLiteDB) Close

func (s *SQLiteDB) Close() error

Close closes the connection to the SQLite instance

func (*SQLiteDB) Connect

func (s *SQLiteDB) Connect(_ context.Context) error

Connect connects to a SQLite instance

func (*SQLiteDB) GetOrders

func (s *SQLiteDB) GetOrders(ctx context.Context, result *[]OrderStatus) error

GetOrders returns a list of Orders from the SQLite instance

func (*SQLiteDB) GetShipments

func (s *SQLiteDB) GetShipments(ctx context.Context, result *[]ShipmentStatus) error

GetShipments returns a list of Shipments from the SQLite instance

func (*SQLiteDB) InsertOrder

func (s *SQLiteDB) InsertOrder(ctx context.Context, order *OrderStatus) error

InsertOrder inserts an Order into the SQLite instance

func (*SQLiteDB) Setup

func (s *SQLiteDB) Setup() error

Setup sets up the SQLite instance

func (*SQLiteDB) UpdateOrderStatus

func (s *SQLiteDB) UpdateOrderStatus(ctx context.Context, id string, status string) error

UpdateOrderStatus updates an Order in the SQLite instance

func (*SQLiteDB) UpdateShipmentStatus

func (s *SQLiteDB) UpdateShipmentStatus(ctx context.Context, id string, status string) error

UpdateShipmentStatus updates a Shipment in the SQLite instance

type ShipmentStatus

type ShipmentStatus struct {
	ID     string `db:"id" bson:"id"`
	Status string `db:"status" bson:"status"`
}

ShipmentStatus is a struct that represents the status of a Shipment

Jump to

Keyboard shortcuts

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