You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto/generate.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,3 +74,23 @@ sql:
74
74
75
75
Databases configured with a `uri` must have an up-to-date schema for query analysis to work correctly, and `sqlc` does not apply schema migrations your database. Use your migration tool of choice to create the necessary
76
76
tables and objects before running `sqlc generate`.
77
+
78
+
## Enhanced analysis with a local container
79
+
80
+
If you have Docker available, `sqlc` can automatically start a local PostgreSQL container, apply your schema, and use it for query analysis — no external database required. Currently supported for PostgreSQL only. Set `testcontainers_image` to the Docker image you want to use:
81
+
82
+
```yaml
83
+
version: "2"
84
+
sql:
85
+
- engine: "postgresql"
86
+
queries: "query.sql"
87
+
schema: "schema.sql"
88
+
database:
89
+
testcontainers_image: "postgres:18-alpine"
90
+
gen:
91
+
go:
92
+
out: "db"
93
+
sql_package: "pgx/v5"
94
+
```
95
+
96
+
`testcontainers_image`is mutually exclusive with `uri` and `managed`.
Copy file name to clipboardExpand all lines: docs/howto/managed-databases.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,3 +99,7 @@ sql:
99
99
rules:
100
100
- sqlc/db-prepare
101
101
```
102
+
103
+
## Local alternative
104
+
105
+
If you prefer not to use managed databases, you can use [`testcontainers_image`](generate.md#enhanced-analysis-with-a-local-container) to have `sqlc` spin up a local PostgreSQL container automatically using Docker.
Copy file name to clipboardExpand all lines: docs/reference/config.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,8 @@ The `database` mapping supports the following keys:
97
97
- If true, connect to a [managed database](../howto/managed-databases.md). Defaults to `false`.
98
98
- `uri`:
99
99
- Database connection URI
100
+
- `testcontainers_image`:
101
+
- Docker image to start a local PostgreSQL container automatically (e.g. `postgres:18-alpine`). Currently supported for PostgreSQL only. Mutually exclusive with `uri` and `managed`.
100
102
101
103
The `uri` string can contain references to environment variables using the `${...}`
102
104
syntax. In the following example, the connection string will have the value of
0 commit comments