Documentation
¶
Index ¶
- Constants
- Variables
- func CommitOrRollback(txCtx *TxContext, err error) error
- func ErrorIsPqCancelStatementByUser(err error) bool
- func IsUpdated(result sql.Result) error
- func NewInt(i int) *int
- func ScanJSON(src interface{}, target interface{}) error
- func ToNullString(str string) sql.NullString
- func WithTransaction(ctx context.Context, db *sqlx.DB, opts *sql.TxOptions, fn TxFunc) (err error)
- type AliasSetter
- type ColumnGetter
- type ColumnWriter
- type Config
- type Database
- func (db *Database) Close() error
- func (db *Database) GetConnection(ctx context.Context) (*sqlx.Conn, error)
- func (db *Database) Init() error
- func (db *Database) InitContext(ctx context.Context) error
- func (db *Database) IsConnected() bool
- func (db *Database) PingContext(ctx context.Context) error
- func (db *Database) WithContext(ctx context.Context) *DatabaseContext
- type DatabaseContext
- func (s *DatabaseContext) MustPrepare(query string) *sqlx.Stmt
- func (s *DatabaseContext) MustPrepareFmt(queryFmt string, args ...interface{}) *sqlx.Stmt
- func (s *DatabaseContext) MustPrepareNamed(query string) *sqlx.NamedStmt
- func (s *DatabaseContext) MustPrepareNamedFmt(queryFmt string, args ...interface{}) *sqlx.NamedStmt
- func (s *DatabaseContext) MustPrepareRebind(query string) *sqlx.Stmt
- func (s *DatabaseContext) MustPrepareReplace(q string, values map[string]string) *sqlx.Stmt
- func (s *DatabaseContext) Rebind(query string) string
- func (s *DatabaseContext) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- type Expander
- type FilterParser
- type FromWriter
- type Int64
- type JoinWriter
- type OrderByWriter
- type SchemaRefGetter
- type SchemaReference
- type SelectWriter
- type String
- type TableGetter
- type TxContext
- type TxFunc
- type VariableWriter
- type WhereCompareWriter
- type WhereLogicWriter
- type WhereWriter
Constants ¶
const ( DriverMySQL = "mysql" DriverPostgreSQL = "postgres" Null = `null` )
const ( DefaultMaxIdleConn = 10 DefaultMaxOpenConn = 10 DefaultMaxConnLifetime = 1 )
const (
Separator = ", "
)
Variables ¶
var EmptyObjectJSON = json.RawMessage("{}")
var RowNotUpdatedError = new(rowNotUpdatedError)
Functions ¶
func CommitOrRollback ¶
CommitOrRollback commits the transaction if err is nil, otherwise rolls back This is useful for manual transaction control
func ScanJSON ¶
func ScanJSON(src interface{}, target interface{}) error
ScanJSON is a generic scanner function to parse json from row data
func ToNullString ¶
func ToNullString(str string) sql.NullString
Types ¶
type AliasSetter ¶
type AliasSetter interface {
SetTableAs(as string)
}
type ColumnGetter ¶
type ColumnGetter interface {
GetColumn() string
}
type ColumnWriter ¶
type ColumnWriter interface {
ColumnQuery() string
SetFormat(format op.ColumnFormat)
ColumnGetter
AliasSetter
SchemaReference
}
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func NewDatabase ¶
func (*Database) GetConnection ¶
func (*Database) IsConnected ¶
func (*Database) WithContext ¶
func (db *Database) WithContext(ctx context.Context) *DatabaseContext
type DatabaseContext ¶
type DatabaseContext struct {
// contains filtered or unexported fields
}
func (*DatabaseContext) MustPrepare ¶
func (s *DatabaseContext) MustPrepare(query string) *sqlx.Stmt
MustPrepare prepare sql statements or exit app if fails or error
func (*DatabaseContext) MustPrepareFmt ¶
func (s *DatabaseContext) MustPrepareFmt(queryFmt string, args ...interface{}) *sqlx.Stmt
MustPrepareFmt prepare sql statements from string format or exit app if fails or error
func (*DatabaseContext) MustPrepareNamed ¶
func (s *DatabaseContext) MustPrepareNamed(query string) *sqlx.NamedStmt
MustPrepareNamed prepare sql statements with named bindvars or exit app if fails or error
func (*DatabaseContext) MustPrepareNamedFmt ¶
func (s *DatabaseContext) MustPrepareNamedFmt(queryFmt string, args ...interface{}) *sqlx.NamedStmt
MustPrepareNamedFmt prepare sql statements from string format with named bindvars or exit app if fails or error
func (*DatabaseContext) MustPrepareRebind ¶
func (s *DatabaseContext) MustPrepareRebind(query string) *sqlx.Stmt
MustPrepareRebind prepare sql statements and rebind with database adapter or exit app if fails or error
func (*DatabaseContext) MustPrepareReplace ¶
MustPrepareReplace prepare sql statements from a string replacement or exit app if fails or error
func (*DatabaseContext) Rebind ¶
func (s *DatabaseContext) Rebind(query string) string
Rebind transforms a query from using ? placeholders to the driver-specific placeholder format
func (*DatabaseContext) SelectContext ¶
func (s *DatabaseContext) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectContext executes a query using the stored context, and BindStructScan each row into dest
type Expander ¶
type Expander interface {
Expand(args ...interface{}) SelectWriter
}
type FilterParser ¶
type FilterParser = func(queryValue string) (WhereWriter, []interface{})
type FromWriter ¶
type FromWriter interface {
FromQuery() string
Join(j JoinWriter)
SchemaRefGetter
}
FromWriter must be implemented by part of query that will generate query in FROM
type Int64 ¶
Int64 add functionality to handle null types of JSON strings
func (*Int64) MarshalJSON ¶
func (*Int64) UnmarshalJSON ¶
type JoinWriter ¶
type JoinWriter interface {
JoinQuery() string
GetTableName() string
GetIndex() int
SetIndex(s int)
SchemaRefGetter
}
type OrderByWriter ¶
type OrderByWriter interface {
OrderByQuery() string
AliasSetter
SchemaReference
}
type SchemaRefGetter ¶
type SchemaReference ¶
type SchemaReference interface {
TableGetter
SchemaRefGetter
SetSchema(s *schema.Schema)
}
SchemaReference must be implemented by part of query that may not require defining schema, but will be set later. For example, Selected fields can only set without defining schema and will be referred to schema that is defined in FROM
type SelectWriter ¶
type SelectWriter interface {
SelectQuery() string
SetFormat(format op.ColumnFormat)
IsAllColumns() bool
AliasSetter
SchemaReference
}
SelectWriter must be implemented by part of query that will generate query in SELECT
type String ¶
type String struct {
sql.NullString
}
String add functionality to handle null types of JSON strings
func (*String) MarshalJSON ¶
func (*String) UnmarshalJSON ¶
type TableGetter ¶
type TableGetter interface {
GetTableName() string
}
type TxContext ¶
type TxContext struct {
// contains filtered or unexported fields
}
TxContext wraps sqlx.Tx with context
type VariableWriter ¶
type VariableWriter interface {
VariableQuery() string
}
type WhereCompareWriter ¶
type WhereCompareWriter interface {
GetVariable() VariableWriter
SetVariable(v VariableWriter)
ColumnGetter
AliasSetter
SchemaReference
}
type WhereLogicWriter ¶
type WhereLogicWriter interface {
GetConditions() []WhereWriter
SetConditions(conditions []WhereWriter)
}
type WhereWriter ¶
type WhereWriter interface {
WhereQuery() string
}