Documentation
¶
Overview ¶
transaction provides a model for a single user transaction. It also provides a simple implementation of a sqlite table for storing and querying transactions.
Index ¶
- Constants
- func Unix(date string) (int64, error)
- type CSVReader
- type CSVWriter
- type Cent
- type Rows
- type Table
- func (t *Table) Init() error
- func (t *Table) Insert(tx Transaction) error
- func (t *Table) Range(start, end time.Time, limit int) (*Rows, error)
- func (t *Table) RangeTotal(start, end time.Time) (Cent, error)
- func (t *Table) Remove(transactionID int) error
- func (t *Table) Search(query string, limit int) (*Rows, error)
- func (t *Table) Total() (Cent, error)
- type Transaction
Constants ¶
const ( TableName = "transactions" IDCol = "ID" EntityCol = "Entity" AmountCol = "Amount" DateCol = "Date" NoteCol = "Note" DateLayout = "1/2/2006" // TODO: this should probably be configurable, but I currently only use US dollars Currency = "$" Point = "." Thousands = "," )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CSVReader ¶
func NewCSVReader ¶
func (*CSVReader) Read ¶
func (cr *CSVReader) Read() (Transaction, error)
? Should I consider allowing headers to set the order?
func (*CSVReader) ReadAll ¶
func (cr *CSVReader) ReadAll() ([]Transaction, error)
type CSVWriter ¶
func NewCSVWriter ¶
func (*CSVWriter) Write ¶
func (cw *CSVWriter) Write(tx Transaction) error
func (*CSVWriter) WriteAll ¶
func (cw *CSVWriter) WriteAll(txs []Transaction) error
type Cent ¶
type Cent int
Cent represents 1/100th of a Dollar
type Rows ¶
Rows wraps *sql.Rows to easily scan Transactions from a DB
func (*Rows) Scan ¶
func (r *Rows) Scan() (Transaction, error)
Scan scans a transaction from the current result set.
func (*Rows) ScanSet ¶
func (r *Rows) ScanSet() ([]Transaction, error)
ScanSet scans up to "limit" transactions from a result set into a slice. Do not use ScanSet if you expect that that your result set will be very large.
type Table ¶
Table is the transactions table in a database
func (*Table) Insert ¶
func (t *Table) Insert(tx Transaction) error
Insert inserts a transaction into the transactions table. The ID provided by "tx" is ignored, as the database determines the ID.
func (*Table) Range ¶
Range returns the transactions that occurred within the give range of time. It returns, at most, "limit" transactions, and returns them in chronological order. A negative "limit" will return as many transactions as are available.
func (*Table) RangeTotal ¶
RangeTotal returns the cost of the transactions that occurred within the give range of time.
It uses, at most, "limit" transactions. A negative "limit" will use as many transactions as are available.
type Transaction ¶
type Transaction struct { ID int // Entity is the person or company the transaction was made with. Entity string // Amount is the cost of the transaction in cents Amount Cent // Date is the Unix Time the transaction occurred in seconds. Date int64 // Note is any note the user wants to add about the transaction. Note string }
TODO: add a String() function Transaction represents a single transaction in a person's budget
func (Transaction) DateString ¶
func (t Transaction) DateString() string
DateString returns the Transaction's date in M/D/YYYY format.