Documentation
¶
Index ¶
- Constants
- Variables
- func FetchDictionary[T comparable, V any](fetcher Fetcher) (res map[T]V, err error)
- func FetchMap[K comparable](fetcher Fetcher) (map[K]any, error)
- func FetchMaps[K comparable](fetcher Fetcher) ([]map[K]any, error)
- func FetchModel[T any](fetcher Fetcher, reader func(scanner Scanner) (T, error)) (model T, err error)
- func FetchModelMap[K comparable, T any](fetcher Fetcher, reader func(scanner Scanner) (K, T, error)) (models map[K]T, err error)
- func FetchModels[T any](fetcher Fetcher, reader func(scanner Scanner) (T, error)) (models []T, err error)
- func FreeContext(ctx context.Context, key DbId) context.Context
- func MakeLiteral(v any) string
- func NewContextWithoutCancel(ctx context.Context) context.Context
- func NormalizeSQL(sql string) string
- func Register(name string, driver driver.Driver)
- func SQLFingerprint(sql string) string
- func SafeTemplate(tmpl string, max int) string
- func ToContext(ctx context.Context, scope Scope) context.Context
- type Act
- type Action
- type BeginAction
- type Behavior
- type Builder
- func (that *Builder) Build() (DB, error)
- func (that *Builder) WithBeforeAcquire(fn func(ctx context.Context, conn *pgx.Conn) bool) *Builder
- func (that *Builder) WithConnMaxIdleTime(d time.Duration) *Builder
- func (that *Builder) WithConnMaxLifetime(d time.Duration) *Builder
- func (that *Builder) WithDSN(dsn string) *Builder
- func (that *Builder) WithDatabase(database string) *Builder
- func (that *Builder) WithDatabaseID(id DbId) *Builder
- func (that *Builder) WithErrorBuilder(errors ErrorBuilder) *Builder
- func (that *Builder) WithHost(host string) *Builder
- func (that *Builder) WithMaxIdleConns(max int) *Builder
- func (that *Builder) WithMaxOpenConns(max int) *Builder
- func (that *Builder) WithPassword(password string) *Builder
- func (that *Builder) WithPort(port uint16) *Builder
- func (that *Builder) WithQueryTracer(tracer pgx.QueryTracer) *Builder
- func (that *Builder) WithUser(user string) *Builder
- type ColumnType
- type CommitAction
- type ContextWithoutCancel
- type CustomHandler
- func (that *CustomHandler) BeginTx(ctx context.Context, opts *TxOptions, action BeginAction) (tx Tx, err error)
- func (that *CustomHandler) Commit(ctx context.Context, action CommitAction) error
- func (that *CustomHandler) Exec(ctx context.Context, action ExecAction, query string, args ...interface{}) (res Result, err error)
- func (that *CustomHandler) Query(ctx context.Context, action QueryAction, query string, args ...interface{}) (rows Rows, err error)
- func (that *CustomHandler) QueryRow(ctx context.Context, action QueryRowAction, query string, args ...interface{}) (row Row)
- func (that *CustomHandler) Rollback(ctx context.Context, action RollbackAction) error
- type DB
- type DBStats
- type DSN
- type DbId
- type DummyBehavior
- type DummyHandler
- func (that *DummyHandler) BeginTx(ctx context.Context, opts *TxOptions, action BeginAction) (Tx, error)
- func (that *DummyHandler) Commit(ctx context.Context, action CommitAction) error
- func (that *DummyHandler) Exec(ctx context.Context, action ExecAction, query string, args ...interface{}) (Result, error)
- func (that *DummyHandler) Query(ctx context.Context, action QueryAction, query string, args ...interface{}) (Rows, error)
- func (that *DummyHandler) QueryRow(ctx context.Context, action QueryRowAction, query string, args ...interface{}) Row
- func (that *DummyHandler) Rollback(ctx context.Context, action RollbackAction) error
- type ErrorBuilder
- type ExecAction
- type Fetcher
- type Handler
- type IsolationLevel
- type LogOptions
- type Manipulator
- type Middleware
- type NullBool
- type NullFloat64
- type NullInt64
- type NullString
- type NullTime
- type Out
- type QueryAction
- type QueryRowAction
- type RawBytes
- type Result
- type RollbackAction
- type Row
- type Rows
- type Scanner
- type Scope
- type Tracer
- type Tx
- type TxOptions
Constants ¶
View Source
const ( LevelDefault = sql.LevelDefault LevelReadUncommitted = sql.LevelReadUncommitted LevelReadCommitted = sql.LevelReadCommitted LevelWriteCommitted = sql.LevelWriteCommitted LevelRepeatableRead = sql.LevelRepeatableRead LevelSnapshot = sql.LevelSnapshot LevelSerializable = sql.LevelSerializable LevelLinearizable = sql.LevelLinearizable )
View Source
const DatabaseComponentName = "database"
Variables ¶
View Source
var ( ErrDatabaseIDRequired = fmt.Errorf("DatabaseID is required") ErrPortIsRequired = fmt.Errorf("Port is required") ErrHostIsRequired = fmt.Errorf("Host is required") ErrUserIsRequired = fmt.Errorf("User is required") ErrDatabaseIsRequired = fmt.Errorf("Database is required") )
View Source
var (
ErrNoRows = sql.ErrNoRows
)
View Source
var ErrSkipValue = errors.New("skip value")
View Source
var ErrTxDone = sql.ErrTxDone
Functions ¶
func FetchDictionary ¶
func FetchDictionary[T comparable, V any]( fetcher Fetcher, ) (res map[T]V, err error)
FetchDictionary - returns a dictionary from fetcher
func FetchMap ¶
func FetchMap[K comparable](fetcher Fetcher) (map[K]any, error)
FetchMap - returns a map from fetcher
func FetchMaps ¶
func FetchMaps[K comparable](fetcher Fetcher) ([]map[K]any, error)
FetchMaps - returns a slice of maps from fetcher
func FetchModel ¶
func FetchModel[T any]( fetcher Fetcher, reader func(scanner Scanner) (T, error), ) (model T, err error)
FetchModel - returns a single model from fetcher
func FetchModelMap ¶
func FetchModelMap[K comparable, T any]( fetcher Fetcher, reader func(scanner Scanner) (K, T, error), ) (models map[K]T, err error)
FetchModelMap - returns multiple models from fetcher as a map
func FetchModels ¶
func FetchModels[T any]( fetcher Fetcher, reader func(scanner Scanner) (T, error), ) (models []T, err error)
FetchModels - returns multiple models from fetcher
func FreeContext ¶
FreeContext - Free context from scope
func MakeLiteral ¶
func NormalizeSQL ¶
NormalizeSQL строит нормализованный шаблон SQL: литералы → "?", параметры → "?", числа → "?", схлопывание IN/ANY/VALUES, пробелы и регистр.
func SQLFingerprint ¶
SQLFingerprint возвращает sha256 hex отпечаток нормализованного SQL.
func SafeTemplate ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder() *Builder
func (*Builder) WithBeforeAcquire ¶
func (*Builder) WithConnMaxIdleTime ¶
func (*Builder) WithConnMaxLifetime ¶
func (*Builder) WithDatabase ¶
func (*Builder) WithDatabaseID ¶
func (*Builder) WithErrorBuilder ¶
func (that *Builder) WithErrorBuilder(errors ErrorBuilder) *Builder
func (*Builder) WithMaxIdleConns ¶
func (*Builder) WithMaxOpenConns ¶
func (*Builder) WithPassword ¶
func (*Builder) WithQueryTracer ¶
type ColumnType ¶
type CommitAction ¶
type ContextWithoutCancel ¶
func (*ContextWithoutCancel) Done ¶
func (that *ContextWithoutCancel) Done() <-chan struct{}
type CustomHandler ¶
type CustomHandler struct {
// contains filtered or unexported fields
}
func NewCustomHandler ¶
func NewCustomHandler(behavior Behavior, next Handler) *CustomHandler
func (*CustomHandler) BeginTx ¶
func (that *CustomHandler) BeginTx(ctx context.Context, opts *TxOptions, action BeginAction) (tx Tx, err error)
func (*CustomHandler) Commit ¶
func (that *CustomHandler) Commit(ctx context.Context, action CommitAction) error
func (*CustomHandler) Exec ¶
func (that *CustomHandler) Exec(ctx context.Context, action ExecAction, query string, args ...interface{}) (res Result, err error)
func (*CustomHandler) Query ¶
func (that *CustomHandler) Query(ctx context.Context, action QueryAction, query string, args ...interface{}) (rows Rows, err error)
func (*CustomHandler) QueryRow ¶
func (that *CustomHandler) QueryRow(ctx context.Context, action QueryRowAction, query string, args ...interface{}) (row Row)
func (*CustomHandler) Rollback ¶
func (that *CustomHandler) Rollback(ctx context.Context, action RollbackAction) error
type DB ¶
type DB interface { Scope Pool() *pgxpool.Pool Scope(ctx context.Context) Scope Transact(ctx context.Context, action Act) error Transaction(ctx context.Context, action Action) error TransactionTx(ctx context.Context, action Action, options *TxOptions) error InTransaction(ctx context.Context) bool WithCancel(ctx context.Context) Scope Close() }
type DSN ¶
type DSN struct { Host string Port uint16 User string Password string Database string SSLMode string Charset string }
func DefaultDSN ¶
func DefaultDSN() DSN
type DummyBehavior ¶
type DummyBehavior struct{}
type DummyHandler ¶
type DummyHandler struct{}
func NewDummyHandler ¶
func NewDummyHandler() *DummyHandler
func (*DummyHandler) BeginTx ¶
func (that *DummyHandler) BeginTx(ctx context.Context, opts *TxOptions, action BeginAction) (Tx, error)
func (*DummyHandler) Commit ¶
func (that *DummyHandler) Commit(ctx context.Context, action CommitAction) error
func (*DummyHandler) Exec ¶
func (that *DummyHandler) Exec(ctx context.Context, action ExecAction, query string, args ...interface{}) (Result, error)
func (*DummyHandler) Query ¶
func (that *DummyHandler) Query(ctx context.Context, action QueryAction, query string, args ...interface{}) (Rows, error)
func (*DummyHandler) QueryRow ¶
func (that *DummyHandler) QueryRow(ctx context.Context, action QueryRowAction, query string, args ...interface{}) Row
func (*DummyHandler) Rollback ¶
func (that *DummyHandler) Rollback(ctx context.Context, action RollbackAction) error
type ErrorBuilder ¶
type ExecAction ¶
type Handler ¶
type Handler interface { Query(ctx context.Context, action QueryAction, query string, args ...interface{}) (Rows, error) QueryRow(ctx context.Context, action QueryRowAction, query string, args ...interface{}) Row Exec(ctx context.Context, action ExecAction, query string, args ...interface{}) (Result, error) BeginTx(ctx context.Context, opts *TxOptions, action BeginAction) (Tx, error) Commit(ctx context.Context, action CommitAction) error Rollback(ctx context.Context, action RollbackAction) error }
type IsolationLevel ¶
type IsolationLevel = sql.IsolationLevel
type LogOptions ¶
type Manipulator ¶
type Middleware ¶
type NullFloat64 ¶
type NullFloat64 = sql.NullFloat64
type NullString ¶
type NullString = sql.NullString
type QueryAction ¶
type QueryRowAction ¶
type RollbackAction ¶
type Scope ¶
type Scope interface { DbId(ctx context.Context) DbId WithCancel(ctx context.Context) Scope Exec(ctx context.Context, query string, args ...interface{}) (Result, error) Query(ctx context.Context, query string, args ...interface{}) (Rows, error) QueryRow(ctx context.Context, query string, args ...interface{}) Row Fetch(ctx context.Context, query string, args ...any) Fetcher Begin(ctx context.Context) (Tx, error) BeginTx(ctx context.Context, opts *TxOptions) (Tx, error) }
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
func (*Tracer) TraceQueryEnd ¶
Click to show internal directories.
Click to hide internal directories.