Documentation ¶
Index ¶
- Constants
- type DB
- func (db *DB) GetLast7DaysMessageCount() (map[string]int, error)
- func (db *DB) GetMessages(filter string) ([]SMS, error)
- func (db *DB) GetPendingMessages(limit int) ([]SMS, error)
- func (db *DB) GetStatusSummary() ([]int, error)
- func (db *DB) InsertMessage(sms SMS) error
- func (db *DB) UpdateMessageStatus(sms SMS) error
- type SMS
- type SMSStatus
Constants ¶
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 ¶
DB is a wrapper around sql.DB.
func New ¶
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 ¶
GetLast7DaysMessageCount determines the number of SMSs added on each of the past 7 days.
func (*DB) GetMessages ¶
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 ¶
GetPendingMessages gets the set of SMSs waiting to be sent.
func (*DB) GetStatusSummary ¶
GetStatusSummary determines the number of SMSs in each state.
func (*DB) InsertMessage ¶
InsertMessage inserts an SMS into the database.
func (*DB) UpdateMessageStatus ¶
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 )