Squirrel

A fluent SQL query builder for Go that composes SELECT, INSERT, UPDATE, and DELETE statements from reusable parts, without being an ORM.

Library
Go
vv1.5.4
7,983stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity0
Maintenance20
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality82
Innovation55
Learning Curve85

Squirrel is a Go library for building SQL queries programmatically instead of concatenating strings by hand. Rather than acting as an ORM, it gives you a fluent, chainable API for constructing SELECT, INSERT, UPDATE, and DELETE statements out of composable parts, so conditional query logic (optional filters, dynamic joins, varying WHERE clauses) can be expressed as plain Go code rather than fragile string templates.

Each builder method returns a new, immutable builder value, so queries can be built up incrementally, branched, and reused safely. Squirrel supports pluggable placeholder formats (? for MySQL/SQLite, $1-style for PostgreSQL, plus colon and @p variants), can bind directly to a database/sql-compatible runner via RunWith for one-step Exec/Query/QueryRow calls, and includes a statement cache (stmtcacher) for reusing prepared statements.

The project has been in maintenance mode since around 2020 — the maintainer describes it as “complete,” merging bug fixes slowly but not adding new features. It remains widely used and is a common building block behind higher-level query-builder and repository-pattern libraries in the Go ecosystem.

What You Get

  • Fluent query builders - Select, Insert, Update, and Delete builders with chainable methods for columns, joins, WHERE/HAVING clauses, ordering, limits, and offsets.
  • Composable WHERE conditions - Eq, Gt, Lt, Like, Or, And and raw Expr() fragments that combine into complex predicates without manual string building.
  • Pluggable placeholder formats - Question, Dollar, Colon, and AtP formats let the same builder target MySQL/SQLite (?) or PostgreSQL ($1, $2, …) style placeholders.
  • Direct execution via RunWith - bind a builder to any database/sql-compatible runner (or context-aware equivalent) and call Exec, Query, QueryRow, or Scan directly on the built query.
  • Prepared statement caching - the stmtcacher package wraps a runner to cache and reuse prepared statements across repeated query executions.
  • Context-aware variants - *_ctx.go builders and a StdSqlCtx runner interface for executing queries with context.Context support.

Common Use Cases

  • Dynamic filter building - construct a query’s WHERE clause incrementally based on which optional filters a user supplied, without string-concatenation bugs.
  • Backend for higher-level data-access layers - used as the SQL-generation engine underneath repository or table-struct-mapper libraries (e.g. structable) that add struct-to-row mapping on top.
  • Multi-database applications - write query-building logic once and swap PlaceholderFormat (Question vs Dollar) to target either MySQL/SQLite or PostgreSQL.
  • Complex reporting queries - compose SELECT statements with multiple joins, GROUP BY/HAVING clauses, and subqueries (FromSelect) that would be error-prone to hand-write as strings.

Under The Hood

Architecture Squirrel is organized around per-statement-type builder files (select.go, insert.go, update.go, delete.go, plus _ctx.go context-aware counterparts) that each define an immutable data struct (e.g. selectData) and a lightweight Builder wrapper type registered with the external github.com/lann/builder package, which implements copy-on-write mutation: every chained method (.Where(...), .From(...), .Limit(...)) returns a new builder value rather than mutating shared state, so builders can be branched and reused safely. squirrel.go defines the core Sqlizer interface (ToSql() (string, []interface{}, error)) that every buildable part implements, plus Runner/Execer/Queryer/QueryRower interfaces that abstract over database/sql.DB-like types via RunWith. part.go, expr.go, and where.go provide the composable predicate and expression primitives (Eq, Expr, And/Or) that plug into any builder’s WHERE/HAVING/JOIN clauses through the shared Sqlizer contract. The core abstraction is Sqlizer itself; if it changed, every builder, predicate type, and the placeholder-substitution logic in placeholder.go would need to change with it.

Tech Stack Squirrel targets Go 1.14+ (per go.mod) with a minimal dependency footprint: github.com/lann/builder for the immutable builder pattern and github.com/lann/ps (persistent-map, indirect) as its backing data structure, github.com/stretchr/testify for test assertions, and github.com/davecgh/go-spew/github.com/pmezard/go-difflib as testify’s indirect dependencies. It has no runtime dependency on any specific database driver — it works with anything satisfying Go’s standard database/sql interfaces (or a slimmed-down StdSql/StdSqlCtx subset), and a separate integration/ module runs the same builder logic against real sqlite3, mysql, and postgres drivers in CI (.travis.yml) to verify generated SQL executes correctly.

Code Quality The project has extensive test coverage: 140+ Test* functions across *_test.go files sitting alongside their corresponding implementation files (select_test.go, expr_test.go, stmtcacher_test.go, etc.), plus a dedicated integration/ module with integration_test.go that exercises builders against live sqlite3, MySQL, and PostgreSQL databases in CI. Error handling is explicit and idiomatic Go — builder methods that can fail return (string, []interface{}, error) triples rather than panicking (though MustSql offers an explicit panic-on-error convenience variant), and sentinel errors like RunnerNotSet are exported for callers to check against. Naming is consistent and conventional for the Go ecosystem (exported Sqlizer, PlaceholderFormat, builder methods matching SQL clause names). No linter config or GitHub Actions workflow is present in the repo — CI is defined via a legacy .travis.yml — and the project is explicitly in low-activity maintenance mode, so quality is high but the toolchain around it (CI provider, Go version pins) is dated.

API Design The public API reads close to the SQL it generates: sq.Select("*").From("users").Where(sq.Eq{"id": 1}) mirrors SELECT * FROM users WHERE id = ? almost one-to-one, which keeps the learning curve low for anyone who already knows SQL. Method chaining plus copy-on-write builders means queries can be partially built, stored in a variable, and branched into multiple final queries safely — a pattern the README demonstrates directly (building a base users query, then deriving active and three_stooges variants from it). Getting started requires zero boilerplate beyond an import and a RunWith(db) call to attach a driver; the README’s own quickstart snippets execute as shown. Documentation is concentrated in GoDoc comments on exported methods rather than a separate docs site, and the README’s FAQ section addresses common gotchas (composite-key IN queries, []byte vs []uint8 ambiguity) directly, which lowers the friction of edge cases that aren’t obvious from the API alone.

Used by 9 apps in this directory

Go
55%
Apache 2.0

Authgear

Authentication

2,014

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
Go
82%
AGPL 3.0

Beta9

Developer Tools · AI Development · Data Engineering

1,762

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
84
Repo Health
78
Technical
67
Dependency
Built with
Go82%
Python17%
Updated 3 days ago
TypeScript
54%
Other

Focalboard

Productivity · Project Management · Collaboration

26,441

Self-hosted, open source project management with Kanban, table, gallery, and calendar views — a privacy-first alternative to Trello, Notion, and Asana.

View details
58
Repo Health
82
Technical
65
Dependency
Built with
TypeScript54%
Go40%
Updated 3 months ago
Go
61%
Apache 2.0

Harness Open Source

Developer Tools · Devops · Code Editors

38,169

A unified open source DevOps platform combining Git hosting, CI/CD pipelines, cloud development environments, and artifact registries in a single self-hosted system.

View details
89
Repo Health
79
Technical
64
Dependency
Built with
Go61%
TypeScript34%
Updated 2 days ago
Go
81%
GPL 3.0

Navidrome

File Storage

23,217

Run your own personal Spotify — stream your entire music collection from any device, anywhere, forever.

View details
91
Repo Health
81
Technical
70
Dependency
Built with
Go81%
JavaScript15%
Updated today
Go
74%
Other

Notifuse

Marketing

2,089

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
83
Repo Health
80
Technical
66
Dependency
Built with
Go74%
TypeScript23%
Updated yesterday
Go
100%
Apache 2.0

SpiceDB

Security · Authentication · Databases

7,001

An open source, Google Zanzibar-inspired authorization database that models permissions as relationships and evaluates fine-grained access checks at massive scale with single-digit millisecond latency.

View details
89
Repo Health
89
Technical
69
Dependency
Built with
Go100%
Updated 2 days ago
Go
85%
Apache 2.0

Uncloud

Devops

5,470

Deploy and scale containerised apps across any servers without Kubernetes or Swarm overhead

View details
83
Repo Health
78
Technical
66
Dependency
Built with
Go85%
Updated 2 days ago
Go
76%
AGPL 3.0

ZITADEL

Authentication

14,896

Open-source, API-first identity platform delivering multi-tenancy, Passkeys, OIDC, SAML, and SCIM without vendor lock-in.

View details
91
Repo Health
81
Technical
69
Dependency
Built with
Go76%
TypeScript12%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search