Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyBindings ¶
ApplyBindings should be called after scanning values from the result set to perform all late binding.
func Nullify ¶
func Nullify[T comparable](value T) any
Nullify returns nil if the value equals to the zero value of its Go data type, else it returns the value. Use this construct to convert zero values to nil when writing to a nullable database column.
Example:
db.Exec( "INSERT INTO my_table (id, desc, modified_time) VALUES (?,?,?)", obj.ID, sequel.Nullify(obj.Description), sequel.Nullify(obj.ModifiedTime), )
Types ¶
type Binder ¶
Binder is a thin wrapper over sql.Null that allows for late-binding of its value.
func Bind ¶
Bind applies a binding function to the scanned value.
Example:
var obj Object
args := []any{
&obj.ID,
sequel.Bind(func(tags string) {
return json.Unmarshal([]byte(tags), &obj.Tags)
}),
sequel.Bind(func(modifiedTime time.Time) {
obj.Year, obj.Month, obj.Day = modifiedTime.Date()
return nil
}),
}
db.QueryRow("SELECT id, tags, modified_time FROM my_table WHERE id=?", id).Scan(args...)
sequel.ApplyBindings(args...)
type DB ¶
DB is an enhanced database connection that
- Limits the size of the connection pool to each server to approx the sqrt of the number of clients
- Performs schema migration
- Automatically creates and connects to a localhost database while testing
func Open ¶
Open returns a database connection to the named data source.
If a driver name is not provided, it is inferred from the data source name on a best-effort basis. Drivers currently supported: "mysql" (MySQL), "pgx" (Postgres) or "mssql" (SQL Server).
Example data source name for each of the supported drivers:
- mysql: username:password@tcp(hostname:3306)/
- pgx: postgres://username:password@hostname:5432/
- mssql: sqlserver://username:password@hostname:1433
func OpenTesting ¶
OpenTesting opens a connection to a uniquely named database for testing purposes. A database is created for each unique test at the database instance pointed to by the input DSN.
If a driver name is not provided, it is inferred from the data source name on a best-effort basis. Drivers currently supported: "mysql" (MySQL), "pgx" (Postgres) or "mssql" (SQL Server).
If a data source name is not provided, the following defaults are used based on the driver name:
- (empty): root:root@tcp(127.0.0.1:3306)/
- mysql: root:root@tcp(127.0.0.1:3306)/
- pgx: postgres://postgres:postgres@127.0.0.1:5432/
- mssql: sqlserver://sa:Password123@127.0.0.1:1433
func (*DB) ConformArgPlaceholders ¶
ConformArgPlaceholders replaces the ? arg placeholders in a SQL statement to $1, $2 etc. for a Postgres driver.
func (*DB) DriverName ¶
DriverName is the name of the driver: "mysql", "pgx" or "mssql".
func (*DB) Migrate ¶
Migrate reads all #.sql files from the FS, and executes any new migrations in order of their file name. The order of execution is guaranteed only within the context of a sequence name.
func (*DB) RegexpTextSearch ¶
RegexpTextSearch is a SQL statement that performs a REGEXP_LIKE search on multiple columns. The statement includes a single argument placeholder ? that should be filled with a valid regular expression.
type Null ¶
Null is a thin wrapper over sql.Null that allows for reading NULL values.
func Nullable ¶
Nullable is a simple binder that interprets NULL values to be the zero value of their Go data type.
Example:
var obj Object
args := []any{
&obj.ID,
sequel.Nullable(&obj.Description),
sequel.Nullable(&obj.ModifiedTime),
}
db.QueryRow("SELECT id, desc, modified_time FROM my_table WHERE id=?", id).Scan(args...)
sequel.ApplyBindings(args...)