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

Commit5f6b0eb

Browse files
feat: Update sqlc go sdk dependency (#31)
1 parent50a4af0 commit5f6b0eb

File tree

5 files changed

+44
-74
lines changed

5 files changed

+44
-74
lines changed

‎go.mod

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

55
require (
6-
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.31.0-20231002190240-3f2d312ab6fd.1
76
github.com/google/go-cmpv0.6.0
87
github.com/jinzhu/inflectionv1.0.0
9-
github.com/sqlc-dev/sqlc-gov1.22.0
8+
github.com/sqlc-dev/sqlc-gov1.22.1-0.20231102170509-ee94c710d92e
109
google.golang.org/protobufv1.31.0
1110
)
11+
12+
require (
13+
github.com/golang/protobufv1.5.3// indirect
14+
golang.org/x/netv0.14.0// indirect
15+
golang.org/x/sysv0.11.0// indirect
16+
golang.org/x/textv0.12.0// indirect
17+
google.golang.org/genproto/googleapis/rpcv0.0.0-20230822172742-b8732ec3820d// indirect
18+
google.golang.org/grpcv1.59.0// indirect
19+
)

‎go.sum

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.31.0-20231002190240-3f2d312ab6fd.1 h1:94JzirpGhebc3++MqmvWY0fi9TJxlle5M52NO4pTEZY=
2-
buf.build/gen/go/sqlc/sqlc/protocolbuffers/gov1.31.0-20231002190240-3f2d312ab6fd.1/go.mod h1:x7kMRcmAiYQXko+NDqLP2agondNlbHKUNGPXqU1nrOU=
31
github.com/golang/protobufv1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2+
github.com/golang/protobufv1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
3+
github.com/golang/protobufv1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
44
github.com/google/go-cmpv0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
55
github.com/google/go-cmpv0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
66
github.com/google/go-cmpv0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
77
github.com/jinzhu/inflectionv1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
88
github.com/jinzhu/inflectionv1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
9-
github.com/sqlc-dev/sqlc-gov1.22.0 h1:ivUplxHRkw1WZ++rs80OfoJLYbpXMXYGtc79e7z/0HA=
10-
github.com/sqlc-dev/sqlc-gov1.22.0/go.mod h1:/4snw3ucbglJfyLRxp8X2weM4pwT8w1NlEKm4PzxAuQ=
9+
github.com/sqlc-dev/sqlc-gov1.22.1-0.20231102170509-ee94c710d92e h1:fgvOWVSJLVvl1ETExPEw2okhTj2kbxvAQ5ECLrAtWbQ=
10+
github.com/sqlc-dev/sqlc-gov1.22.1-0.20231102170509-ee94c710d92e/go.mod h1:SXs+GYtPBUfDJQWSOvcJesiAwj4HNfigK7EwzwpHNPk=
11+
golang.org/x/netv0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
12+
golang.org/x/netv0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
13+
golang.org/x/sysv0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
14+
golang.org/x/sysv0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15+
golang.org/x/textv0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
16+
golang.org/x/textv0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
1117
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
18+
google.golang.org/genproto/googleapis/rpcv0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
19+
google.golang.org/genproto/googleapis/rpcv0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
20+
google.golang.org/grpcv1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
21+
google.golang.org/grpcv1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
1222
google.golang.org/protobufv1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
23+
google.golang.org/protobufv1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
1324
google.golang.org/protobufv1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
1425
google.golang.org/protobufv1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

‎internal/gen.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"sort"
1111
"strings"
1212

13-
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
1413
"github.com/sqlc-dev/sqlc-go/metadata"
14+
"github.com/sqlc-dev/sqlc-go/plugin"
1515
"github.com/sqlc-dev/sqlc-go/sdk"
1616

1717
pyast"github.com/sqlc-dev/sqlc-gen-python/internal/ast"
@@ -180,7 +180,7 @@ func (q Query) ArgDictNode() *pyast.Node {
180180
}
181181
}
182182

183-
funcmakePyType(req*plugin.CodeGenRequest,col*plugin.Column)pyType {
183+
funcmakePyType(req*plugin.GenerateRequest,col*plugin.Column)pyType {
184184
typ:=pyInnerType(req,col)
185185
returnpyType{
186186
InnerType:typ,
@@ -189,21 +189,7 @@ func makePyType(req *plugin.CodeGenRequest, col *plugin.Column) pyType {
189189
}
190190
}
191191

192-
funcpyInnerType(req*plugin.CodeGenRequest,col*plugin.Column)string {
193-
columnType:=sdk.DataType(col.Type)
194-
for_,oride:=rangereq.Settings.Overrides {
195-
if!pyTypeIsSet(oride) {
196-
continue
197-
}
198-
sameTable:=sdk.Matches(oride,col.Table,req.Catalog.DefaultSchema)
199-
iforide.Column!=""&&sdk.MatchString(oride.ColumnName,col.Name)&&sameTable {
200-
returnoride.CodeType
201-
}
202-
iforide.DbType!=""&&oride.DbType==columnType&&oride.Nullable!= (col.NotNull||col.IsArray) {
203-
returnoride.CodeType
204-
}
205-
}
206-
192+
funcpyInnerType(req*plugin.GenerateRequest,col*plugin.Column)string {
207193
switchreq.Settings.Engine {
208194
case"postgresql":
209195
returnpostgresType(req,col)
@@ -214,9 +200,6 @@ func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
214200
}
215201

216202
funcmodelName(namestring,settings*plugin.Settings)string {
217-
ifrename:=settings.Rename[name];rename!="" {
218-
returnrename
219-
}
220203
out:=""
221204
for_,p:=rangestrings.Split(name,"_") {
222205
out+=strings.Title(p)
@@ -243,7 +226,7 @@ func pyEnumValueName(value string) string {
243226
returnstrings.ToUpper(id)
244227
}
245228

246-
funcbuildEnums(req*plugin.CodeGenRequest) []Enum {
229+
funcbuildEnums(req*plugin.GenerateRequest) []Enum {
247230
varenums []Enum
248231
for_,schema:=rangereq.Catalog.Schemas {
249232
ifschema.Name=="pg_catalog"||schema.Name=="information_schema" {
@@ -276,7 +259,7 @@ func buildEnums(req *plugin.CodeGenRequest) []Enum {
276259
returnenums
277260
}
278261

279-
funcbuildModels(confConfig,req*plugin.CodeGenRequest) []Struct {
262+
funcbuildModels(confConfig,req*plugin.GenerateRequest) []Struct {
280263
varstructs []Struct
281264
for_,schema:=rangereq.Catalog.Schemas {
282265
ifschema.Name=="pg_catalog"||schema.Name=="information_schema" {
@@ -338,7 +321,7 @@ type pyColumn struct {
338321
*plugin.Column
339322
}
340323

341-
funccolumnsToStruct(req*plugin.CodeGenRequest,namestring,columns []pyColumn)*Struct {
324+
funccolumnsToStruct(req*plugin.GenerateRequest,namestring,columns []pyColumn)*Struct {
342325
gs:=Struct{
343326
Name:name,
344327
}
@@ -380,7 +363,7 @@ func sqlalchemySQL(s, engine string) string {
380363
returns
381364
}
382365

383-
funcbuildQueries(confConfig,req*plugin.CodeGenRequest,structs []Struct) ([]Query,error) {
366+
funcbuildQueries(confConfig,req*plugin.GenerateRequest,structs []Struct) ([]Query,error) {
384367
qs:=make([]Query,0,len(req.Queries))
385368
for_,query:=rangereq.Queries {
386369
ifquery.Name=="" {
@@ -1091,7 +1074,7 @@ func HashComment(s string) string {
10911074
return"# "+strings.ReplaceAll(s,"\n","\n# ")
10921075
}
10931076

1094-
funcGenerate(_ context.Context,req*plugin.CodeGenRequest) (*plugin.CodeGenResponse,error) {
1077+
funcGenerate(_ context.Context,req*plugin.GenerateRequest) (*plugin.GenerateResponse,error) {
10951078
varconfConfig
10961079
iflen(req.PluginOptions)>0 {
10971080
iferr:=json.Unmarshal(req.PluginOptions,&conf);err!=nil {
@@ -1107,11 +1090,10 @@ func Generate(_ context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenRes
11071090
}
11081091

11091092
i:=&importer{
1110-
Settings:req.Settings,
1111-
Models:models,
1112-
Queries:queries,
1113-
Enums:enums,
1114-
C:conf,
1093+
Models:models,
1094+
Queries:queries,
1095+
Enums:enums,
1096+
C:conf,
11151097
}
11161098

11171099
tctx:=pyTmplCtx{
@@ -1143,7 +1125,7 @@ func Generate(_ context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenRes
11431125
output[name]=string(result.Python)
11441126
}
11451127

1146-
resp:= plugin.CodeGenResponse{}
1128+
resp:= plugin.GenerateResponse{}
11471129

11481130
forfilename,code:=rangeoutput {
11491131
resp.Files=append(resp.Files,&plugin.File{

‎internal/imports.go

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"sort"
66
"strings"
7-
8-
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
97
)
108

119
typeimportSpecstruct {
@@ -14,10 +12,6 @@ type importSpec struct {
1412
Aliasstring
1513
}
1614

17-
funcpyTypeIsSet(o*plugin.Override)bool {
18-
returno.CodeType!=""
19-
}
20-
2115
func (iimportSpec)String()string {
2216
ifi.Alias!="" {
2317
ifi.Name=="" {
@@ -32,11 +26,10 @@ func (i importSpec) String() string {
3226
}
3327

3428
typeimporterstruct {
35-
Settings*plugin.Settings
36-
Models []Struct
37-
Queries []Query
38-
Enums []Enum
39-
CConfig
29+
Models []Struct
30+
Queries []Query
31+
Enums []Enum
32+
CConfig
4033
}
4134

4235
funcstructUses(namestring,sStruct)bool {
@@ -104,18 +97,6 @@ func (i *importer) modelImportSpecs() (map[string]importSpec, map[string]importS
10497

10598
pkg:=make(map[string]importSpec)
10699

107-
for_,o:=rangei.Settings.Overrides {
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}
115-
}
116-
}
117-
}
118-
119100
returnstd,pkg
120101
}
121102

@@ -155,18 +136,6 @@ func (i *importer) queryImportSpecs(fileName string) (map[string]importSpec, map
155136
pkg["sqlalchemy.ext.asyncio"]=importSpec{Module:"sqlalchemy.ext.asyncio"}
156137
}
157138

158-
for_,o:=rangei.Settings.Overrides {
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}
166-
}
167-
}
168-
}
169-
170139
queryValueModelImports:=func(qvQueryValue) {
171140
ifqv.IsStruct()&&qv.EmitStruct() {
172141
ifi.C.EmitPydanticModels {

‎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-
"buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
6+
"github.com/sqlc-dev/sqlc-go/plugin"
77
"github.com/sqlc-dev/sqlc-go/sdk"
88
)
99

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

1313
switchcolumnType {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp