Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e8e0a3

Browse files
authored
sqlc-gen-python: Build using Go 1.21rc2 (#10)
* sqlc-gen-python: Build using Go 1.21rc2* deps: Use go-sdk v1.18.0* Use go1.21rc* Don't hardcode path
1 parent827dea5 commit7e8e0a3

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

‎.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ jobs:
1010
runs-on:ubuntu-latest
1111
steps:
1212
-uses:actions/checkout@v3
13-
-uses:actions/setup-go@v3
13+
-uses:actions/setup-go@v4
1414
with:
15-
go-version:'1.19'
16-
-run:wget https://github.com/tinygo-org/tinygo/releases/download/v0.26.0/tinygo_0.26.0_amd64.deb
17-
-run:sudo dpkg -i tinygo_0.26.0_amd64.deb
15+
go-version:'1.21.0-rc.2'
1816
-run:make

‎Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ sqlc-gen-python:
44
cd plugin&& go build -o~/bin/sqlc-gen-python ./main.go
55

66
sqlc-gen-python.wasm:
7-
cd plugin&&tinygobuild -o sqlc-gen-python.wasm -gc=leaking -scheduler=none -wasm-abi=generic -target=wasi main.go
7+
cd plugin&&GOOS=wasip1 GOARCH=wasm gobuild -o sqlc-gen-python.wasm main.go
88
openssl sha256 plugin/sqlc-gen-python.wasm
9-

‎go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module github.com/tabbed/sqlc-gen-python
33
go1.19
44

55
require (
6+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.30.0-20230621221448-196413f69ab3.1
67
github.com/google/go-cmpv0.5.9
78
github.com/jinzhu/inflectionv1.0.0
89
github.com/mailru/easyjsonv0.7.7
9-
github.com/tabbed/sqlc-gov1.16.0
10-
google.golang.org/protobufv1.28.1
10+
github.com/tabbed/sqlc-gov1.18.0
11+
google.golang.org/protobufv1.30.0
1112
)
1213

1314
requiregithub.com/josharian/internv1.0.0// indirect

‎go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.30.0-20230621221448-196413f69ab3.1 h1:ze0HODAjPRXSkiqSpDTYq2baS4IVtRtDLSZY2p1ZCX4=
2+
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.30.0-20230621221448-196413f69ab3.1/go.mod h1:DSpReHp8PwHOeCfGymiiY4HSx2iVL358X7JRMciL7T0=
13
github.com/golang/protobufv1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
24
github.com/google/go-cmpv0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
35
github.com/google/go-cmpv0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
@@ -10,7 +12,9 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
1012
github.com/mailru/easyjsonv0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
1113
github.com/tabbed/sqlc-gov1.16.0 h1:EwPBXdGn5tyrLjcNiHRoQthWvJeF5NjG9Cx1WK5iFsY=
1214
github.com/tabbed/sqlc-gov1.16.0/go.mod h1:mqMU5duZRGz5Wp/qJXwkERf+MXgGOZ8BmW/tH9KyvWA=
15+
github.com/tabbed/sqlc-gov1.18.0 h1:GNE8b8xue8fKVptQnr3Z6DV8FqdokyDYML7O0kYtbe4=
16+
github.com/tabbed/sqlc-gov1.18.0/go.mod h1:qx8ocsmviBDyRfLNuJQtdu0f5oqa8XBjKxMldl+Wm24=
1317
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1418
google.golang.org/protobufv1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
15-
google.golang.org/protobufv1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
16-
google.golang.org/protobufv1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
19+
google.golang.org/protobufv1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
20+
google.golang.org/protobufv1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

‎internal/gen.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"sort"
1010
"strings"
1111

12+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
1213
easyjson"github.com/mailru/easyjson"
13-
plugin"github.com/tabbed/sqlc-go/codegen"
1414
"github.com/tabbed/sqlc-go/metadata"
1515
"github.com/tabbed/sqlc-go/sdk"
1616

@@ -192,15 +192,15 @@ func makePyType(req *plugin.CodeGenRequest, col *plugin.Column) pyType {
192192
funcpyInnerType(req*plugin.CodeGenRequest,col*plugin.Column)string {
193193
columnType:=sdk.DataType(col.Type)
194194
for_,oride:=rangereq.Settings.Overrides {
195-
if!pyTypeIsSet(oride.PythonType) {
195+
if!pyTypeIsSet(oride) {
196196
continue
197197
}
198198
sameTable:=sdk.Matches(oride,col.Table,req.Catalog.DefaultSchema)
199199
iforide.Column!=""&&sdk.MatchString(oride.ColumnName,col.Name)&&sameTable {
200-
returnpyTypeString(oride.PythonType)
200+
returnoride.CodeType
201201
}
202202
iforide.DbType!=""&&oride.DbType==columnType&&oride.Nullable!= (col.NotNull||col.IsArray) {
203-
returnpyTypeString(oride.PythonType)
203+
returnoride.CodeType
204204
}
205205
}
206206

@@ -1091,7 +1091,7 @@ func HashComment(s string) string {
10911091
return"# "+strings.ReplaceAll(s,"\n","\n# ")
10921092
}
10931093

1094-
funcGenerate(_ context.Context,req*plugin.Request) (*plugin.Response,error) {
1094+
funcGenerate(_ context.Context,req*plugin.CodeGenRequest) (*plugin.CodeGenResponse,error) {
10951095
varconfConfig
10961096
iflen(req.PluginOptions)>0 {
10971097
iferr:=easyjson.Unmarshal(req.PluginOptions,&conf);err!=nil {
@@ -1143,7 +1143,7 @@ func Generate(_ context.Context, req *plugin.Request) (*plugin.Response, error)
11431143
output[name]=string(result.Python)
11441144
}
11451145

1146-
resp:= plugin.Response{}
1146+
resp:= plugin.CodeGenResponse{}
11471147

11481148
forfilename,code:=rangeoutput {
11491149
resp.Files=append(resp.Files,&plugin.File{

‎internal/imports.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"sort"
66
"strings"
77

8-
"github.com/tabbed/sqlc-go/codegen"
8+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
99
)
1010

1111
typeimportSpecstruct {
@@ -14,15 +14,8 @@ type importSpec struct {
1414
Aliasstring
1515
}
1616

17-
funcpyTypeIsSet(t*codegen.PythonType)bool {
18-
returnt.Module!=""||t.Name!=""
19-
}
20-
21-
funcpyTypeString(t*codegen.PythonType)string {
22-
ift.Name!=""&&t.Module=="" {
23-
returnt.Name
24-
}
25-
returnt.Module+"."+t.Name
17+
funcpyTypeIsSet(o*plugin.Override)bool {
18+
returno.CodeType!=""
2619
}
2720

2821
func (iimportSpec)String()string {
@@ -39,7 +32,7 @@ func (i importSpec) String() string {
3932
}
4033

4134
typeimporterstruct {
42-
Settings*codegen.Settings
35+
Settings*plugin.Settings
4336
Models []Struct
4437
Queries []Query
4538
Enums []Enum
@@ -112,12 +105,17 @@ func (i *importer) modelImportSpecs() (map[string]importSpec, map[string]importS
112105
pkg:=make(map[string]importSpec)
113106

114107
for_,o:=rangei.Settings.Overrides {
115-
ifpyTypeIsSet(o.PythonType)&&o.PythonType.Module!="" {
116-
ifmodelUses(pyTypeString(o.PythonType)) {
117-
pkg[o.PythonType.Module]=importSpec{Module:o.PythonType.Module}
108+
ifpyTypeIsSet(o) {
109+
mod,_,found:=strings.Cut(o.CodeType,".")
110+
if!found {
111+
continue
112+
}
113+
ifmodelUses(o.CodeType) {
114+
pkg[mod]=importSpec{Module:mod}
118115
}
119116
}
120117
}
118+
121119
returnstd,pkg
122120
}
123121

@@ -158,9 +156,13 @@ func (i *importer) queryImportSpecs(fileName string) (map[string]importSpec, map
158156
}
159157

160158
for_,o:=rangei.Settings.Overrides {
161-
ifpyTypeIsSet(o.PythonType)&&o.PythonType.Module!="" {
162-
ifqueryUses(pyTypeString(o.PythonType)) {
163-
pkg[o.PythonType.Module]=importSpec{Module:o.PythonType.Module}
159+
ifpyTypeIsSet(o) {
160+
mod,_,found:=strings.Cut(o.CodeType,".")
161+
if!found {
162+
continue
163+
}
164+
ifqueryUses(o.CodeType) {
165+
pkg[mod]=importSpec{Module:mod}
164166
}
165167
}
166168
}

‎internal/postgresql_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package python
33
import (
44
"log"
55

6-
"github.com/tabbed/sqlc-go/codegen"
6+
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
77
"github.com/tabbed/sqlc-go/sdk"
88
)
99

10-
funcpostgresType(req*codegen.Request,col*codegen.Column)string {
10+
funcpostgresType(req*plugin.CodeGenRequest,col*plugin.Column)string {
1111
columnType:=sdk.DataType(col.Type)
1212

1313
switchcolumnType {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp