db

package
v0.0.0-...-78a518a Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	Datastore *gorm.DB
}

DB stores database connection

func New

func New(dbType string, dbConnInfo string) *DB

New creates a new database datastore

func (*DB) AddPayment

func (db *DB) AddPayment(userID uint, amount int)

AddPayment adds a payment for a user specified by id with a certain amount

func (*DB) Close

func (db *DB) Close()

Close closes current database connection

func (*DB) CreateNewUser

func (db *DB) CreateNewUser(username string)

CreateNewUser creates a new user with given username

func (*DB) DeletePayment

func (db *DB) DeletePayment(paymentID uint)

DeletePayment deletes a payment specified by its id

func (*DB) DeletePurchase

func (db *DB) DeletePurchase(purchaseID uint)

DeletePurchase deletes a purchase from database

func (*DB) GetAllDrinks

func (db *DB) GetAllDrinks() []models.Drink

GetAllDrinks returns all drinks in the database

func (*DB) GetAllPaymentsOfUser

func (db *DB) GetAllPaymentsOfUser(userID uint) []models.Payment

GetAllPaymentsOfUser returns all payments of one user specified by id

func (*DB) GetAllUsers

func (db *DB) GetAllUsers() []models.User

GetAllUsers returns all users currently in the database

func (*DB) GetNumberOfPurchasesOfUser

func (db *DB) GetNumberOfPurchasesOfUser(userID uint) int

GetNumberOfPurchasesOfUser returns the number of purchases by a given user

func (*DB) GetPaginatedPurchasesOfUser

func (db *DB) GetPaginatedPurchasesOfUser(userID uint, itemsPerPage int, page int) []models.Purchase

GetPaginatedPurchasesOfUser returns purchases for a given user on a specific page (beginning with 1) with given numberOfItems on each page

func (*DB) GetPurchasesOfUser

func (db *DB) GetPurchasesOfUser(userID uint) []models.Purchase

GetPurchasesOfUser returns all purchases of one user specified by user id with drink information preloaded

func (*DB) GetTotalDebtOfUser

func (db *DB) GetTotalDebtOfUser(userID uint) int

GetTotalDebtOfUser returns the total debt of one user specified by their user id

func (*DB) GetUsername

func (db *DB) GetUsername(userID uint) string

GetUsername returns the username for a given user id

func (*DB) PurchaseDrink

func (db *DB) PurchaseDrink(userID uint, drinkID uint)

PurchaseDrink adds a purchase for one user specified by their id and a drink also specified by id

Jump to

Keyboard shortcuts

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