Documentation ¶
Index ¶
- Variables
- func BeginTx(ctx context.Context, serializable bool) context.Context
- func CloseTx(ctx context.Context)
- func CoalseceBool(v sql.NullBool, dv bool) bool
- func CoalseceByte(v sql.NullByte, dv byte) byte
- func CoalseceFloat64(v sql.NullFloat64, dv float64) float64
- func CoalseceInt16(v sql.NullInt16, dv int16) int16
- func CoalseceInt32(v sql.NullInt32, dv int32) int32
- func CoalseceInt64(v sql.NullInt64, dv int64) int64
- func CoalseceString(v sql.NullString, dv string) string
- func CoalseceTime(v sql.NullTime, dv time.Time) time.Time
- func CommitTx(ctx context.Context)
- func EscapeLikeString(s utils.String) utils.String
- func Exec[T int | int8 | int16 | int32 | int64](ctx context.Context, query string, args ...any) (T, error)
- func ExecLastInsertId[T int | int8 | int16 | int32 | int64](ctx context.Context, query string, args ...any) (T, error)
- func InitMySqlDb(addr, username, password, dbname string) error
- func InsertBatch(ctx context.Context, query string, rows ...[]any) (int64, error)
- func JoinInInt[T int | int8 | int16 | int32 | int64](args []T) string
- func JoinInString(args []string) string
- func ParseNullInt16(s string) sql.NullInt16
- func ParseNullInt32(s string) sql.NullInt32
- func ParseNullInt64(s string) sql.NullInt64
- func Query[...](ctx context.Context, query string, args ...any) (T, error)
- func QueryKeyValueMap[T bool | int | int8 | int16 | int32 | int64 | string](ctx context.Context, query string, args ...any) (map[string]T, error)
- func QueryList[...](ctx context.Context, query string, args ...any) ([]T, error)
- func QueryObj[T any](ctx context.Context, query string, rh RowHandler[T], args ...any) (*T, error)
- func QueryObjList[T any](ctx context.Context, query string, rh RowHandler[T], args ...any) ([]*T, error)
- func Version() string
- type DbRow
- type DynamicSqlBuilder
- type InsertSqlBuilder
- type KeyValuePairMapper
- type KeyValuePairPo
- type RowHandler
- type SqlBuilder
- func (b *SqlBuilder) Append(sql string) *SqlBuilder
- func (b *SqlBuilder) AppendIf(sql string, p bool) *SqlBuilder
- func (b *SqlBuilder) Dynamic(prefix, suffix, joint string) *DynamicSqlBuilder
- func (b *SqlBuilder) Inserter(quote string) *InsertSqlBuilder
- func (b *SqlBuilder) Limit(startRowIndex, maximumRows int) *SqlBuilder
- func (b *SqlBuilder) OrderBy(sql ...string) *SqlBuilder
- func (b *SqlBuilder) Set() *DynamicSqlBuilder
- func (b *SqlBuilder) String() string
- func (b *SqlBuilder) Where() *DynamicSqlBuilder
Constants ¶
This section is empty.
Variables ¶
View Source
var (
SQL_ARG_PATTERN = regexp.MustCompile(`:[1|2|3|4|5|6|7|8|9](0|1|2|3|4|5|6|7|8|9)?`)
)
Functions ¶
func CoalseceFloat64 ¶ added in v0.0.8
func CoalseceFloat64(v sql.NullFloat64, dv float64) float64
func CoalseceString ¶ added in v0.0.8
func CoalseceString(v sql.NullString, dv string) string
func EscapeLikeString ¶ added in v0.0.13
EscapeLikeString 对LIKE参数进行转义。
func Exec ¶
func Exec[T int | int8 | int16 | int32 | int64](ctx context.Context, query string, args ...any) (T, error)
Exec 执行指定的sql并返回受影响的行数。
func ExecLastInsertId ¶
func ExecLastInsertId[T int | int8 | int16 | int32 | int64](ctx context.Context, query string, args ...any) (T, error)
ExecLastInsertId 执行指定的sql并返回插入的ID值。只要sql执行成功,即使未插入任何记录也不会返回错误。
func InitMySqlDb ¶
InitMySqlDb 初始化MySql数据源。
func InsertBatch ¶
insertBatch 批量插入记录。 返回成功插入的记录数。
func JoinInString ¶
func ParseNullInt16 ¶ added in v0.0.11
func ParseNullInt32 ¶ added in v0.0.11
func ParseNullInt64 ¶ added in v0.0.11
func QueryKeyValueMap ¶
func QueryObjList ¶
func QueryObjList[T any](ctx context.Context, query string, rh RowHandler[T], args ...any) ([]*T, error)
QueryObjList 查询对象列表。
Types ¶
type DynamicSqlBuilder ¶ added in v0.0.7
type DynamicSqlBuilder struct {
// contains filtered or unexported fields
}
func (*DynamicSqlBuilder) Append ¶ added in v0.0.7
func (d *DynamicSqlBuilder) Append(sql string) *DynamicSqlBuilder
func (*DynamicSqlBuilder) AppendIf ¶ added in v0.0.7
func (d *DynamicSqlBuilder) AppendIf(sql string, p bool) *DynamicSqlBuilder
func (*DynamicSqlBuilder) End ¶ added in v0.0.7
func (d *DynamicSqlBuilder) End() *SqlBuilder
type InsertSqlBuilder ¶ added in v0.0.17
type InsertSqlBuilder struct {
// contains filtered or unexported fields
}
func (*InsertSqlBuilder) Append ¶ added in v0.0.17
func (d *InsertSqlBuilder) Append(col string) *InsertSqlBuilder
func (*InsertSqlBuilder) AppendIf ¶ added in v0.0.17
func (d *InsertSqlBuilder) AppendIf(col string, p bool) *InsertSqlBuilder
func (*InsertSqlBuilder) End ¶ added in v0.0.17
func (d *InsertSqlBuilder) End() *SqlBuilder
type KeyValuePairMapper ¶
func (*KeyValuePairMapper[T]) Scan ¶
func (m *KeyValuePairMapper[T]) Scan(r DbRow) (*KeyValuePairPo[T], error)
type KeyValuePairPo ¶
type RowHandler ¶
type SqlBuilder ¶ added in v0.0.7
type SqlBuilder struct {
// contains filtered or unexported fields
}
func NewSqlBuilder ¶ added in v0.0.7
func NewSqlBuilder(sql string) *SqlBuilder
func (*SqlBuilder) Append ¶ added in v0.0.7
func (b *SqlBuilder) Append(sql string) *SqlBuilder
func (*SqlBuilder) AppendIf ¶ added in v0.0.7
func (b *SqlBuilder) AppendIf(sql string, p bool) *SqlBuilder
func (*SqlBuilder) Dynamic ¶ added in v0.0.7
func (b *SqlBuilder) Dynamic(prefix, suffix, joint string) *DynamicSqlBuilder
func (*SqlBuilder) Inserter ¶ added in v0.0.17
func (b *SqlBuilder) Inserter(quote string) *InsertSqlBuilder
func (*SqlBuilder) Limit ¶ added in v0.0.7
func (b *SqlBuilder) Limit(startRowIndex, maximumRows int) *SqlBuilder
Limit 创建分页参数SQL。 startRowIndex 起始行索引,从0开始。 maximumRows 最大行数,如果小于等于0,则不添加LIMIT子句。
func (*SqlBuilder) OrderBy ¶ added in v0.0.7
func (b *SqlBuilder) OrderBy(sql ...string) *SqlBuilder
func (*SqlBuilder) Set ¶ added in v0.0.17
func (b *SqlBuilder) Set() *DynamicSqlBuilder
func (*SqlBuilder) String ¶ added in v0.0.7
func (b *SqlBuilder) String() string
func (*SqlBuilder) Where ¶ added in v0.0.7
func (b *SqlBuilder) Where() *DynamicSqlBuilder
Click to show internal directories.
Click to hide internal directories.