Documentation ¶
Index ¶
- Variables
- func Count(ctx context.Context, q Queryable, table string, filter PaginateFilter) (int, error)
- func CreateSqliteDatabaseSchemaString(ctx context.Context, db Queryable) (string, error)
- func HashGoSqliteSchema(ctx context.Context, schemaStr string) (string, error)
- func HashMattnSqliteSchema(ctx context.Context, schemaStr string) (string, error)
- func HashSqliteDatabase(ctx context.Context, db Queryable) (string, error)
- func InsertAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string, ...) (TData, error)
- func InsertMultiple[TData any](ctx context.Context, q Queryable, tableName string, vArr []TData, maxBatch int) ([]sql.Result, error)
- func InsertSingle[TData any](ctx context.Context, q Queryable, tableName string, v TData) (sql.Result, error)
- func PPID() string
- func Paginate[TData any](ctx context.Context, q Queryable, table string, filter PaginateFilter, ...) ([]TData, pag.Pagination, error)
- func QueryAll[TData any](ctx context.Context, q Queryable, sql string, pp PP, mode StructScanMode, ...) ([]TData, error)
- func QuerySingle[TData any](ctx context.Context, q Queryable, sql string, pp PP, mode StructScanMode, ...) (TData, error)
- func QuerySingleOpt[TData any](ctx context.Context, q Queryable, sqlstr string, pp PP, mode StructScanMode, ...) (*TData, error)
- func ScanAll[TData any](ctx context.Context, q Queryable, rows *sqlx.Rows, mode StructScanMode, ...) ([]TData, error)
- func ScanSingle[TData any](ctx context.Context, q Queryable, rows *sqlx.Rows, mode StructScanMode, ...) (TData, error)
- func UpdateAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string, ...) (TData, error)
- func UpdateSingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string) (sql.Result, error)
- type AutoJson
- type DB
- type DBDataConstraint
- type DBOptions
- type DBTypeConverter
- type DatabaseConvertible
- type FilterSort
- type JsonArr
- type JsonObj
- type Listener
- func NewPostExecListener(f func(txID *uint16, sqlOriginal string, sqlReal string, params PP)) Listener
- func NewPostListener(...) Listener
- func NewPostPingListener(f func(result error)) Listener
- func NewPostQueryListener(f func(txID *uint16, sqlOriginal string, sqlReal string, params PP)) Listener
- func NewPostTxBeginListener(f func(txid uint16, result error)) Listener
- func NewPostTxCommitListener(f func(txid uint16, result error)) Listener
- func NewPostTxRollbackListener(f func(txid uint16, result error)) Listener
- func NewPreExecListener(f func(ctx context.Context, txID *uint16, sql *string, params *PP) error) Listener
- func NewPreListener(...) Listener
- func NewPrePingListener(f func(ctx context.Context) error) Listener
- func NewPreQueryListener(f func(ctx context.Context, txID *uint16, sql *string, params *PP) error) Listener
- func NewPreTxBeginListener(f func(ctx context.Context, txid uint16) error) Listener
- func NewPreTxCommitListener(f func(txid uint16) error) Listener
- func NewPreTxRollbackListener(f func(txid uint16) error) Listener
- type PP
- func BuildInsertMultipleStatement[TData any](q Queryable, tableName string, vArr []TData) (string, PP, error)
- func BuildInsertStatement[TData any](q Queryable, tableName string, obj TData) (string, PP, error)
- func BuildUpdateStatement[TData any](q Queryable, tableName string, obj TData, idColumn string) (string, PP, error)
- func Join(pps ...PP) PP
- type PaginateFilter
- type Queryable
- type StructScanMode
- type StructScanSafety
- type StructScanner
- type Tx
- type TxStatus
Constants ¶
This section is empty.
Variables ¶
View Source
var CommentTrimmer = NewPreListener(fnTrimComments)
View Source
var ConverterBoolToBit = NewDBTypeConverter[bool, int64](func(v bool) (int64, error) { return langext.Conditional(v, int64(1), int64(0)), nil }, func(v int64) (bool, error) { if v == 0 { return false, nil } if v == 1 { return true, nil } return false, errors.New(fmt.Sprintf("invalid valud for boolean: '%d'", v)) })
View Source
var ConverterExErrCategoryToString = NewDBTypeConverter[exerr.ErrorCategory, string](func(v exerr.ErrorCategory) (string, error) { return v.Category, nil }, func(v string) (exerr.ErrorCategory, error) { for _, cat := range exerr.AllCategories { if cat.Category == v { return cat, nil } } return exerr.CatUser, errors.New("failed to convert '" + v + "' to exerr.ErrorCategory") })
View Source
var ConverterExErrSeverityToString = NewDBTypeConverter[exerr.ErrorSeverity, string](func(v exerr.ErrorSeverity) (string, error) { return v.Severity, nil }, func(v string) (exerr.ErrorSeverity, error) { for _, sev := range exerr.AllSeverities { if sev.Severity == v { return sev, nil } } return exerr.SevErr, errors.New("failed to convert '" + v + "' to exerr.ErrorSeverity") })
View Source
var ConverterExErrTypeToString = NewDBTypeConverter[exerr.ErrorType, string](func(v exerr.ErrorType) (string, error) { return v.Key, nil }, func(v string) (exerr.ErrorType, error) { for _, etp := range exerr.ListRegisteredTypes() { if etp.Key == v { return etp, nil } } return exerr.NewType(v, nil), nil })
View Source
var ConverterJsonArrToString = NewAutoDBTypeConverter(JsonArr{})
View Source
var ConverterJsonObjToString = NewAutoDBTypeConverter(JsonObj{})
View Source
var ConverterRFC339NanoTimeToString = NewDBTypeConverter[rfctime.RFC3339NanoTime, string](func(v rfctime.RFC3339NanoTime) (string, error) { return v.Time().In(time.UTC).Format("2006-01-02 15:04:05.999999999"), nil }, func(v string) (rfctime.RFC3339NanoTime, error) { t, err := time.ParseInLocation("2006-01-02 15:04:05.999999999", v, time.UTC) if err != nil { return rfctime.RFC3339NanoTime{}, err } return rfctime.NewRFC3339Nano(t), nil })
ConverterRFC339NanoTimeToString Does not really use RFC339 - but sqlite does not understand timezones and the `T` delimiter
View Source
var ConverterRFC339TimeToString = NewDBTypeConverter[rfctime.RFC3339Time, string](func(v rfctime.RFC3339Time) (string, error) { return v.Time().In(time.UTC).Format("2006-01-02 15:04:05"), nil }, func(v string) (rfctime.RFC3339Time, error) { t, err := time.Parse("2006-01-02 15:04:05", v) if err != nil { return rfctime.RFC3339Time{}, err } return rfctime.NewRFC3339(t), nil })
ConverterRFC339TimeToString Does not really use RFC339 - but sqlite does not understand timezones and the `T` delimiter
View Source
var ConverterRFCDateToString = NewDBTypeConverter[rfctime.Date, string](func(v rfctime.Date) (string, error) { return fmt.Sprintf("%04d-%02d-%02d", v.Year, v.Month, v.Day), nil }, func(v string) (rfctime.Date, error) { split := strings.Split(v, "-") if len(split) != 3 { return rfctime.Date{}, errors.New("invalid date format: " + v) } year, err := strconv.ParseInt(split[0], 10, 32) if err != nil { return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error()) } month, err := strconv.ParseInt(split[0], 10, 32) if err != nil { return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error()) } day, err := strconv.ParseInt(split[0], 10, 32) if err != nil { return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error()) } return rfctime.Date{Year: int(year), Month: int(month), Day: int(day)}, nil })
View Source
var ConverterRFCSecondsF64ToString = NewDBTypeConverter[rfctime.SecondsF64, float64](func(v rfctime.SecondsF64) (float64, error) { return v.Seconds(), nil }, func(v float64) (rfctime.SecondsF64, error) { return rfctime.NewSecondsF64(timeext.FromSeconds(v)), nil })
View Source
var ConverterRFCTimeToString = NewDBTypeConverter[rfctime.Time, string](func(v rfctime.Time) (string, error) { return v.SerializeShort(), nil }, func(v string) (rfctime.Time, error) { res := rfctime.Time{} err := res.Deserialize(v) if err != nil { return rfctime.Time{}, err } return res, nil })
View Source
var ConverterRFCUnixMilliTimeToUnixMillis = NewDBTypeConverter[rfctime.UnixMilliTime, int64](func(v rfctime.UnixMilliTime) (int64, error) { return v.UnixMilli(), nil }, func(v int64) (rfctime.UnixMilliTime, error) { return rfctime.NewUnixMilli(time.UnixMilli(v)), nil })
View Source
var ConverterRFCUnixNanoTimeToUnixNanos = NewDBTypeConverter[rfctime.UnixNanoTime, int64](func(v rfctime.UnixNanoTime) (int64, error) { return v.UnixNano(), nil }, func(v int64) (rfctime.UnixNanoTime, error) { return rfctime.NewUnixNano(time.Unix(0, v)), nil })
Functions ¶
func CreateSqliteDatabaseSchemaString ¶ added in v0.0.125
func HashGoSqliteSchema ¶ added in v0.0.350
HashGoSqliteSchema use if mattn/go-sqlite3
func HashMattnSqliteSchema ¶ added in v0.0.350
HashMattnSqliteSchema use if github.com/glebarez/go-sqlite
func HashSqliteDatabase ¶ added in v0.0.126
func InsertAndQuerySingle ¶ added in v0.0.386
func InsertAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string, mode StructScanMode, sec StructScanSafety) (TData, error)
func InsertMultiple ¶ added in v0.0.383
func InsertSingle ¶ added in v0.0.125
func Paginate ¶ added in v0.0.372
func Paginate[TData any](ctx context.Context, q Queryable, table string, filter PaginateFilter, scanMode StructScanMode, scanSec StructScanSafety, page int, limit *int) ([]TData, pag.Pagination, error)
func QueryAll ¶ added in v0.0.125
func QueryAll[TData any](ctx context.Context, q Queryable, sql string, pp PP, mode StructScanMode, sec StructScanSafety) ([]TData, error)
func QuerySingle ¶ added in v0.0.125
func QuerySingle[TData any](ctx context.Context, q Queryable, sql string, pp PP, mode StructScanMode, sec StructScanSafety) (TData, error)
func QuerySingleOpt ¶ added in v0.0.384
func QuerySingleOpt[TData any](ctx context.Context, q Queryable, sqlstr string, pp PP, mode StructScanMode, sec StructScanSafety) (*TData, error)
func ScanAll ¶ added in v0.0.34
func ScanAll[TData any](ctx context.Context, q Queryable, rows *sqlx.Rows, mode StructScanMode, sec StructScanSafety, close bool) ([]TData, error)
func ScanSingle ¶ added in v0.0.34
func ScanSingle[TData any](ctx context.Context, q Queryable, rows *sqlx.Rows, mode StructScanMode, sec StructScanSafety, close bool) (TData, error)
func UpdateAndQuerySingle ¶ added in v0.0.385
func UpdateAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string, mode StructScanMode, sec StructScanSafety) (TData, error)
Types ¶
type AutoJson ¶ added in v0.0.399
type AutoJson[T any] struct { Value T }
func (AutoJson[T]) MarshalToDB ¶ added in v0.0.399
type DB ¶
type DBDataConstraint ¶ added in v0.0.399
type DBDataConstraint interface { string | langext.NumberConstraint | []byte }
type DBTypeConverter ¶ added in v0.0.127
type DBTypeConverter interface { ModelTypeString() string DBTypeString() string ModelToDB(v any) (any, error) DBToModel(v any) (any, error) }
func NewAutoDBTypeConverter ¶ added in v0.0.399
func NewAutoDBTypeConverter[TDBData DBDataConstraint, TModelData DatabaseConvertible[TModelData, TDBData]](obj TModelData) DBTypeConverter
func NewDBTypeConverter ¶ added in v0.0.127
func NewDBTypeConverter[TModelData any, TDBData DBDataConstraint](todb func(v TModelData) (TDBData, error), tomodel func(v TDBData) (TModelData, error)) DBTypeConverter
type DatabaseConvertible ¶ added in v0.0.399
type DatabaseConvertible[TModelData any, TDBData DBDataConstraint] interface { MarshalToDB(v TModelData) (TDBData, error) UnmarshalToModel(v TDBData) (TModelData, error) }
type FilterSort ¶ added in v0.0.372
type FilterSort struct { Field string Direction ct.SortDirection }
type JsonObj ¶ added in v0.0.355
func (JsonObj) MarshalToDB ¶ added in v0.0.399
type Listener ¶
type Listener interface { PrePing(ctx context.Context) error PreTxBegin(ctx context.Context, txid uint16) error PreTxCommit(txid uint16) error PreTxRollback(txid uint16) error PreQuery(ctx context.Context, txID *uint16, sql *string, params *PP) error PreExec(ctx context.Context, txID *uint16, sql *string, params *PP) error PostPing(result error) PostTxBegin(txid uint16, result error) PostTxCommit(txid uint16, result error) PostTxRollback(txid uint16, result error) PostQuery(txID *uint16, sqlOriginal string, sqlReal string, params PP) PostExec(txID *uint16, sqlOriginal string, sqlReal string, params PP) }
func NewPostExecListener ¶ added in v0.0.400
func NewPostListener ¶ added in v0.0.400
func NewPostPingListener ¶ added in v0.0.400
func NewPostQueryListener ¶ added in v0.0.400
func NewPostTxBeginListener ¶ added in v0.0.400
func NewPostTxCommitListener ¶ added in v0.0.400
func NewPostTxRollbackListener ¶ added in v0.0.400
func NewPreExecListener ¶ added in v0.0.400
func NewPreListener ¶ added in v0.0.400
func NewPrePingListener ¶ added in v0.0.400
func NewPreQueryListener ¶ added in v0.0.400
func NewPreTxBeginListener ¶ added in v0.0.400
func NewPreTxCommitListener ¶ added in v0.0.400
func NewPreTxRollbackListener ¶ added in v0.0.400
type PP ¶
func BuildInsertMultipleStatement ¶ added in v0.0.383
func BuildInsertStatement ¶ added in v0.0.373
func BuildUpdateStatement ¶ added in v0.0.358
type PaginateFilter ¶ added in v0.0.372
type PaginateFilter interface { SQL(params PP) (filterClause string, joinClause string, joinTables []string) Sort() []FilterSort }
func NewPaginateFilter ¶ added in v0.0.389
func NewPaginateFilter(sql func(params PP) (filterClause string, joinClause string, joinTables []string), sort []FilterSort) PaginateFilter
func NewSimplePaginateFilter ¶ added in v0.0.389
func NewSimplePaginateFilter(filterClause string, filterParams PP, sort []FilterSort) PaginateFilter
type StructScanMode ¶ added in v0.0.44
type StructScanMode string
const ( SModeFast StructScanMode = "FAST" // Use default sq.Scan, does not work with joined/resolved types and/or custom value converter SModeExtended StructScanMode = "EXTENDED" // Fully featured perhaps (?) a tiny bit slower - default )
type StructScanSafety ¶ added in v0.0.44
type StructScanSafety string
const ( Safe StructScanSafety = "SAFE" // return error for missing fields Unsafe StructScanSafety = "UNSAFE" // ignore missing fields )
type StructScanner ¶ added in v0.0.44
func NewStructScanner ¶ added in v0.0.44
func NewStructScanner(rows *sqlx.Rows, unsafe bool) *StructScanner
func (*StructScanner) Start ¶ added in v0.0.44
func (r *StructScanner) Start(dest any) error
func (*StructScanner) StructScanBase ¶ added in v0.0.44
func (r *StructScanner) StructScanBase(dest any) error
StructScanBase forked from github.com/jmoiron/sqlx@v1.3.5/sqlx.go without (relevant) changes
func (*StructScanner) StructScanExt ¶ added in v0.0.44
func (r *StructScanner) StructScanExt(q Queryable, dest any) error
StructScanExt forked from github.com/jmoiron/sqlx@v1.3.5/sqlx.go does also work with nullabel structs (from LEFT JOIN's) does also work with custom value converters
Click to show internal directories.
Click to hide internal directories.