database

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDBExists

func EnsureDBExists(cfg *config.Config) error

EnsureDBExists creates the database and the correct tables.

func TestDBExistence

func TestDBExistence(cfg *config.Config) error

TestDBExistence checks for the host and the database.

func TestDBHost

func TestDBHost(cfg *config.Config) error

TestDBHost only tests for the host.

Types

type Client

type Client struct {
	// ID is autogenerated.
	ID int64
	// Company is the primary string reference.
	Company string
	// Email is the primary contact. Add to the contacts table for more.
	Email string
	// Phone if applicable.
	Phone string
	// Address to print on invoices.
	Address string
	// VATID or org. no.
	VATID string
	// Created timestamp.
	Created time.Time
}

Client structure translated from the database.

type Contact added in v0.2.0

type Contact struct {
	// ID in the database.
	ID int64
	// Name of person. Non-unique to allow multiple e-mails or phone numbers.
	Name string
	// Email to contact them at. May be blank.
	Email string
	// Phone number to contact them at. May be blank.
	Phone string
	// Client they work for.
	Client int64
	// Created timestamp.
	Created time.Time
}

Contact structure from the database.

type Invoices

type Invoices struct {
	*sql.DB
}

Invoices is the name of our DB type to make it clear this isn't generic.

func Open

func Open(host, port, user, password, dbname string, ssl bool) (*Invoices, error)

Open a database session.

func (*Invoices) AddClient

func (db *Invoices) AddClient(c *Client) (int64, error)

AddClient returns the client ID on success.

func (*Invoices) AddContact added in v0.2.0

func (db *Invoices) AddContact(c *Contact) (int64, error)

AddContact returns the contact ID on success.

func (*Invoices) GetAllClients

func (db *Invoices) GetAllClients() ([]*Client, error)

GetAllClients returns all clients.

func (*Invoices) GetAllContacts added in v0.2.0

func (db *Invoices) GetAllContacts() ([]*Contact, error)

GetAllContacts returns all contacts.

func (*Invoices) GetClient

func (db *Invoices) GetClient(id int64) *Client

GetClient returns one client by ID.

func (*Invoices) GetClients

func (db *Invoices) GetClients(keyword string) ([]*Client, error)

GetClients returns all matching clients.

func (*Invoices) GetContact added in v0.2.0

func (db *Invoices) GetContact(id int64) *Contact

GetContact returns one contact by ID.

func (*Invoices) GetContacts added in v0.2.0

func (db *Invoices) GetContacts(keyword string) ([]*Contact, error)

GetContacts returns all matching contacts.

func (*Invoices) RemoveClient

func (db *Invoices) RemoveClient(id int64) error

RemoveClient from database.

func (*Invoices) RemoveContact added in v0.2.0

func (db *Invoices) RemoveContact(id int64) error

RemoveContact from database.

func (*Invoices) UpdateClient

func (db *Invoices) UpdateClient(c *Client) error

UpdateClient changes the details of a client.

func (*Invoices) UpdateContact added in v0.2.0

func (db *Invoices) UpdateContact(c *Contact) error

UpdateContact changes the details of a contact.

Jump to

Keyboard shortcuts

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