Documentation ¶
Overview ¶
Package sqlh provides some helper functions and types to simplify working with sql package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustPrepare ¶
MustPrepare is like DB.Prepare but panics if the SQL cannot be parsed. It simplifies safe initialization of global variables holding prepared statements.
func StmtScanAll ¶
func StmtScanAll(stmt *sql.Stmt, dst MultiScannable, args ...interface{}) error
StmtScanAll performs prepared statement stmt with arguments 'args' and stores all result rows in dst. StmtScanAll stop working on first error. Example:
type Label struct { Id int32 Name string } func (l *Label) SqlScanInterface() []interface{} { return []interface{}{ &l.Id, &l.Name, } } type Labels []*Label func (l *Labels) SqlNewElement() sqlh.SingleScannable { e := &Label{} *l = append(*l, e) return e } ... var labels Labels if err := sqlh.StmtScanAll(someStmtGetLabels, &labels, someId, someOtherParam); err != nil { return err }
Types ¶
type MultiScannable ¶
type MultiScannable interface { // SqlNewElement called for each row in query result. It should returns SingleScannable object for scanning row. // Usually this method add new element to the underlying slice and return this element. SQLNewElement() SingleScannable }
MultiScannable represent object in that any amount of rows can be saved.
type SingleScannable ¶
type SingleScannable interface {
// SqlScanInterface return slice of interfaces which will be passed into Row.Scan at once.
SQLScanInterface() []interface{}
}
SingleScannable represent object in that single row can be saved.
Click to show internal directories.
Click to hide internal directories.