udb

package
v0.0.0-...-76c535a Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 1 Imported by: 0

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.

Documentation

Overview

Go programming helpers for common database needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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`.

Types

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 {
	// contains filtered or unexported fields
}

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`.

Directories

Path Synopsis
Go programming helpers for common MongoDB needs.
Go programming helpers for common MongoDB needs.

Jump to

Keyboard shortcuts

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