data

package
v0.0.0-...-77cfd70 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DB_USER  database username
	DB_USER = GetEnv("DB_USER", "postgres")
	// DB_PASSWORD username password
	DB_PASSWORD = GetEnv("DB_PASSWORD", "password")
	// DB_NAME database name
	DB_NAME = GetEnv("DB_NAME", "test_bill")
	// DB_HOST database connection host
	DB_HOST = GetEnv("DB_HOST", "localhost")
	// DB_PORT database connection port
	DB_PORT = GetEnv("DB_PORT", "5432")
)
View Source
var Db *sql.DB

Db is the global Database variable

Functions

func BillSplitDeleteAll

func BillSplitDeleteAll() (err error)

BillSplitDeleteAll deletes all BillSplits from database

func ExpenseDeleteAll

func ExpenseDeleteAll() (err error)

ExpenseDeleteAll deletes all Expenses from database

func GetEnv

func GetEnv(key, fallback string) string

GetEnv gets the value of an env var, and if empty returns the default value

func InitDb

func InitDb()

InitDb initializes and opens a connection to the Database with the env vars parameters

func ParticipantDeleteAll

func ParticipantDeleteAll() (err error)

ParticipantDeleteAll deletes all Participants from database

func ParticipantExpenseDeleteAll

func ParticipantExpenseDeleteAll() (err error)

ParticipantExpenseDeleteAll deletes all ParticipantExpense from database

func ReplaceSQL

func ReplaceSQL(old, searchPattern string, startCount int) string

ReplaceSQL replaces the instance occurrence of any string pattern with an increasing $n based sequence

func SetupDB

func SetupDB()

SetupDB clears the database completely

Types

type BillSplit

type BillSplit struct {
	Id        int
	Uuid      string
	Name      string
	CreatedAt JSONTime
}

BillSplit holds DB info of a bill split

func BillSplitByID

func BillSplitByID(id int) (billSplit BillSplit, err error)

BillSplitByID gets a BillSplit record in the DB by its id

func BillSplitByName

func BillSplitByName(name string) (billSplit BillSplit, err error)

BillSplitByName gets a BillSplit record in the DB by its name (unique)

func BillSplitByUUID

func BillSplitByUUID(uuid string) (billSplit BillSplit, err error)

BillSplitByUUID gets a BillSplit record in the DB by its uuid

func BillSplits

func BillSplits() (billSplits []BillSplit, err error)

BillSplits gets all BillSplit records in the DB

func CreateBillSplit

func CreateBillSplit(name string) (billsplit BillSplit, err error)

CreateBillSplit create a new BillSplit in the DB

func (*BillSplit) CreateExpense

func (billSplit *BillSplit) CreateExpense(name string, amount float64, participantName string) (expense Expense, err error)

CreateExpense creates a new expense to the billsplit name: name of the expense to create amount: amount of the expense participantName: payer of the expense

func (*BillSplit) CreateExpenseParticipants

func (billSplit *BillSplit) CreateExpenseParticipants(uuid string, participantNames []string) (err error)

CreateExpenseParticipants add participants to an existing expense uuid: uuid of the expense participantNames: participants to the expense

func (*BillSplit) CreateParticipant

func (billSplit *BillSplit) CreateParticipant(name string) (participant Participant, err error)

CreateParticipant creates a new participant name: name of the participant to create

func (*BillSplit) CreateParticipants

func (billSplit *BillSplit) CreateParticipants(names []string) (err error)

CreateParticipants creates new participants to the billsplit name: names of the participants to create

func (*BillSplit) ExpenseByUuid

func (billSplit *BillSplit) ExpenseByUuid(name string) (expense Expense, err error)

ExpenseByUuid gets an expense in the DB by uuid

func (*BillSplit) Expenses

func (billSplit *BillSplit) Expenses() (items []Expense, err error)

Expenses gets all expenses in the DB of a BillSplit

func (*BillSplit) GetDebts

func (billSplit *BillSplit) GetDebts() (debts []Debt, err error)

GetDebts gets the debts of each participants

func (*BillSplit) GetFullBalance

func (billSplit *BillSplit) GetFullBalance() (fullBalance map[string]float64, err error)

GetFullBalance gets the balance of each participants

func (*BillSplit) ParticipantByName

func (billSplit *BillSplit) ParticipantByName(name string) (participant Participant, err error)

ParticipantByName gets a Participant in the DB by name

func (*BillSplit) Participants

func (billSplit *BillSplit) Participants() (items []Participant, err error)

Participants gets all participants in the DB to a BillSplit

func (*BillSplit) ParticipantsByName

func (billSplit *BillSplit) ParticipantsByName(names []string) (items []Participant, err error)

ParticipantsByName gets a Participants in the DB by name names: names of the participants to get

type Debt

type Debt struct {
	Debtor   string
	Creditor string
	Amount   float64
}

Debt is a struct for debt description: Debtor: participant that owes money Creditor: participant that claims money

type Expense

type Expense struct {
	Id          int
	Uuid        string
	Name        string
	Amount      float64
	BillSplitID int
	PayerName   string
	CreatedAt   JSONTime
}

Expense struct has info of an Expense

func ExpenseByUuid

func ExpenseByUuid(name string) (expense Expense, err error)

ExpenseByUuid gets an Expense record in the DB by its uuid (unique)

func (*Expense) AddParticipant

func (expense *Expense) AddParticipant(name string) (err error)

AddParticipant adds one participants to an expense

func (*Expense) AddParticipants

func (expense *Expense) AddParticipants(names []string) (err error)

AddParticipants adds multiple participants to an expense

func (Expense) Balance

func (expense Expense) Balance() map[string]float64

Balance gets the balance of each participants of the expense

func (*Expense) ExpenseParticipants

func (expense *Expense) ExpenseParticipants() (items []string, err error)

ExpenseParticipants gets the participants to and expense

type JSONTime

type JSONTime time.Time

JSONTime is a time.Time type that implements MarshalJSON in order to have a custom time format

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON returns custom time format

type Participant

type Participant struct {
	Id          int
	Uuid        string
	Name        string
	BillSplitID int
	CreatedAt   JSONTime
}

Participant struct has info of a Participant

func ParticipantByID

func ParticipantByID(id int) (participant Participant, err error)

ParticipantByID gets an Participant record in the DB by its id (unique)

func ParticipantByName

func ParticipantByName(uuid string, billsplitID int) (participant Participant, err error)

ParticipantByName gets an Participant record in the DB by its name and billsplit ID (unique)

func ParticipantByUUID

func ParticipantByUUID(uuid string) (participant Participant, err error)

ParticipantByUUID gets an Participant record in the DB by its uuid (unique)

Jump to

Keyboard shortcuts

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