xsql

package
v0.0.0-...-9307e03 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRecord   = xerror.ErrNotFound.Msg("no record found")
	ErrDuplicate  = xerror.ErrDuplicate.Msg("duplicate entry")
	ErrOutOfRange = xerror.ErrDataTooLong.Msg("out of range")
)

Functions

func ConvertError

func ConvertError(err error) error

转换not found和duplicate entry两种错误

func GetDsn

func GetDsn(user, pass, addr, dbName string) string

func GetFieldSlice

func GetFieldSlice(v any, skip ...string) []string

func GetFields

func GetFields(v any, skip ...string) string

func GetFields2WithSkip

func GetFields2WithSkip(v any, skip ...string) (string, string)

同时返回参数化参数?

func IsCriticalErr

func IsCriticalErr(err error) bool

func IsDuplicate

func IsDuplicate(err error) bool

func IsMildErr

func IsMildErr(err error) bool

func IsNoRecord

func IsNoRecord(err error) bool

func SQLStateEqual

func SQLStateEqual(src [5]byte, target SQLState) bool

func SelectFields

func SelectFields(v any, targets ...string) string

func SelectFields2

func SelectFields2(v any, targets ...string) (string, string)

Types

type DB

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

对db的封装

func New

func New(s sqlx.SqlConn) *DB

func NewFromEnv

func NewFromEnv() *DB

func (*DB) Close

func (d *DB) Close() error

func (*DB) Conn

func (d *DB) Conn() sqlx.SqlConn

func (*DB) Exec

func (d *DB) Exec(query string, args ...any) (sql.Result, error)

func (*DB) ExecCtx

func (d *DB) ExecCtx(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*DB) Prepare

func (d *DB) Prepare(query string) (sqlx.StmtSession, error)

func (*DB) PrepareCtx

func (d *DB) PrepareCtx(ctx context.Context, query string) (sqlx.StmtSession, error)

func (*DB) QueryRow

func (d *DB) QueryRow(v any, query string, args ...any) error

func (*DB) QueryRowCtx

func (d *DB) QueryRowCtx(ctx context.Context, v any, query string, args ...any) error

func (*DB) QueryRowPartial

func (d *DB) QueryRowPartial(v any, query string, args ...any) error

func (*DB) QueryRowPartialCtx

func (d *DB) QueryRowPartialCtx(ctx context.Context, v any, query string, args ...any) error

func (*DB) QueryRows

func (d *DB) QueryRows(v any, query string, args ...any) error

func (*DB) QueryRowsCtx

func (d *DB) QueryRowsCtx(ctx context.Context, v any, query string, args ...any) error

func (*DB) QueryRowsPartial

func (d *DB) QueryRowsPartial(v any, query string, args ...any) error

func (*DB) QueryRowsPartialCtx

func (d *DB) QueryRowsPartialCtx(ctx context.Context, v any, query string, args ...any) error

func (*DB) Transact

func (d *DB) Transact(ctx context.Context, fn func(ctx context.Context) error) error

type SQLState

type SQLState string
var (
	SQLStateOutOfRange SQLState = "22003" // [5]uint8{50, 50, 48, 48, 51}
)

type TransactFunc

type TransactFunc func(ctx context.Context, s sqlx.Session) error

Jump to

Keyboard shortcuts

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