sqlex — A Modern Drop-in Replacement for jmoiron/sqlx

go dev.to

title: sqlex — A Modern Drop-in Replacement for jmoiron/sqlx
published: false
description: sqlex is a fully API-compatible modernization of jmoiron/sqlx that fixes 20+ long-standing bugs, adds pluggable hooks, auto IN expansion, and more. Built for Go 1.21+.
tags: go, database, sql, opensource

If you use sqlx, this is worth 3 minutes of your time

jmoiron/sqlx has been the go-to SQL extension library for Go for years. Struct mapping, named parameters, IN clause expansion — it made database/sql actually pleasant to use. I've used it in almost every Go project I've worked on.

But here's the reality: its activity has been modest at best, and has slowed to a crawl in recent years. Hundreds of issues sit untouched. PRs go unanswered. Bugs reported years ago are still there, waiting to cause production incidents.

This isn't a knock on sqlx — it's a great library with solid design. But an unmaintained foundational library is a liability.

So we built sqlex

sqlex is a drop-in replacement for jmoiron/sqlx that is 100% API-compatible. All sqlx methods (Get, Select, Exec, NamedQuery, Preparex, etc.) work identically.

Migrating takes 30 seconds — just change the import path:

- import "github.com/jmoiron/sqlx"
+ import "github.com/go-sqlex/sqlex"
Enter fullscreen mode Exit fullscreen mode

🐛 20+ bug fixes from sqlx, all fixed

🚀 New features sqlx never had

  • Auto-Rebind — write ? everywhere, works on PostgreSQL ($1), MySQL (?), SQLite (?), SQL Server (@p1). No more manual db.Rebind().

  • SQL parsing fixes — colons in strings, :: type casts, ? in comments are correctly handled. Silent bugs from sqlx are gone.

  • Auto IN expansion — slices in IN (?) are detected and expanded automatically on all methods.

  • Hook system — pluggable SQL interceptors for logging, tracing, metrics (onion model).

  • JSONValue[T] — generic JSON column type with auto serialize/deserialize.

  • StrictMode — lenient by default (matching sqlx Unsafe()), optionally strict for debugging.

  • Unified interfaces — Ext / ExtContext / NamedExt / BindExt with compile-time checks.

Project status
Version: v1.5.3 (just released, actively maintained)

Go version: 1.21+

License: MIT

100% API-compatible with sqlx

sqlx was great for its time, and its design still holds up. But the lack of maintenance — the unfixed lexer bugs, the inconsistent APIs, the silent data corruption issues — adds real cost to real projects.

sqlex isn't a rewrite. It's a modernization that keeps what sqlx got right and fixes what it got wrong.

If you're using sqlx and you've run into any of the issues above, give sqlex a try. The migration is trivial, and the improvements are real.

GitHub: https://github.com/go-sqlex/sqlex

Source: dev.to

arrow_back Back to Tutorials