# masterminds/squirrel architecture

> Architecture diagram of the GitHub repository masterminds/squirrel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/masterminds/squirrel
- Repository: https://github.com/masterminds/squirrel

## Overview

Squirrel is a fluent Go SQL generator, not an ORM. Callers compose SELECT, INSERT, UPDATE, DELETE, and CASE expressions, then serialize them into SQL plus bound arguments or execute them through a supplied database runner. Expression predicates and placeholder formatting support composable queries and PostgreSQL-style placeholders; optional context-aware runners and prepared-statement caching extend execution. The graph follows only relationships visible in excerpts or documented by the README; some builder internals and individual query execution paths were not sampled.

Main entry points: [`select.go`](https://github.com/masterminds/squirrel/blob/master/select.go) (SELECT builder), [`statement.go`](https://github.com/masterminds/squirrel/blob/master/statement.go) (Statement entrypoints), [`squirrel.go`](https://github.com/masterminds/squirrel/blob/master/squirrel.go) (Runner interfaces), [`update.go`](https://github.com/masterminds/squirrel/blob/master/update.go) (UPDATE builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Builder API"]
  node_statements["Statement entrypoints<br/>[statement.go]"]
  node_select["SELECT builder<br/>[select.go]"]
  node_insert["INSERT builder<br/>[insert.go]"]
  node_update["UPDATE builder<br/>[update.go]"]
  node_delete["DELETE builder<br/>[delete.go]"]
  node_case["CASE expressions<br/>[case.go]"]
end

subgraph group_sql["SQL Composition"]
  node_expressions["SQL expressions<br/>[expr.go]"]
  node_where["Predicate parts<br/>[where.go]"]
  node_parts["SQL parts<br/>[part.go]"]
  node_placeholders["Placeholder formats<br/>[placeholder.go]"]
end

subgraph group_execution["Execution"]
  node_runner["Runner interfaces<br/>[squirrel.go]"]
  node_context["Context runners<br/>[squirrel_ctx.go]"]
  node_row["Row scanner<br/>[row.go]"]
  node_cache["Prepared statement cache<br/>[stmtcacher.go]"]
end

node_caller(("Go caller"))
node_database[("SQL database")]

node_caller -->|"starts builders"| node_statements
node_caller -->|"composes SELECT"| node_select
node_caller -->|"composes INSERT"| node_insert
node_statements -->|"creates"| node_select
node_statements -->|"creates"| node_insert
node_statements -->|"creates"| node_update
node_statements -->|"creates"| node_delete
node_statements -->|"creates"| node_case
node_select -->|"adds predicates"| node_where
node_delete -->|"adds predicates"| node_where
node_update -->|"accepts subquery"| node_select
node_select -->|"uses expressions"| node_expressions
node_insert -->|"uses expressions"| node_expressions
node_update -->|"uses expressions"| node_expressions
node_delete -->|"uses expressions"| node_expressions
node_case -->|"wraps parts"| node_parts
node_where -->|"builds parts"| node_parts
node_expressions -->|"formats placeholders"| node_placeholders
node_select -->|"formats placeholders"| node_placeholders
node_insert -->|"formats placeholders"| node_placeholders
node_update -->|"formats placeholders"| node_placeholders
node_delete -->|"formats placeholders"| node_placeholders
node_select -.->|"executes via"| node_runner
node_insert -->|"executes via"| node_runner
node_update -->|"executes via"| node_runner
node_delete -->|"executes via"| node_runner
node_runner -->|"runs SQL"| node_database
node_context -->|"runs context SQL"| node_database
node_runner -->|"wraps query row"| node_row
node_cache -->|"prepares statements"| node_database
node_caller -->|"may configure"| node_cache
node_caller -->|"may use context"| node_context

click node_statements "https://github.com/masterminds/squirrel/blob/master/statement.go"
click node_select "https://github.com/masterminds/squirrel/blob/master/select.go"
click node_insert "https://github.com/masterminds/squirrel/blob/master/insert.go"
click node_update "https://github.com/masterminds/squirrel/blob/master/update.go"
click node_delete "https://github.com/masterminds/squirrel/blob/master/delete.go"
click node_case "https://github.com/masterminds/squirrel/blob/master/case.go"
click node_expressions "https://github.com/masterminds/squirrel/blob/master/expr.go"
click node_where "https://github.com/masterminds/squirrel/blob/master/where.go"
click node_parts "https://github.com/masterminds/squirrel/blob/master/part.go"
click node_placeholders "https://github.com/masterminds/squirrel/blob/master/placeholder.go"
click node_runner "https://github.com/masterminds/squirrel/blob/master/squirrel.go"
click node_context "https://github.com/masterminds/squirrel/blob/master/squirrel_ctx.go"
click node_row "https://github.com/masterminds/squirrel/blob/master/row.go"
click node_cache "https://github.com/masterminds/squirrel/blob/master/stmtcacher.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_statements,node_select,node_insert,node_update,node_delete,node_case toneBlue
class node_expressions,node_where,node_parts,node_placeholders,node_database toneAmber
class node_runner,node_context,node_row,node_cache toneMint
class node_caller toneIndigo
```

## Components

### Builder API

- [Statement entrypoints](https://github.com/masterminds/squirrel/blob/master/statement.go): `statement.go`
- [SELECT builder](https://github.com/masterminds/squirrel/blob/master/select.go): `select.go`
- [INSERT builder](https://github.com/masterminds/squirrel/blob/master/insert.go): `insert.go`
- [UPDATE builder](https://github.com/masterminds/squirrel/blob/master/update.go): `update.go`
- [DELETE builder](https://github.com/masterminds/squirrel/blob/master/delete.go): `delete.go`
- [CASE expressions](https://github.com/masterminds/squirrel/blob/master/case.go): `case.go`

### SQL Composition

- [SQL expressions](https://github.com/masterminds/squirrel/blob/master/expr.go): `expr.go`
- [Predicate parts](https://github.com/masterminds/squirrel/blob/master/where.go): `where.go`
- [SQL parts](https://github.com/masterminds/squirrel/blob/master/part.go): `part.go`
- [Placeholder formats](https://github.com/masterminds/squirrel/blob/master/placeholder.go): `placeholder.go`

### Execution

- [Runner interfaces](https://github.com/masterminds/squirrel/blob/master/squirrel.go): `squirrel.go`
- [Context runners](https://github.com/masterminds/squirrel/blob/master/squirrel_ctx.go): `squirrel_ctx.go`
- [Row scanner](https://github.com/masterminds/squirrel/blob/master/row.go): `row.go`
- [Prepared statement cache](https://github.com/masterminds/squirrel/blob/master/stmtcacher.go): `stmtcacher.go`

### Other components

- **Go caller**
- **SQL database**

## Connections

- Go caller → Statement entrypoints: starts builders (evidence: `README.md`)
- Go caller → SELECT builder: composes SELECT (evidence: `README.md`)
- Go caller → INSERT builder: composes INSERT (evidence: `README.md`)
- Statement entrypoints → SELECT builder: creates (evidence: `statement.go`)
- Statement entrypoints → INSERT builder: creates (evidence: `statement.go`)
- Statement entrypoints → UPDATE builder: creates (evidence: `statement.go`)
- Statement entrypoints → DELETE builder: creates (evidence: `statement.go`)
- Statement entrypoints → CASE expressions: creates (evidence: `statement.go`)
- SELECT builder → Predicate parts: adds predicates (evidence: `select.go`)
- DELETE builder → Predicate parts: adds predicates (evidence: `delete.go`)
- UPDATE builder → SELECT builder: accepts subquery (evidence: `update.go`)
- SELECT builder → SQL expressions: uses expressions (evidence: `expr.go`)
- INSERT builder → SQL expressions: uses expressions (evidence: `insert.go`)
- UPDATE builder → SQL expressions: uses expressions (evidence: `update.go`)
- DELETE builder → SQL expressions: uses expressions (evidence: `delete.go`)
- CASE expressions → SQL parts: wraps parts (evidence: `case.go`)
- Predicate parts → SQL parts: builds parts (evidence: `where.go`)
- SQL expressions → Placeholder formats: formats placeholders (evidence: `expr.go`)
- SELECT builder → Placeholder formats: formats placeholders (evidence: `select.go`)
- INSERT builder → Placeholder formats: formats placeholders (evidence: `insert.go`)
- UPDATE builder → Placeholder formats: formats placeholders (evidence: `update.go`)
- DELETE builder → Placeholder formats: formats placeholders (evidence: `delete.go`)
- SELECT builder → Runner interfaces: executes via
- INSERT builder → Runner interfaces: executes via (evidence: `insert.go`)
- UPDATE builder → Runner interfaces: executes via (evidence: `update.go`)
- DELETE builder → Runner interfaces: executes via (evidence: `delete.go`)
- Runner interfaces → SQL database: runs SQL (evidence: `squirrel.go`)
- Context runners → SQL database: runs context SQL (evidence: `squirrel_ctx.go`)
- Runner interfaces → Row scanner: wraps query row (evidence: `squirrel.go`)
- Prepared statement cache → SQL database: prepares statements (evidence: `stmtcacher.go`)
- Go caller → Prepared statement cache: may configure (evidence: `README.md`)
- Go caller → Context runners: may use context (evidence: `squirrel_ctx.go`)
