Project Brief: sqlh
June 12, 2026 ยท View on GitHub
Overview
sqlh (SQL Helper) is a lightweight Go package that simplifies interactions with SQL databases. It leverages Go generics (Go 1.25+) to provide a set of intuitive type-safe CRUD functions (Insert, Update, Get, List, Delete, Set) that work directly with user-defined Go structs, reducing boilerplate SQL code.
Core Mission
Eliminate repetitive SQL query writing for Go developers by automatically generating SQL statements from struct definitions using struct tags, while maintaining database-agnostic compatibility and transactional safety.
Key Stakeholders
- Author/Maintainer: Kirill Scherba (kirill@scherba.ru)
- Target Users: Go developers working with SQL databases (SQLite, MySQL, PostgreSQL) who want to avoid writing boilerplate CRUD SQL
Core Capabilities
- Automatic Query Generation: Auto-generates
CREATE TABLE,INSERT,UPDATE,SELECT, andDELETEstatements from Go structs - Generic Type-Safe API: Uses Go generics (
T any) for compile-time type safety - Struct Tag Mapping: Uses
db,db_type, anddb_keytags to define column names, types, and constraints - Autoincrement Support: Automatically excludes
autoincrementfields from INSERT and UPDATE statements - Transactional Writes: All write operations (
Insert,Update,Delete,Set) are wrapped in transactions - Database Lock Retry: Built-in retry mechanism (up to 20 attempts with 100ms delay) for "database is locked" errors
- Standardized Errors: Returns
sql.ErrNoRowsand exported package errors (ErrWhereClauseRequired,ErrMultipleRowsFound, etc.) - Context Support: Functions accept
context.Contextfor timeouts and cancellations - Pagination:
ListRowsandListRangesupport explicit offset/limit pagination - Iterators: Uses Go 1.25 iterators (
iter.Seq2[int, T]) for row iteration inListRange - JOIN Support: Basic JOIN support via
query.Joinattribute - DISTINCT, Alias, Name: Flexible query attributes for advanced SELECT queries
- Metadata Cache: Struct reflection metadata is cached by
reflect.Typefor repeated query generation and scan/apply operations
Current Version
v0.8.0 (2026-06-12) โ type-safe WHERE helpers, benchmarks, animated GIF demo, pkg.go.dev badge, and awesome-go submission.
License
BSD-style license
Distribution
- GitHub: https://github.com/kirill-scherba/sqlh
- pkg.go.dev: https://pkg.go.dev/github.com/kirill-scherba/sqlh
- Go Report Card: https://goreportcard.com/report/github.com/kirill-scherba/sqlh
- awesome-go: Submitted to avelino/awesome-go PR #6401 (SQL Query Builders).