Repository navigation
Expand file tree
/
Copy pathsqlc.yaml
More file actions
84 lines (84 loc) · 4.01 KB
/
Copy pathsqlc.yaml
File metadata and controls
84 lines (84 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# sqlc turns internal/store/queries/*.sql into typed Go in internal/store/sqlcgen, against the
# schema the migrations build, and internal/store/cache/queries/*.sql into internal/store/cachegen,
# against cache.db's one schema file. `make generate` runs `sqlc generate` then `sqlc vet`; the output is
# committed and `make check` fails if it is stale or hand-edited. Rules: standards/sql.md.
version: "2"
sql:
- engine: sqlite
schema: internal/store/migrations
queries: internal/store/queries
rules:
- no-unbounded-write
- upsert-only-if-changed
gen:
go:
package: sqlcgen
out: internal/store/sqlcgen
# The SQLite engine generates for database/sql; the pure-Go driver registers with it
# (D31). pgx is PostgreSQL-only.
sql_package: database/sql
# Generated rows are store types, never wire types: the API maps them to its own
# camelCase structs, so nothing generated is marshalled.
emit_json_tags: false
emit_db_tags: false
# A nullable column is *T, not sql.NullT, so callers see absence as nil.
emit_pointers_for_null_types: true
# A :many query with no rows returns an empty slice, never nil.
emit_empty_slices: true
# One Queries type with methods; callers depend on the small interfaces they declare.
emit_interface: false
emit_prepared_queries: false
emit_exact_table_names: false
emit_result_struct_pointers: false
emit_params_struct_pointers: false
omit_unused_structs: true
# Every parameter list becomes a Params struct once it has two or more parameters, so
# a call site names each value.
query_parameter_limit: 1
# Initialisms read as hand-written Go reads them (ArgsJSON, NFOBody, TruePeakDBTP):
# sqlc's default knows only "id". SHA-256 is Sha256 in both, as sqlc spells it unasked.
initialisms: [id, json, nfo, vtt, ass, db, dbtp, lufs, lu]
# cache.db: one schema file, versioned by discard (migrations.md), generating its own package
# so a library query cannot name a cache table (M2-1).
- engine: sqlite
schema: internal/store/cache/schema.sql
queries: internal/store/cache/queries
rules:
- no-unbounded-write
- upsert-only-if-changed
gen:
go:
package: cachegen
out: internal/store/cachegen
sql_package: database/sql
emit_json_tags: false
emit_db_tags: false
emit_pointers_for_null_types: true
emit_empty_slices: true
emit_interface: false
emit_prepared_queries: false
emit_exact_table_names: false
emit_result_struct_pointers: false
emit_params_struct_pointers: false
omit_unused_structs: true
query_parameter_limit: 1
initialisms: [id, json, nfo, vtt, ass, db, dbtp, lufs, lu]
# `sqlc vet` sees each query after sqlc has expanded `*` into a column list, so a SELECT * rule
# here could never fire; TestArch_QueriesNameEveryColumn reads the .sql files instead.
rules:
- name: no-unbounded-write
message: "an UPDATE or DELETE without WHERE rewrites the whole table; say which rows (standards/sql.md)"
rule: >-
query.sql.matches("(?is)^(\\s|--[^\\n]*\\n)*(update|delete)\\b")
&& !query.sql.matches("(?is)\\bwhere\\b")
# D303 (DL9): SQLite rewrites a row an upsert's DO UPDATE names, and fires its triggers, whatever
# the values; a write that changes nothing must write nothing. A query whose upsert must touch
# the row regardless (one that returns it) opts out with `-- @sqlc-vet-disable
# upsert-only-if-changed` and says why.
- name: upsert-only-if-changed
message: "an ON CONFLICT DO UPDATE with no WHERE rewrites the row, and fires its triggers, even when nothing changed; guard it with WHERE (columns) IS NOT (new values) (standards/sql.md section 13, DL9)"
rule: >-
query.sql.matches("(?is)\\bdo\\s+update\\b")
&& !query.sql.matches("(?is)\\bdo\\s+update\\b.*\\bwhere\\b")