Documentation
¶
Index ¶
- func NewMySQLConnector(host string, username string, password string, database string) (*sqlx.DB, error)
- func NewPostgresConnector(host string, port string, user string, password string, database string) (*sqlx.DB, error)
- type Commander
- type Counter
- type Executable
- type Finder
- type IDecoder
- type Inserter
- type QueryBuilder
- type Updater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Commander ¶ added in v2.5.0
type Commander interface {
// NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder
NumericArgs(isNumeric bool) Commander
// Command set sql comman
Command(cmd string) Commander
// Replace replace phrase in query string before ru
Replace(old string, new string) Commander
// Exec normalize command and exe
Exec(args ...any) (sql.Result, error)
}
func NewCMD ¶ added in v2.5.0
func NewCMD(db Executable) Commander
type Counter ¶ added in v2.5.0
type Counter interface {
// NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder
NumericArgs(isNumeric bool) Counter
// Query set sql query
Query(query string) Counter
// Replace replace phrase in query string before run
Replace(old string, new string) Counter
// Result get count, returns -1 on error
Result(args ...any) (int64, error)
}
func NewCounter ¶ added in v2.5.0
type Executable ¶ added in v2.4.0
type Finder ¶ added in v2.5.0
type Finder[T any] interface { // NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder NumericArgs(isNumeric bool) Finder[T] // QuoteFields specifies whether to use quoted field name ("id", "name") or not QuoteFields(quoted bool) Finder[T] // Query set sql query Query(query string) Finder[T] // Replace replace phrase in query string before run Replace(old string, new string) Finder[T] // Resolve reginster new resolver to run on record after read Resolve(resolver func(*T) error) Finder[T] // Cursor get sqlx cursor, this method return nil of no rows exists Cursor(args ...any) (*sqlx.Rows, error) // Single get first result Single(args ...any) (*T, error) // Result get multiple result Result(args ...any) ([]T, error) }
type Inserter ¶ added in v2.5.0
type Inserter[T any] interface { // NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder NumericArgs(isNumeric bool) Inserter[T] // QuoteFields specifies whether to use quoted field name ("id", "name") or not QuoteFields(quoted bool) Inserter[T] // Table table name Table(table string) Inserter[T] // Insert insert and return result Insert(entity T) (sql.Result, error) }
func NewInserter ¶ added in v2.5.0
func NewInserter[T any](db Executable) Inserter[T]
type QueryBuilder ¶
type QueryBuilder interface {
// And add new simple condition to query with AND
And(query string, args ...any) QueryBuilder
// AndIf add new And condition if first parameter is true
AndIf(cond bool, query string, args ...any) QueryBuilder
// Or add new simple condition to query with OR
Or(query string, args ...any) QueryBuilder
// OrIf add new Or condition if first parameter is true
OrIf(cond bool, query string, args ...any) QueryBuilder
// AndClosure add new condition to query with AND in nested ()
AndClosure(query string, args ...any) QueryBuilder
// AndClosureIf add new AndClosure condition if first parameter is true
AndClosureIf(cond bool, query string, args ...any) QueryBuilder
// OrClosure add new condition to query with OR in nested ()
OrClosure(query string, args ...any) QueryBuilder
// OrClosureIf add new AndClosure condition if first parameter is true
OrClosureIf(cond bool, query string, args ...any) QueryBuilder
// NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder
NumericArgs(bool) QueryBuilder
// NumericStart set numeric argument start for numeric args mode
NumericStart(int) QueryBuilder
// Replace replace phrase in query string before run
Replace(string, string) QueryBuilder
// Raw get raw generated query
Raw() string
// SQL use generated query in part of sql command
// automatically replace @query with Raw() value
// automatically replace @where with `WHERE Raw()` value
SQL(query string) string
// Args get list of arguments
Args() []any
}
Query builder
type Updater ¶ added in v2.5.0
type Updater[T any] interface { // NumericArgs specifies whether to use numeric ($1, $2) or normal (?, ?) placeholder NumericArgs(isNumeric bool) Updater[T] // QuoteFields specifies whether to use quoted field name ("id", "name") or not QuoteFields(quoted bool) Updater[T] // Table table name Table(table string) Updater[T] // Where update condition Where(cond string, args ...any) Updater[T] // Update update and return result Update(entity T) (sql.Result, error) }
func NewUpdater ¶ added in v2.5.0
func NewUpdater[T any](db Executable) Updater[T]
Source Files
¶
Click to show internal directories.
Click to hide internal directories.