sqlutils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DateTimeFormat = "2006-01-02 15:04:05.999999"

Variables

View Source
var EmptyResultData = ResultData{}

Functions

func Args

func Args(args ...interface{}) []interface{}

Convert variable length arguments into arguments array

func Exec

func Exec(db *sql.DB, query string, args ...interface{}) (sql.Result, error)

Exec executes given query using given args on given DB. It will safele prepare, execute and close the statement.

func ExecNoPrepare

func ExecNoPrepare(db *sql.DB, query string, args ...interface{}) (res sql.Result, err error)

ExecNoPrepare executes given query using given args on given DB, without using prepared statements.

func ExecSilently

func ExecSilently(db *sql.DB, query string, args ...interface{}) (sql.Result, error)

ExecSilently acts like Exec but does not report any error

func GetDB

func GetDB(mysql_uri string) (*sql.DB, bool, error)

GetDB returns a MySQL DB instance based on uri. bool result indicates whether the DB was returned from cache; err

func GetGenericDB

func GetGenericDB(driverName, dataSourceName string) (*sql.DB, bool, error)

GetDB returns a DB instance based on uri. bool result indicates whether the DB was returned from cache; err

func GetSQLiteDB

func GetSQLiteDB(dbFile string) (*sql.DB, bool, error)

GetDB returns a SQLite DB instance based on DB file name. bool result indicates whether the DB was returned from cache; err

func InClauseStringValues

func InClauseStringValues(terms []string) string

func IsAlterTable

func IsAlterTable(statement string) bool

func IsCreateIndex

func IsCreateIndex(statement string) bool

func IsCreateTable

func IsCreateTable(statement string) bool

func IsDropIndex

func IsDropIndex(statement string) bool

func IsInsert

func IsInsert(statement string) bool

func NilIfZero

func NilIfZero(i int64) interface{}

func QueryRowsMap

func QueryRowsMap(db *sql.DB, query string, on_row func(RowMap) error, args ...interface{}) (err error)

QueryRowsMap is a convenience function allowing querying a result set while poviding a callback function activated per read row.

func QueryRowsMapBuffered

func QueryRowsMapBuffered(db *sql.DB, query string, on_row func(RowMap) error, args ...interface{}) error

QueryRowsMapBuffered reads data from the database into a buffer, and only then applies the given function per row. This allows the application to take its time with processing the data, albeit consuming as much memory as required by the result set.

func ScanRowsToArrays

func ScanRowsToArrays(rows *sql.Rows, on_row func([]CellData) error) error

ScanRowsToArrays is a convenience function, typically not called directly, which maps rows already read from the databse into arrays of NullString

func ScanRowsToMaps

func ScanRowsToMaps(rows *sql.Rows, on_row func(RowMap) error) error

ScanRowsToMaps is a convenience function, typically not called directly, which maps rows already read from the databse into RowMap entries.

func ToSqlite3CreateTable

func ToSqlite3CreateTable(statement string) string

func ToSqlite3Dialect

func ToSqlite3Dialect(statement string) (translated string)

func ToSqlite3Insert

func ToSqlite3Insert(statement string) string

func WriteTable

func WriteTable(db *sql.DB, tableName string, data NamedResultData) (err error)

Types

type CellData

type CellData sql.NullString

Cell data is the result of a single (atomic) column in a single row

func RowToArray

func RowToArray(rows *sql.Rows, columns []string) []CellData

RowToArray is a convenience function, typically not called directly, which maps a single read database row into a NullString

func (*CellData) MarshalJSON

func (this *CellData) MarshalJSON() ([]byte, error)

func (*CellData) NullString

func (this *CellData) NullString() *sql.NullString

func (*CellData) UnmarshalJSON

func (this *CellData) UnmarshalJSON(b []byte) error

UnmarshalJSON reds this object from JSON

type NamedResultData

type NamedResultData struct {
	Columns []string
	Data    ResultData
}

func QueryNamedResultData

func QueryNamedResultData(db *sql.DB, query string, args ...interface{}) (NamedResultData, error)

QueryResultDataNamed returns a raw array of rows, with column names

func ScanTable

func ScanTable(db *sql.DB, tableName string) (NamedResultData, error)

type ResultData

type ResultData []RowData

ResultData is an ordered row set of RowData

func QueryResultData

func QueryResultData(db *sql.DB, query string, args ...interface{}) (ResultData, error)

QueryResultData returns a raw array of rows

type RowData

type RowData []CellData

RowData is the result of a single row, in positioned array format

func (*RowData) Args

func (this *RowData) Args() []interface{}

func (*RowData) MarshalJSON

func (this *RowData) MarshalJSON() ([]byte, error)

MarshalJSON will marshal this map as JSON

type RowMap

type RowMap map[string]CellData

RowMap represents one row in a result set. Its objective is to allow for easy, typed getters by column name.

func (*RowMap) GetBool

func (this *RowMap) GetBool(key string) bool

func (*RowMap) GetInt

func (this *RowMap) GetInt(key string) int

func (*RowMap) GetInt64

func (this *RowMap) GetInt64(key string) int64

func (*RowMap) GetIntD

func (this *RowMap) GetIntD(key string, def int) int

func (*RowMap) GetNullInt64

func (this *RowMap) GetNullInt64(key string) sql.NullInt64

func (*RowMap) GetString

func (this *RowMap) GetString(key string) string

func (*RowMap) GetStringD

func (this *RowMap) GetStringD(key string, def string) string

GetStringD returns a string from the map, or a default value if the key does not exist

func (*RowMap) GetTime

func (this *RowMap) GetTime(key string) time.Time

func (*RowMap) GetUint

func (this *RowMap) GetUint(key string) uint

func (*RowMap) GetUint64

func (this *RowMap) GetUint64(key string) uint64

func (*RowMap) GetUint64D

func (this *RowMap) GetUint64D(key string, def uint64) uint64

func (*RowMap) GetUintD

func (this *RowMap) GetUintD(key string, def uint) uint

Jump to

Keyboard shortcuts

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