db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2018 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const SMSRetryLimit = 3

SMSRetryLimit specifies the number of attempts to send an SMS before marking it as SMSErrored. TODO: should be configurable (in the DB?? Per modem? Modems in the DB??)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
}

DB is a wrapper around sql.DB.

func New

func New(driver, dbname string) (*DB, error)

New creates a database client. If it does not already exist then it is created and initialised. If it does exist then it checks that it has the correct schema version.

func (*DB) GetLast7DaysMessageCount

func (db *DB) GetLast7DaysMessageCount() (map[string]int, error)

GetLast7DaysMessageCount determines the number of SMSs added on each of the past 7 days.

func (*DB) GetMessages

func (db *DB) GetMessages(filter string) ([]SMS, error)

GetMessages gets the set of SMSs corresponding to the filter. Expecting filter as empty string or WHERE clauses, simply appended to the query to get desired set from the database

func (*DB) GetPendingMessages

func (db *DB) GetPendingMessages(limit int) ([]SMS, error)

GetPendingMessages gets the set of SMSs waiting to be sent.

func (*DB) GetStatusSummary

func (db *DB) GetStatusSummary() ([]int, error)

GetStatusSummary determines the number of SMSs in each state.

func (*DB) InsertMessage

func (db *DB) InsertMessage(sms SMS) error

InsertMessage inserts an SMS into the database.

func (*DB) UpdateMessageStatus

func (db *DB) UpdateMessageStatus(sms SMS) error

UpdateMessageStatus updates the mutable fields of the SMS.

type SMS

type SMS struct {
	UUID      string    `json:"uuid"`
	Mobile    string    `json:"mobile"`
	Body      string    `json:"body"`
	Status    SMSStatus `json:"status"`
	Retries   int       `json:"retries"`
	Device    string    `json:"device"`
	CreatedAt string    `json:"created_at"`
	UpdatedAt string    `json:"updated_at"`
}

SMS represents an SMS, as stored in the db.

type SMSStatus

type SMSStatus int

SMSStatus indicates the state of the SMS.

const (
	// SMSPending indicates the SMS is waiting to be sent.
	SMSPending SMSStatus = iota // 0
	// SMSSent indicates the SMS was successfully sent.
	SMSSent // 1
	// SMSErrored indicates the SMS was attempted to be sent but failed.
	SMSErrored // 2
	// SMSCanceled indicates the SMS was canceled prior to being sent.
	SMSCanceled // 3
)

Jump to

Keyboard shortcuts

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