Documentation
¶
Index ¶
- func Scan(s SQLRow, d ...any) error
- func ScriptMigration(script string) func(*sql.Tx) error
- type Assign
- type BoundCols
- type Builder
- func (b *Builder) Args() []any
- func (b *Builder) DeleteWhere(table Raw, whereFormat string, a ...any)
- func (b *Builder) Exec(db DB) (sql.Result, error)
- func (b *Builder) ExecLastInsertID(db DB) (int64, error)
- func (b *Builder) ExecRowsAffected(db DB) (int64, error)
- func (b *Builder) InsertValues(table Raw, a BoundCols)
- func (b *Builder) JoinBy(sep string)
- func (b *Builder) Printf(format string, a ...any)
- func (b *Builder) Query(db DB) (*sql.Rows, error)
- func (b *Builder) QueryRow(db DB) *sql.Row
- func (b *Builder) Reset()
- func (b *Builder) Scan(db DB, d ...any) Rows
- func (b *Builder) ScanArgs() []any
- func (b *Builder) ScanBound(db DB) Rows
- func (b *Builder) ScanBoundRow(db DB) error
- func (b *Builder) ScanRow(db DB, d ...any) error
- func (b *Builder) SelectWhere(c BoundCols, table Raw, whereFormat string, a ...any)
- func (b *Builder) String() string
- func (b *Builder) UpdateWhere(table Raw, c BoundCols, whereFormat string, a ...any)
- type ColsFor
- type ColsMapFunc
- type ColsPred
- type DB
- type Dialect
- type Migration
- type Names
- type Raw
- type RawWriter
- type Rows
- type SQLRow
- type SQLWriter
- type Vals
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assign ¶ added in v0.3.0
type Assign struct{ C BoundCols }
Assign is formatted as Col = Val by Printf
type BoundCols ¶ added in v0.3.0
type BoundCols struct {
// contains filtered or unexported fields
}
BoundCols is the combination of column names and corresponding values
type Builder ¶
type Builder struct {
Dialect Dialect
// contains filtered or unexported fields
}
Builder is used to build an SQL query
func (*Builder) DeleteWhere ¶ added in v0.3.0
func (*Builder) ExecLastInsertID ¶ added in v0.2.0
func (*Builder) ExecRowsAffected ¶ added in v0.2.0
func (*Builder) InsertValues ¶ added in v0.3.0
InsertValues prints INSERT INTO ... VALUES (...), ...
func (*Builder) JoinBy ¶ added in v0.2.0
JoinBy will cause subsequent calls to Printf to be joined by sep if sep is not empty.
func (*Builder) Printf ¶
Printf appends a fmt.Printf style query to b. Instead of printing the arguments directly, they will be replaced by a placeholder generated by Dialect. Raw arguments will be printed directly. If an argument implements SQLWriter, the WriteSQL method will be called (see documentation of SQLWriter). Because of this special handling, it is best to use %v as string parameter.
func (*Builder) Reset ¶ added in v0.0.9
func (b *Builder) Reset()
Reset resets the Builder so that it can be re-used. Args() and ScanArgs() slices are re-used.
func (*Builder) ScanBoundRow ¶ added in v0.3.0
func (*Builder) SelectWhere ¶ added in v0.3.0
SelectWhere prints SELECT ... FROM ...
type ColsFor ¶ added in v0.3.0
type ColsFor[T any] struct { // contains filtered or unexported fields }
ColsFor is a subset of all struct fields of struct type T. It is safe to use ColsFor from multiple goroutines.
func NewCols ¶ added in v0.3.1
NewCols returns the columns for the struct type T where pred returns true. If pred is nil, all columns are returned
func (ColsFor[T]) Map ¶ added in v0.3.0
func (c ColsFor[T]) Map(mapFunc ColsMapFunc) ColsFor[T]
Map returns c but with mapFunc applied to each name
type ColsMapFunc ¶ added in v0.3.0
func MapPrefix ¶ added in v0.3.0
func MapPrefix(prefix Raw) ColsMapFunc
MapPrefix returns a ColsMapFunc that adds prefix to the column name
type DB ¶ added in v0.0.9
type DB interface {
Exec(query string, a ...any) (sql.Result, error)
Query(query string, a ...any) (*sql.Rows, error)
QueryRow(query string, a ...any) *sql.Row
}
DB describes the common interface of *sql.Tx and *sql.Rows
type Dialect ¶ added in v0.0.9
Dialect is used to customize how SQL placeholders are formatted (?, $n, @n, ...)
var (
SQLite Dialect = sqliteDialectImpl{}
)
type Names ¶ added in v0.3.0
type Names []Raw
Names are formatted as comma seperated list of strings
type RawWriter ¶ added in v0.2.0
type RawWriter struct {
// contains filtered or unexported fields
}
func (*RawWriter) Write ¶ added in v0.2.0
Write appends the contents of d to b's buffer. Write always returns len(p), nil.
func (*RawWriter) WriteParam ¶ added in v0.2.0
WriteParam appends a param placeholder to bs buffer
type Rows ¶ added in v0.2.0
type Rows struct {
// contains filtered or unexported fields
}
Rows wraps the result of Query