Documentation ¶
Index ¶
- Variables
- func BuildInsertQuery(table string, rows ...[]ColumnValue) (query string, args []any)
- func BuildSelectQuery(table string, columns, joins []string, whereClause string) string
- func InClauseQuestionMarks(n int) string
- func IsErrDuplicateErr(err error) bool
- func NilIfEmptyString(s string) interface{}
- func Transact(ctx context.Context, db *sql.DB, f func(tx *sql.Tx) error) error
- type ColumnValue
- type NullBool
- type NullFloat64
- type NullInt32
- type NullString
- type NullTime
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateRow = errors.New("1062: Duplicate row")
ErrDuplicateRow is for when MySQL returns a 1062 error code.
Functions ¶
func BuildInsertQuery ¶
func BuildInsertQuery(table string, rows ...[]ColumnValue) (query string, args []any)
BuildInsertQuery prepares an insert sql statement on table. It returns the query string and an array of args for, for example, sql.DB's Exec.
func BuildSelectQuery ¶
BuildSelectQuery prepares a select sql statement. columns and whereClause could be empty strings.
func InClauseQuestionMarks ¶
In question mark returns a string of the format "(?, ?, ?)" where there are n question marks. It panics if n <= 0.
func IsErrDuplicateErr ¶
IsErrDuplicateErr checks MySQL/MariaDB error string to see a '1062' can be found.
func NilIfEmptyString ¶
func NilIfEmptyString(s string) interface{}
NilIfEmptyString returns nil if s is empty. Otherwise it returns s.
Types ¶
type ColumnValue ¶
ColumnValue represents value in a table's row and the column it belongs to.
type NullBool ¶
NullBool represents a bool that may be null. NullBool implements the Scanner interface so it can be used as a scan destination, similar to NullString.
Unlike sql.NullBool, NullBool marshals into JSON properly (with the JSON value being null if Valid is false).
func NewNullBool ¶
func NewNullBool(t interface{}) NullBool
NewNullBool returns a NullBool with Valid set to true is t is of type bool.
func (NullBool) MarshalJSON ¶
MarshalJSON implements json.Marshalar interface.
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshalar interface.
type NullFloat64 ¶
type NullFloat64 struct {
sql.NullFloat64
}
NullFloat64 represents a float64 that may be null. NullFloat64 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
Unlike sql.NullFloat64, NullFloat64 marshals into JSON properly (with the JSON value being null if Valid is false).
func NewNullFloat64 ¶
func NewNullFloat64(fl interface{}) NullFloat64
NewNullFloat64 returns a NullFloat64 with Valid set to true if fl is a float64.
func (NullFloat64) MarshalJSON ¶
func (i NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshalar interface.
func (*NullFloat64) UnmarshalJSON ¶
func (i *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshalar interface.
type NullInt32 ¶
NullInt32 represents an int32 that may be null. NullInt32 implements the Scanner interface so it can be used as a scan destination, similar to NullString.
Unlike sql.NullInt32, NullInt32 marshals into JSON properly (with the JSON value being null if Valid is false).
func NewNullInt32 ¶
func NewNullInt32(t interface{}) NullInt32
NewNullInt32 returns a NullInt32 with Valid set to true if t is an int.
func (NullInt32) MarshalJSON ¶
MarshalJSON implements json.Marshalar interface.
func (*NullInt32) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshalar interface.
type NullString ¶
type NullString struct {
sql.NullString
}
NullString represents a string that may be null. NullString implements the Scanner interface so it can be used as a scan destination:
Unlike sql.NullString, NullString marshals into JSON properly (with the JSON value being null if Valid is false).
func NewNullString ¶
func NewNullString(str interface{}) NullString
NewNullString returns a NullString with Valid set to true if str is a string.
func (NullString) MarshalJSON ¶
func (s NullString) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshalar interface
func (*NullString) UnmarshalJSON ¶
func (s *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshalar interface
type NullTime ¶
NullTime represents a time.Time that may be null. NullTime implements the Scanner interface so it can be used as a scan destination, similar to NullString.
Unlike sql.NullTime, NullTime marshals into JSON properly (with the JSON value being null if Valid is false).
func NewNullTime ¶
func NewNullTime(t interface{}) NullTime
NewNullTime returns a NullTime with Valid set to true if t is a time.Time.
func (NullTime) MarshalJSON ¶
MarshalJSON implements json.Marshalar interface.
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshalar interface.