dbutil

package
v0.0.0-...-406b088 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Insert

func Insert(db Execer, tableName string, vals H) (sql.Result, error)

Insert inserts given values into the given database table

func InsertWithoutConflict

func InsertWithoutConflict(db Execer, tableName string, vals H) (sql.Result, error)

InsertWithoutConflict inserts given values into the given database table with 'on conflict do nothing'

func MustInsert

func MustInsert(db Execer, tableName string, vals H) sql.Result

MustInsert inserts given values into the given database table and panics (in 'mustbe' way) if error

func MustInsertWithoutConflict

func MustInsertWithoutConflict(db Execer, tableName string, vals H) sql.Result

MustInsertWithoutConflict inserts given values into the given database table with 'on conflict do nothing' and panics (in 'mustbe' way) if error

func MustQueryRows

func MustQueryRows(db Querier, query string, args Args, foo func(RowScanner))

MustQueryRows performs Query and Scan's resulting Rows and panics (in 'mustbe' way) if error. It also expects mustbe-panic in foo.

func MustTransact

func MustTransact(db *sql.DB, foo func(*sql.Tx))

MustTransact opens transaction and call foo with it. It rollback transaction if panic happens in foo and re-panic that panic.

func QueryCol

func QueryCol(db Querier, dest interface{}, query string, args ...interface{}) error

QueryCol fetches a single column from the query result. dest must be a pointer to slice of column type.

func QueryCols

func QueryCols(db Querier, dest interface{}, query string, args ...interface{}) error

QueryCols fetches all columns from the query result. dest must be a pointer to slice of structs with fields ordered and typed as columns.

func QueryRows

func QueryRows(db Querier, query string, args Args, foo func(RowScanner) error) error

QueryRows performs Query and Scan's resulting Rows

func QuoteString

func QuoteString(s string) string

QuoteString quotes string value according to PostgreSQL rules see https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS

func QuoteStrings

func QuoteStrings(ss []string) (out []string)

QuoteStrings quotes all strings in array

func SQLizeParams

func SQLizeParams(vals H) (names, placeholders string, params []interface{})

SQLizeParams converts vals to 1) string of names, 2) string of placeholders and 3) slice of params values

Types

type Args

type Args []interface{}

Args is a general argoments list

type Execer

type Execer interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Execer is the interface for Exec method

type H

type H map[string]interface{}

H is a general map string->any

type Querier

type Querier interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

Querier is the interface for Query method

type QueryRower

type QueryRower interface {
	QueryRow(query string, args ...interface{}) *sql.Row
}

QueryRower is the interface for QueryRow method

type RowScanner

type RowScanner interface {
	Scan(dest ...interface{}) error
}

RowScanner is an interface with a sql.Row(s) Scan function

type ScanValuer

type ScanValuer interface {
	sql.Scanner
	driver.Valuer
}

ScanValuer interface combines sql.Scanner and driver.Valuer

func JSONVal

func JSONVal(v interface{}) ScanValuer

JSONVal returns an object implementing ScanValuer interfaces to read/write JSON(b) values from/to DB. 'v' must be pointer for Scan use.

Jump to

Keyboard shortcuts

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