general purpose extensions to golang's database/sql
sqlx is a library which provides a set of extensions on go's standard
database/sql library. The sqlx versions of sql.DB, sql.TX, sql.Stmt,
et al. all leave the underlying interfaces untouched, so that their interfaces
are a superset on the standard ones. This makes it relatively painless to
integrate existing codebases using database/sql with sqlx.
Major additional concepts are:
Get and Select to go quickly from query to struct/sliceIn addition to the godoc API documentation,
there is also some user documentation that
explains how to use database/sql along with sqlx.
1.3.0:
sqlx.DB.Connx(context.Context) *sqlx.Connsqlx.BindDriver(driverName, bindType)[]map[string]interface{} to do "batch" insertionssqlx.InDB.Connx returns an sqlx.Conn, which is an sql.Conn-alike consistent with
sqlx's wrapping of other types.
BindDriver allows users to control the bindvars that sqlx will use for drivers,
and add new drivers at runtime. This results in a very slight performance hit
when resolving the driver into a bind type (~40ns per call), but it allows users
to specify what bindtype their driver uses even when sqlx has not been updated
to know about it by default.
Compatibility with the most recent two versions of Go is a requirement for any new changes. Compatibility beyond that is not guaranteed.
Versioning is done with Go modules. Breaking changes (eg. removing deprecated API) will get major version number bumps.
go get github.com/jmoiron/sqlx
Row headers can be ambiguous (SELECT 1 AS a, 2 AS a), and the result of
Columns() does not fully qualify column names in queries like:
SELECT a.id, a.name, b.id, b.name FROM foos AS a JOIN foos AS b ON a.parent = b.id;
making a struct or map destination ambiguous. Use AS in your queries
to give columns distinct names, rows.Scan to scan them manually, or
SliceScan to get a slice of results.
Below is an example which shows some common use cases for sqlx. Check sqlx_test.go for more usage.
…
No open issues yet, or sync has not completed.