Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

sqlx

> 编程语言
Open source

general purpose extensions to golang's database/sql

17.7K stars0 likes4 views
WebsiteGitHub

About

general purpose extensions to golang's database/sql

sqlx

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:

  • Marshal rows into structs (with embedded struct support), maps, and slices
  • Named parameter support including prepared statements
  • Get and Select to go quickly from query to struct/slice

In addition to the godoc API documentation, there is also some user documentation that explains how to use database/sql along with sqlx.

Recent Changes

1.3.0:

  • sqlx.DB.Connx(context.Context) *sqlx.Conn
  • sqlx.BindDriver(driverName, bindType)
  • support for []map[string]interface{} to do "batch" insertions
  • allocation & perf improvements for sqlx.In

DB.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.

Backwards Compatibility

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.

install

go get github.com/jmoiron/sqlx

issues

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:

sql
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.

usage

Below is an example which shows some common use cases for sqlx. Check sqlx_test.go for more usage.

…

Issues· 396 open

View all issuesOpen on GitHub
  • #759

    How to mock QueryerContext interface when it returns a sqlx.Row?

    Updated Sep 29, 2026
  • #959

    (Documentation) sqlx.In should be used with (?) instead of ($1) for postgres

    Updated Sep 27, 2026
  • #989

    Would it be possible to expand a slice of structs inside a struct within the same sql statement?

    Updated Aug 27, 2026
  • #206

    Colon in string with a space after it can lead to invalid param name

    Updated Jul 21, 2026
  • #994

    Bump github.com/go-sql-driver/mysql to v1.10.0 (clears CVE-2026-26958 / edwards25519 scanner flags)

    Updated Jul 7, 2026
  • #975

    The reflectx.Mapper from conn cannot be passed to stmt when creating stmt from conn

    Updated Jul 1, 2026
  • #961

    Inline comment with a question mark ? results in a "number of bindVars exceeds arguments" error within sqlx.In

    Updated Jun 28, 2026
  • #983

    sqlx.Named fails when a named parameter is immediately followed by a PostgreSQL cast

    Updated Jun 28, 2026
  • #969

    No update to master in over a year

    Updated Jun 18, 2026
  • #956

    Bug in sqlx.Named where ::text is incorrectly processed, leading to syntax erro

    Updated Jun 18, 2026

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言