Skip to content

Commit 9b397b7

Browse files
authored
Merge branch 'main' into feature/pgxv5-2
2 parents 3e14416 + f83ea82 commit 9b397b7

File tree

885 files changed

+203
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

885 files changed

+203
-64
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build-endtoend:
1717

1818
test-ci: test-examples build-endtoend
1919

20-
regen: sqlc-dev
20+
regen: sqlc-dev sqlc-gen-json
2121
go run ./scripts/regenerate/
2222

2323
sqlc-dev:
@@ -26,6 +26,9 @@ sqlc-dev:
2626
sqlc-pg-gen:
2727
go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen
2828

29+
sqlc-gen-json:
30+
go build -o ~/bin/sqlc-gen-json ./cmd/sqlc-gen-json
31+
2932
start:
3033
docker-compose up -d
3134

docs/reference/config.md

Lines changed: 56 additions & 5 deletions

docs/tutorials/getting-started-sqlite.md

Lines changed: 1 addition & 1 deletion

examples/python/sqlc.json

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,79 @@
11
{
22
"version": "2",
3+
"plugins": [
4+
{
5+
"name": "py",
6+
"wasm": {
7+
"url": "https://github.com/tabbed/sqlc-gen-python/releases/download/v0.16.0-alpha/sqlc-gen-python.wasm",
8+
"sha256": "428476c7408fd4c032da4ec74e8a7344f4fa75e0f98a5a3302f238283b9b95f2"
9+
}
10+
}
11+
],
312
"sql": [
413
{
514
"schema": "../authors/postgresql/schema.sql",
615
"queries": "../authors/postgresql/query.sql",
716
"engine": "postgresql",
8-
"gen": {
9-
"python": {
17+
"codegen": [
18+
{
1019
"out": "src/authors",
11-
"package": "authors",
12-
"emit_sync_querier": true,
13-
"emit_async_querier": true,
14-
"query_parameter_limit": 5
20+
"plugin": "py",
21+
"options": {
22+
"package": "authors",
23+
"emit_sync_querier": true,
24+
"emit_async_querier": true,
25+
"query_parameter_limit": 5
26+
}
1527
}
16-
}
28+
]
1729
},
1830
{
1931
"schema": "../booktest/postgresql/schema.sql",
2032
"queries": "../booktest/postgresql/query.sql",
2133
"engine": "postgresql",
22-
"gen": {
23-
"python": {
34+
"codegen": [
35+
{
2436
"out": "src/booktest",
25-
"package": "booktest",
26-
"emit_async_querier": true,
27-
"query_parameter_limit": 5
37+
"plugin": "py",
38+
"options": {
39+
"package": "booktest",
40+
"emit_async_querier": true,
41+
"query_parameter_limit": 5
42+
}
2843
}
29-
}
44+
]
3045
},
3146
{
3247
"schema": "../jets/schema.sql",
3348
"queries": "../jets/query-building.sql",
3449
"engine": "postgresql",
35-
"gen": {
36-
"python": {
50+
"codegen": [
51+
{
3752
"out": "src/jets",
38-
"package": "jets",
39-
"emit_async_querier": true,
40-
"query_parameter_limit": 5
53+
"plugin": "py",
54+
"options": {
55+
"package": "jets",
56+
"emit_async_querier": true,
57+
"query_parameter_limit": 5
58+
}
4159
}
42-
}
60+
]
4361
},
4462
{
4563
"schema": "../ondeck/postgresql/schema",
4664
"queries": "../ondeck/postgresql/query",
4765
"engine": "postgresql",
48-
"gen": {
49-
"python": {
66+
"codegen": [
67+
{
5068
"out": "src/ondeck",
51-
"package": "ondeck",
52-
"emit_async_querier": true,
53-
"query_parameter_limit": 5
69+
"plugin": "py",
70+
"options": {
71+
"package": "ondeck",
72+
"emit_async_querier": true,
73+
"query_parameter_limit": 5
74+
}
5475
}
55-
}
76+
]
5677
}
5778
]
5879
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e
7-
github.com/bytecodealliance/wasmtime-go v0.40.0
7+
github.com/bytecodealliance/wasmtime-go v1.0.0
88
github.com/davecgh/go-spew v1.1.1
99
github.com/go-sql-driver/mysql v1.6.0
1010
github.com/google/go-cmp v0.5.9
@@ -14,7 +14,7 @@ require (
1414
github.com/lib/pq v1.10.7
1515
github.com/mattn/go-sqlite3 v1.14.15
1616
github.com/pganalyze/pg_query_go/v2 v2.1.2
17-
github.com/spf13/cobra v1.5.0
17+
github.com/spf13/cobra v1.6.0
1818
github.com/spf13/pflag v1.0.5
1919
google.golang.org/protobuf v1.28.1
2020
gopkg.in/yaml.v3 v3.0.1
@@ -28,7 +28,7 @@ require (
2828

2929
require (
3030
github.com/golang/protobuf v1.5.2 // indirect
31-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
31+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
3232
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
3333
github.com/jackc/pgio v1.0.0 // indirect
3434
github.com/jackc/pgpassfile v1.0.0 // indirect

go.sum

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e h1:b
55
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
66
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
77
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
8-
github.com/bytecodealliance/wasmtime-go v0.40.0 h1:7cGLQEctJf09JWBl3Ai0eMl1PTrXVAjkAb27+KHfIq0=
9-
github.com/bytecodealliance/wasmtime-go v0.40.0/go.mod h1:q320gUxqyI8yB+ZqRuaJOEnGkAnHh6WtJjMaT2CW4wI=
8+
github.com/bytecodealliance/wasmtime-go v1.0.0 h1:9u9gqaUiaJeN5IoD1L7egD8atOnTGyJcNp8BhkL9cUU=
9+
github.com/bytecodealliance/wasmtime-go v1.0.0/go.mod h1:jjlqQbWUfVSbehpErw3UoWFndBXRRMvfikYH6KsCwOg=
1010
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
1111
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
1212
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
@@ -42,8 +42,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
4242
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
4343
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
4444
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
45-
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
46-
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
45+
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
46+
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4747
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
4848
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
4949
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -97,8 +97,6 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
9797
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
9898
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
9999
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
100-
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
101-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
102100
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
103101
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
104102
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
@@ -116,6 +114,7 @@ github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
116114
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
117115
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
118116
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
117+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
119118
github.com/pganalyze/pg_query_go/v2 v2.1.2 h1:LiNm3WoBV/cc144X6jlVKD5DPL+fI2wfvCXT7z25B8U=
120119
github.com/pganalyze/pg_query_go/v2 v2.1.2/go.mod h1:XAxmVqz1tEGqizcQ3YSdN90vCOHBWjJi8URL1er5+cA=
121120
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
@@ -143,8 +142,8 @@ github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXY
143142
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
144143
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
145144
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
146-
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
147-
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
145+
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
146+
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
148147
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
149148
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
150149
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -262,16 +261,15 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
262261
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
263262
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
264263
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
265-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
266264
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
265+
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
267266
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
268267
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
269268
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
270269
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
271270
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
271+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
272272
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
273-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
274-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
275273
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
276274
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
277275
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/cmd/generate.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/kyleconroy/sqlc/internal/codegen/python"
1818
"github.com/kyleconroy/sqlc/internal/compiler"
1919
"github.com/kyleconroy/sqlc/internal/config"
20+
"github.com/kyleconroy/sqlc/internal/config/convert"
2021
"github.com/kyleconroy/sqlc/internal/debug"
2122
"github.com/kyleconroy/sqlc/internal/ext"
2223
"github.com/kyleconroy/sqlc/internal/ext/process"
@@ -300,6 +301,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
300301
if debug.Traced {
301302
region = trace.StartRegion(ctx, "codegen")
302303
}
304+
req := codeGenRequest(result, combo)
303305
var handler ext.Handler
304306
var out string
305307
switch {
@@ -340,10 +342,16 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
340342
return "", nil, fmt.Errorf("unsupported plugin type")
341343
}
342344

345+
opts, err := convert.YAMLtoJSON(sql.Plugin.Options)
346+
if err != nil {
347+
return "", nil, fmt.Errorf("invalid plugin options")
348+
}
349+
req.PluginOptions = opts
350+
343351
default:
344352
return "", nil, fmt.Errorf("missing language backend")
345353
}
346-
resp, err := handler.Generate(ctx, codeGenRequest(result, combo))
354+
resp, err := handler.Generate(ctx, req)
347355
if region != nil {
348356
region.End()
349357
}

internal/endtoend/testdata/codegen_json/gen/codegen.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49697,5 +49697,6 @@
4969749697
"insert_into_table": null
4969849698
}
4969949699
],
49700-
"sqlc_version": "v1.15.0"
49700+
"sqlc_version": "v1.15.0",
49701+
"plugin_options": ""
4970149702
}

0 commit comments

Comments
 (0)