sqlx (Go)
Extensions to Go's standard database/sql package. sqlx adds struct scanning (DB.Get, DB.Select), named queries (:param syntax), IN clause expansion, and StructScan to avoid manual Scan() field-by-field mapping. A thin but highly practical layer over database/sql — not a full ORM, just ergonomic SQL with struct binding. The most common Go database helper library for teams that want raw SQL with less boilerplate.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Inherits database/sql security. Prepared statements prevent SQL injection. No additional security mechanisms — application responsibility for credential management.
⚡ Reliability
Best When
You're writing Go with raw SQL and want struct scanning + named parameters without a full ORM — sqlx is the pragmatic choice that stays close to database/sql while eliminating boilerplate.
Avoid When
You need ORM-level abstractions (relationships, hooks, migrations) — GORM offers a more complete ORM experience for Go.
Use Cases
- • Map SQL query results directly to Go structs with DB.Get() and DB.Select() — eliminating manual rows.Scan() field-by-field assignment in agent database code
- • Use named parameters in SQL queries (:user_id, :status) with sqlx.Named() for more readable agent database operations
- • Expand Go slices into SQL IN clauses with sqlx.In() — avoiding manual query string construction for multi-value filters
- • Execute bulk inserts with named struct binding for batch agent data persistence without ORM overhead
- • Migrate existing database/sql code to sqlx incrementally — sqlx.DB is a drop-in replacement for sql.DB
Not For
- • Full ORM features (associations, eager loading, model callbacks) — use GORM or Ent for ORM-style abstractions
- • Compile-time SQL verification — use Rust's SQLx (different project!) for type-checked SQL at build time
- • Teams wanting query builder DSL — use squirrel or goqu for programmatic query building
Interface
Authentication
Library — no external auth. Database credentials via connection string. Drop-in replacement for database/sql.
Pricing
MIT-licensed open source Go module. Note: project is lightly maintained (author considers it feature-complete).
Agent Metadata
Known Gotchas
- ⚠ Struct field tags must match DB column names via `db:"column_name"` tag — without tags, sqlx uses lowercase field name which may not match snake_case column names
- ⚠ DB.Get() returns sql.ErrNoRows (not nil) when no record found — agents must check for this specific error to distinguish 'not found' from other errors
- ⚠ sqlx.In() requires rebind for database-specific placeholders — PostgreSQL needs DB.Rebind() to convert ? to $1,$2,$3 format after sqlx.In() expansion
- ⚠ Named queries require BindNamed() and the query must use :name syntax — mixing ? placeholders with named params in the same query causes errors
- ⚠ sqlx does not manage connection pool settings — must configure MaxOpenConns, MaxIdleConns, ConnMaxLifetime on the underlying sql.DB for production agent workloads
- ⚠ StructScan and Select() use reflection — performance-critical code scanning millions of rows should benchmark against raw Scan() to verify acceptable overhead
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for sqlx (Go).
Scores are editorial opinions as of 2026-03-06.