Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. go-sqlbuilder

go-sqlbuilder

MITGov1.41.0

A flexible and powerful SQL string builder library plus a zero-config ORM for Go.

Visit WebsiteGitHubGitHub
1.7k stars139 forks0 contributors

What is go-sqlbuilder?

go-sqlbuilder is a Go library for programmatically building SQL strings and acting as a zero-configuration ORM. It provides a flexible suite of builders for constructing SQL statements (SELECT, INSERT, UPDATE, etc.) that are compatible with Go's standard database/sql interfaces. It solves the problem of writing raw SQL strings manually, offering type-safe construction, argument escaping, and support for multiple database flavors.

Target Audience

Go developers who need to generate SQL queries dynamically, work with multiple database systems, or want a lightweight ORM alternative without the overhead of full-featured ORMs. It's particularly useful in enterprise environments with complex SQL requirements or custom database drivers.

Value Proposition

Developers choose go-sqlbuilder for its driver-agnostic design, performance optimization, and flexibility. It avoids locking users into a specific database driver or ORM framework, supports complex SQL scenarios like nested queries and reusable WHERE clauses, and includes a zero-config ORM that works with any database/sql-compatible driver.

Overview

A flexible and powerful SQL string builder library plus a zero-config ORM.

Use Cases

Best For

  • Dynamically building SQL queries with complex conditions and joins
  • Supporting multiple database systems (MySQL, PostgreSQL, SQLite, etc.) in one codebase
  • Creating reusable SQL templates for common query patterns
  • Implementing a lightweight ORM without external dependencies
  • Generating SQL for non-standard database systems or custom drivers
  • Writing type-safe SQL in Go without concatenating raw strings

Not Ideal For

  • Projects requiring full-featured ORM capabilities like automatic schema migrations, relationship management, and lazy loading
  • Teams that prefer integrated database solutions with built-in connection pooling and driver-specific optimizations
  • Applications with simple, static SQL queries where raw strings or lighter libraries like squirrel would suffice
  • Developers needing extensive community plugins or GUI tools for query building and debugging

Pros & Cons

Pros

Flexible SQL Building

Supports a comprehensive suite of builders for SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, UNION, and CTEs, with nested queries and JOINs, as shown in the README examples for complex SQL scenarios.

Zero-Config ORM

The Struct type acts as a lightweight ORM, generating SQL from Go structs without database connection setup, allowing use with any database/sql-compatible driver for type-safe data mapping.

Reusable WHERE Clauses

WhereClause struct enables sharing and reusing conditions across different builders, improving code maintainability in enterprise environments with complex filtering logic.

Cloneable Builders

Builders can be cloned to create reusable templates, avoiding repeated setup and supporting safe concurrent use, as demonstrated in the global template example.

Cons

No Automatic Relationships

Lacks built-in support for model relationships like joins or lazy loading; developers must manually write JOINs and manage associations, unlike full ORMs such as GORM.

Interpolation Security Risks

The SQL interpolation feature for non-standard drivers comes with a security warning in the README, as it's less secure than using prepared statements and can be vulnerable to injection if misused.

Limited High-Level Abstractions

Focuses solely on SQL string construction, so tasks like schema migrations, transaction management, or connection pooling require additional libraries or custom code.

Frequently Asked Questions

Quick Stats

Stars1,710
Forks139
Contributors0
Open Issues3
Last commit1 month ago
CreatedSince 2017

Tags

#query-builder#orm#database#struct-mapping#lightweight#database-abstraction#postgresql#mysql#sqlite#sql-builder#go#sql#sql-generation

Built With

G
Go

Links & Resources

Website

Included in

Go169.1k
Auto-fetched 1 day ago

Related Projects

GORMGORM

The fantastic ORM library for Golang, aims to be developer friendly

Stars39,771
Forks4,153
Last commit28 days ago
entent

An entity framework for Go

Stars17,102
Forks1,005
Last commit8 days ago
SQLBoilerSQLBoiler

Generate a Go ORM tailored to your database schema.

Stars6,990
Forks557
Last commit1 month ago
bunbun

SQL-first Golang ORM

Stars4,847
Forks279
Last commit10 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub