Documentation
¶
Overview ¶
Package dialect holds the per-database adaptors used by the lookup direct backend. An adaptor supplies only what differs between databases (placeholders, quoting, booleans, time and JSON handling, insert-returning-id); the backend builds queries from it. It imports only the standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dialect ¶
type Dialect interface {
// Name is the registry name, e.g. "postgres".
Name() string
// Matches reports whether a driver type identifier (lowercased "<pkgpath>.<Type>")
// belongs to this database. Used by Detect.
Matches(driver string) bool
// Placeholder returns the bind placeholder for the n-th (1-based) argument.
Placeholder(n int) string
// Quote quotes an identifier. A dotted name is quoted per part ("schema.table").
// Embedded quote characters are escaped, never interpolated raw.
Quote(ident string) string
// Bool converts a Go bool to the value bound as a boolean column argument.
Bool(v bool) any
// ScanBool reads a boolean column value that the driver returned as bool, integer, string or bytes.
ScanBool(src any) (bool, error)
// ScanTime reads a time column value that the driver returned as time.Time, string or bytes.
// NULL (nil) yields the zero time.
ScanTime(src any) (time.Time, error)
// EncodeJSON converts a value to the argument bound to a JSON/TEXT column. A nil
// value, map or slice yields nil (SQL NULL).
EncodeJSON(v any) (any, error)
// DecodeJSON reads a JSON/TEXT column value into dst. NULL and empty values leave dst untouched.
DecodeJSON(src any, dst any) error
// InsertReturningID builds an INSERT of cols into table and describes how to read the new id.
// Arguments are bound positionally in cols order.
InsertReturningID(table string, cols []string, idCol string) Insert
}
Dialect is the adaptor for one database type.
func DetectDriver ¶
DetectDriver picks the dialect for a driver type identifier (see Dialect.Matches).
type Insert ¶
type Insert struct {
SQL string
Strategy InsertStrategy
}
Insert is a generated INSERT statement and how to read the id it creates.
type InsertStrategy ¶
type InsertStrategy int
InsertStrategy tells how the generated id is read after an Insert.
const ( // ReturningQuery means the statement returns the id as a single row (QueryRow + Scan). ReturningQuery InsertStrategy = iota // LastInsertID means the id is read from sql.Result.LastInsertId after Exec. LastInsertID )
Click to show internal directories.
Click to hide internal directories.