sqlt

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 7 Imported by: 0

README

sqlt

GitHub go.mod Go version GitHub release (latest by date) Go Report Card

Minimal set of useful things to work with database in Go.

Installation

go get -u github.com/mono83/sqlt

Provided custom types

  • sqlt.TrueFalse - to read boolean value stored in database as enum(true,false)
  • sqlt.UnixSecinds - to read time.Time value stored in database as integer unix timestamp in seconds

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnixSecondsUnsupportedType = errors.New("unsupported type")

Functions

func InsertID

func InsertID(result sql.Result, err error) (int64, error)

InsertID returns auto incremental identifier of last inserted entity as int64.

func InsertIDU

func InsertIDU(result sql.Result, err error) (uint64, error)

InsertIDU returns auto incremental identifier of last inserted entity as uint64.

func IterateScan

func IterateScan(rows *sql.Rows, callback func([]string, []*sql.ColumnType, []interface{})) error

IterateScan scans given rows ony by one passing obtained data to callback function.

func StdConvert

func StdConvert(src interface{}, def *sql.ColumnType) interface{}

StdConvert performs conversion from interface{} to defined in sql.ColumnType type using standard ruleset.

Types

type Executor

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

Executor is a thin interface for database connection capable to modify data

type Getter

type Getter interface {
	Get(dest interface{}, query string, args ...interface{}) error
}

Getter is a thin interface for database connection capable to read data

type Reader

type Reader interface {
	Getter
	Selector
}

Reader is an interface defining connection able to perform read operations

type ReaderExecutor

type ReaderExecutor interface {
	Reader
	Executor
}

ReaderExecutor is a thin interface for database connection capable to both read and write data

type Rowset

type Rowset struct {
	ColumnNames []string
	ColumnTypes []*sql.ColumnType
	Rows        [][]interface{}
}

Rowset is plain two-dimensional data table containing data, obtained from SQL database in non-structured way (via interface{})

func (*Rowset) Clear

func (r *Rowset) Clear()

Clear cleans up rowset contents.

func (Rowset) Each

func (r Rowset) Each(f func([]string, []*sql.ColumnType, []interface{}))

Each iterated over each row, passing it with corresponding metadata to callback function.

func (Rowset) MapValues

func (r Rowset) MapValues(f func(src interface{}, def *sql.ColumnType) interface{}) Rowset

MapValues maps all values in rowset using given conversion function.

func (Rowset) MapValuesStd

func (r Rowset) MapValuesStd() Rowset

MapValuesStd maps all values in rowset using standard conversion function.

func (*Rowset) Scan

func (r *Rowset) Scan(rows *sql.Rows) error

Scan method fills rowset contents using data from given sql.Rows.

func (Rowset) Size

func (r Rowset) Size() int

Size returns amount of rows.

func (Rowset) SliceMap

func (r Rowset) SliceMap() (out []map[string]interface{})

SliceMap returns content of rowset as slice of maps.

type Selector

type Selector interface {
	Select(dest interface{}, query string, args ...interface{}) error
}

Selector is a thin interface for database connection capable to read data

type TrueFalse

type TrueFalse bool

TrueFalse wraps values stored in database as enum(true,false)

func (TrueFalse) Bool

func (t TrueFalse) Bool() bool

Bool returns boolean representation

func (TrueFalse) IsTrue

func (t TrueFalse) IsTrue() bool

IsTrue returns boolean representation, is an alias to Bool

func (TrueFalse) NativeSQL

func (t TrueFalse) NativeSQL() interface{}

NativeSQL returns data in SQL native format

func (*TrueFalse) Scan

func (t *TrueFalse) Scan(value interface{}) error

Scan is sql.Scanner interface implementation

func (*TrueFalse) String

func (t *TrueFalse) String() string

String returns string representation of boolean value

func (TrueFalse) Value

func (t TrueFalse) Value() (driver.Value, error)

Value is a sql.driver.Valuer interface implementation

type UnixSeconds

type UnixSeconds int64

UnixSeconds is type containing timestamp in unix seconds

func (UnixSeconds) Int64

func (u UnixSeconds) Int64() int64

Int64 returns unix seconds as int64

func (UnixSeconds) NativeSQL

func (u UnixSeconds) NativeSQL() interface{}

NativeSQL returns data in SQL native format

func (*UnixSeconds) Scan

func (u *UnixSeconds) Scan(src interface{}) error

Scan is sql.Scanner interface implementation

func (UnixSeconds) String

func (u UnixSeconds) String() string

String return string representation of time in UTC

func (UnixSeconds) Time

func (u UnixSeconds) Time() time.Time

Time return unix seconds formatted as UTC time

func (UnixSeconds) Value

func (u UnixSeconds) Value() (driver.Value, error)

Value is a driver.Valuer interface implementation

Jump to

Keyboard shortcuts

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