package
0.0.0-20180330192724-a09253046f73
Repository: https://github.com/metaleap/go-util.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

udb

Go programming helpers for common database needs.

Usage

func Exec

func Exec(execer Execer, isInsert bool, query string, args ...interface{}) (result int64, err error)

Exec calls execer.Exec(query, args...) and from the returned sql.Result, returns either its LastInsertId (if isInsert is true) or its RowsAffected.

type Execer

type Execer interface {
	//	Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Implemented by both *sql.DB and *sql.Tx.

type Querier

type Querier interface {
	//	Query executes a query that returns rows. The args are for any placeholder parameters in the query.
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

Implemented by both *sql.DB and *sql.Tx.

type SqlCursor

type SqlCursor struct {
}

Helps iterating over *sql.Rows. After each rows.Next call, you can call the Scan method to return the record set as a map[string]interface{}.

If the columns are identical for all records (most SQL databases), call PrepareColumns just once prior to iteration. If the columns vary across records (some NoSQL databases), call PrepareColumns during each iteration prior to Scan.

func (*SqlCursor) PrepareColumns

func (me *SqlCursor) PrepareColumns(rows *sql.Rows) (err error)

Retrieves meta-data information about the rows.Columns.

func (*SqlCursor) Scan

func (me *SqlCursor) Scan(rows *sql.Rows) (rec map[string]interface{}, err error)

According to the meta-data retrieved during your prior-most call to me.PrepareColumns, populates rec with all field values for the current record in the specified rows.