db

package
v0.0.0-...-5416f79 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2017 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IterateContinue = IterateControl(1)
	IterateStop     = IterateControl(0)
)

Variables

This section is empty.

Functions

func GroupedStringToIntArray

func GroupedStringToIntArray(groupedValue sql.NullString, separator string) []int64

Converts grouped string to array of int64

groupedValue - The grouped value retrieved from database, could be null separator - The separator

func GroupedStringToStringArray

func GroupedStringToStringArray(groupedValue sql.NullString, separator string) []string

Converts grouped string to array of string

groupedValue - The grouped value retrieved from database, could be null separator - The separator

func GroupedStringToUintArray

func GroupedStringToUintArray(groupedValue sql.NullString, separator string) []uint64

Converts grouped string to array of uint64

groupedValue - The grouped value retrieved from database, could be null separator - The separator

func IpV4ToBytesForLike

func IpV4ToBytesForLike(ip string) ([]byte, error)

Converts IPv4 address of string to byte array could be used in SQL.

func IsPartialIpV4

func IsPartialIpV4(ip string) bool

Checks whether or not the string is partial IPv4:

123
123.74
123.74.109.81

func PanicIfError

func PanicIfError(err error)

Panic with database error if the error is vialbe

Types

type Bytes16

type Bytes16 types.Bytes16

func (Bytes16) IsNil

func (b Bytes16) IsNil() bool

func (*Bytes16) Scan

func (b *Bytes16) Scan(src interface{}) error

Supports hex string or bytes

func (Bytes16) Value

func (b Bytes16) Value() (driver.Value, error)

type DbCallback

type DbCallback interface {
	OnDb(db *sql.DB)
}

The interface of DB callback for sql package

type DbCallbackFunc

type DbCallbackFunc func(*sql.DB)

The function object delegates the DbCallback interface

func (DbCallbackFunc) OnDb

func (f DbCallbackFunc) OnDb(db *sql.DB)

type DbConfig

type DbConfig struct {
	Dsn     string
	MaxIdle int
}

Configuration of database

func (*DbConfig) String

func (config *DbConfig) String() string

type DbController

type DbController struct {
	// contains filtered or unexported fields
}

Main controller of database

func NewDbController

func NewDbController(newDbObject *sql.DB) *DbController

Initialize a controller for database

Without RegisterPanicHandler() any PanicHandler, The raised panic would be re-paniced.

func (*DbController) Exec

func (dbController *DbController) Exec(query string, args ...interface{}) sql.Result

Executes the query string or panic

func (*DbController) ExecQueriesInTx

func (dbController *DbController) ExecQueriesInTx(queries ...string)

Executes in transaction

func (*DbController) InTx

func (dbController *DbController) InTx(txCallback TxCallback)

Executes in transaction.

This method would commit the transaction if there is no raised panic, rollback it otherwise.

func (*DbController) InTxForIf

func (dbController *DbController) InTxForIf(ifCallbacks ExecuteIfByTx)

Executes the complex statement in transaction

func (*DbController) OperateOnDb

func (dbController *DbController) OperateOnDb(dbCallback DbCallback)

Operate on database

func (*DbController) QueryForRow

func (dbController *DbController) QueryForRow(
	rowCallback RowCallback,
	sqlQuery string, args ...interface{},
)

Query for a row and get called if the query is not failed

func (*DbController) QueryForRows

func (dbController *DbController) QueryForRows(
	rowsCallback RowsCallback,
	sqlQuery string, args ...interface{},
) (numberOfRows uint)

Query for rows and get called of rows with Next()

func (*DbController) RegisterPanicHandler

func (dbController *DbController) RegisterPanicHandler(panicHandler utils.PanicHandler)

Registers a handler while a panic is raised

This object may register multiple handlers for panic

func (*DbController) Release

func (dbController *DbController) Release()

Releases the database object under this object

As of service application(web, daemon...), this method is rarely get called

type DbError

type DbError struct {
	*utils.StackError
}

Defines the type of database error

func NewDatabaseError

func NewDatabaseError(err error) *DbError

Constructs an error of database

type DbUuid

type DbUuid uuid.UUID

Uses the []byte for database/sql/driver.Value

func (DbUuid) IsNil

func (u DbUuid) IsNil() bool

func (*DbUuid) Scan

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

This function supports []byte or string value

func (DbUuid) ToUuid

func (u DbUuid) ToUuid() uuid.UUID

func (DbUuid) Value

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

This function would supply []byte as value of database driver

type ExecuteIfByTx

type ExecuteIfByTx interface {
	// First calling of database for boolean result
	BootCallback(tx *sql.Tx) bool
	// If the boot callback has true result, this callback would get called
	IfTrue(tx *sql.Tx)
}

Executes callbacks in transaction if the boot callback has true value

type GraphEndpoint

type GraphEndpoint struct {
	Id       int64
	Endpoint string
}

graph.endpoint

type GraphEndpointCounter

type GraphEndpointCounter struct {
	Id         int64
	EndpointId int64
	Counter    string
}

graph.endpoint_counter

type GraphTagEndpoint

type GraphTagEndpoint struct {
	Id         int64
	Tag        string
	EndpointId int64
}

graph.tag_endpoint

type IterateControl

type IterateControl byte

The control of iterating

type ResultExt

type ResultExt struct {
	// contains filtered or unexported fields
}

Extension for sql.Result

func ToResultExt

func ToResultExt(result sql.Result) *ResultExt

Converts sql.Result to ResultExt

func (*ResultExt) LastInsertId

func (resultExt *ResultExt) LastInsertId() int64

Gets last id of insert with panic instead of returned error

func (*ResultExt) RowsAffected

func (resultExt *ResultExt) RowsAffected() int64

Gets last number of affected rows with panic instead of returned error

type RowCallback

type RowCallback interface {
	ResultRow(row *sql.Row)
}

The interface of row callback for sql package

type RowCallbackFunc

type RowCallbackFunc func(*sql.Row)

The function object delegates the RowCallback interface

func (RowCallbackFunc) ResultRow

func (callbackFunc RowCallbackFunc) ResultRow(row *sql.Row)

type RowExt

type RowExt sql.Row

Extension for sql.Row

func ToRowExt

func ToRowExt(row *sql.Row) *RowExt

Converts the sql.Row to RowExt

func (*RowExt) Scan

func (rowExt *RowExt) Scan(dest ...interface{})

Scans the values of row into variables, with panic instead of returned error

type RowsCallback

type RowsCallback interface {
	NextRow(row *sql.Rows) IterateControl
}

The interface of rows callback for sql package

type RowsCallbackFunc

type RowsCallbackFunc func(*sql.Rows) IterateControl

The function object delegates the RowsCallback interface

func (RowsCallbackFunc) NextRow

func (callbackFunc RowsCallbackFunc) NextRow(rows *sql.Rows) IterateControl

type RowsExt

type RowsExt sql.Rows

Extension for sql.Rows

func ToRowsExt

func ToRowsExt(rows *sql.Rows) *RowsExt

converts the sql.Rows to RowsExt

func (*RowsExt) Columns

func (rowsExt *RowsExt) Columns() []string

Gets columns, with panic instead of returned error

func (*RowsExt) Scan

func (rowsExt *RowsExt) Scan(dest ...interface{})

Scans the values of row into variables, with panic instead of returned error

type StmtExt

type StmtExt sql.Stmt

Extension for sql.Stmt

func ToStmtExt

func ToStmtExt(stmt *sql.Stmt) *StmtExt

Converts sql.Stmt to StmtExt

func (*StmtExt) Exec

func (stmtExt *StmtExt) Exec(args ...interface{}) sql.Result

Exec with panic instead of error

func (*StmtExt) Query

func (stmtExt *StmtExt) Query(args ...interface{}) *sql.Rows

Query with panic instead of error

type TxCallback

type TxCallback interface {
	InTx(tx *sql.Tx) TxFinale
}

The interface of transaction callback for sql package

func BuildTxForSqls

func BuildTxForSqls(queries ...string) TxCallback

BuildTxForSqls builds function for exeuction of multiple SQLs

type TxCallbackFunc

type TxCallbackFunc func(*sql.Tx) TxFinale

The function object delegates the TxCallback interface

func (TxCallbackFunc) InTx

func (callbackFunc TxCallbackFunc) InTx(tx *sql.Tx) TxFinale

type TxExt

type TxExt sql.Tx

Extnesion for sql.Tx

func ToTxExt

func ToTxExt(tx *sql.Tx) *TxExt

Converts sql.Tx to TxExt

func (*TxExt) Commit

func (txExt *TxExt) Commit()

Commit with panic instead of returned error

func (*TxExt) Exec

func (txExt *TxExt) Exec(query string, args ...interface{}) sql.Result

Commit with panic instead of returned error

func (*TxExt) Prepare

func (txExt *TxExt) Prepare(query string) *sql.Stmt

Prepare with panic instead of returned error

func (*TxExt) Query

func (txExt *TxExt) Query(query string, args ...interface{}) *sql.Rows

Query with panic instead of returned error

func (*TxExt) Rollback

func (txExt *TxExt) Rollback()

Rollback with panic instead of returned error

type TxFinale

type TxFinale byte
const (
	TxCommit   TxFinale = 1
	TxRollback TxFinale = 2
)

Directories

Path Synopsis
nqm

Jump to

Keyboard shortcuts

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