database

package
v0.0.0-...-8bbd0fc Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInsert

func BuildInsert(tableName string, obj interface{}) string

BuildInsert creates an insert query for given table name and accompanying struct returning a query string with placeholders ? for mysql

func BuildUpdate

func BuildUpdate(tableName string, obj interface{}) string

BuildUpdate creates an update query for given table name and accompanying struct returning a query string with placeholders ? for mysql

func Exec

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

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func ExecContext

func ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.

func Get

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

Get scans into single dest

func GetArguments

func GetArguments(s interface{}) []interface{}

GetArguments receives a struct and puts the struct values into an array so that it can be passed into a query

func GetArgumentsForUpdate

func GetArgumentsForUpdate(s interface{}) []interface{}

GetArgumentsForUpdate receives a struct and puts the struct values into an array so that it can be passed into a query

func Query

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

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func QueryContext

func QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func QueryRow

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

QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.

func QueryRowContext

func QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.

func Select

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

Select scans dest array

Types

type IntBool

type IntBool struct {
	Bool  bool
	Valid bool
}

IntBool is a type wrapper for tinyint columns used as bools

func (IntBool) MarshalJSON

func (n IntBool) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON bool

func (*IntBool) Scan

func (n *IntBool) Scan(value interface{}) error

Scan converts 1 to true and 0 to false

func (IntBool) String

func (n IntBool) String() string

String is the Stringer interface for IntBool

func (*IntBool) UnmarshalJSON

func (n *IntBool) UnmarshalJSON(data []byte) error

UnmarshalJSON converts 1, 0, true, false to bool value from JSON or nil on null

func (IntBool) Value

func (n IntBool) Value() (driver.Value, error)

Value returns 0 for false and 1 for true

type NullBool

type NullBool struct {
	sql.NullBool
}

NullBool is a wrapper for sql.NullBool for JSON methods to remove Valid

func (*NullBool) MarshalJSON

func (n *NullBool) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON bool

func (NullBool) String

func (n NullBool) String() string

type NullFloat64

type NullFloat64 struct {
	sql.NullFloat64
}

NullFloat64 is a wrapper for sql.NullFLoat64 for JSON methods to remove Valid

func (NullFloat64) MarshalJSON

func (n NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON float

func (NullFloat64) String

func (n NullFloat64) String() string

type NullInt64

type NullInt64 struct {
	sql.NullInt64
}

NullInt64 is a wrapper for sql.NullInt64 for JSON methods to remove Valid

func ToNullInt

func ToNullInt(value int64, setValidOnEmpty bool) NullInt64

func (NullInt64) MarshalJSON

func (n NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON int

func (NullInt64) String

func (n NullInt64) String() string

type NullString

type NullString struct {
	sql.NullString
}

NullString is a wrapper for sql.NullString for JSON methods to remove Valid

func ToNullString

func ToNullString(value string, setValidOnEmpty bool) NullString

func (NullString) MarshalJSON

func (n NullString) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON string

func (*NullString) Scan

func (ns *NullString) Scan(value interface{}) error

Scan implements the Scanner interface for NullString

type NullTime

type NullTime struct {
	mysql.NullTime
}

NullTime is a wrapper for mysql.NullTime for JSON methods to remove Valid

func ToNullTime

func ToNullTime(value time.Time, setValidOnEmpty bool) NullTime

func (NullTime) MarshalJSON

func (n NullTime) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to null or JSON time

func (NullTime) String

func (n NullTime) String() string

Jump to

Keyboard shortcuts

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