model

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package model encapsules db operations. Only for internal purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBDrv

type DBDrv interface {
	// creates a notification to send
	Create(i *Item) (err error)
	// send a notification again, does not retry, return &E404{} if id not found
	Resend(id string, max uint32) (err error)
	// update a notification after sending. *NEVER* return error if id not found
	Update(id string, tried uint32, next int64, state types.State, resp []byte) (err error)
	// retrieve last sending result, return &E404{} if id not found
	Result(id string) (ret []byte, err error)
	// retrieve status, return &E404{} if id not found
	Status(id string) (ret types.Status, err error)
	// retrieve detail info, return &E404{} if id not found
	Detail(id string) (ret types.Detail, err error)
	// get one pending notification
	Pending(now int64, max uint32, drvs, ids []string) (ret *Item, err error)
	// delete a notification, excepts current sending notifications
	// *NEVER* return error if nothing's deleted (id not found or something)
	Delete(id string, cur []string) (err error)
	// clear finished notifications older than t, excepts current sending ones
	Clear(t time.Time, cur []string) (err error)
	// clear all notifications older than t, excepts current sending ones
	ForceClear(t time.Time, cur []string) (err error)
}

DBDrv defines db related methods

It is possible to do some magic in this interface to affect sender, but you *SHOULD NOT* do this unless you have good reason.

type DrvBase

type DrvBase struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

DrvBase is a helper to cache *sql.Stmt

func NewDrvBase

func NewDrvBase(db *sql.DB) (ret *DrvBase)

NewDrvBase creates a DrvBase

func (*DrvBase) Prepare

func (d *DrvBase) Prepare(qstr string, e error) (err error)

Prepare caches a *sql.Stmt

It supports error checking like this:

err = d.Prepare(query1, nil)
err = d.Prepare(query2, err)
err = d.Prepare(query3, err)
if err != nil {
    return err
}

func (*DrvBase) Stmt

func (d *DrvBase) Stmt(qstr string) (ret *sql.Stmt)

Stmt retrieves previously cached *sql.Stmt, returns nil if not found

It is *RECOMMENDED* to store your sql query statement in constant or variable, and call Prepare()/Stmt() with that const/var. See package mysqldrv as a simple example, and package pgsqldrv for a even better example.

type E404

type E404 struct{}

func (*E404) Error

func (e *E404) Error() string

type Item

type Item struct {
	ID       string
	Driver   string
	Endpoint string
	Content  []byte
	CreateAt int64
	NextAt   int64
	Tried    uint32
	State    types.State
}

Directories

Path Synopsis
Package dbdrvtest provides needed integral test for db driver writer.
Package dbdrvtest provides needed integral test for db driver writer.
Package mysqldrv provides mysql db driver This driver is tested with github.com/go-sql-driver/mysql against mysql 5.7/8
Package mysqldrv provides mysql db driver This driver is tested with github.com/go-sql-driver/mysql against mysql 5.7/8
Package pgsqldrv provides postgresql db driver This driver is tested with github.com/jackc/pgx/v4 against postgres 9~13
Package pgsqldrv provides postgresql db driver This driver is tested with github.com/jackc/pgx/v4 against postgres 9~13

Jump to

Keyboard shortcuts

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