8000 Use enums in func signatures too · cortea-ai/sqlc-gen-python@057e7fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 057e7fb

Browse files
committed
Use enums in func signatures too
1 parent fb986b8 commit 057e7fb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

internal/gen.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ type Enum struct {
3434
}
3535

3636
type pyType struct {
37-
InnerType string
38-
IsArray bool
39-
IsNull bool
37+
InnerType string
38+
IsArray bool
39+
IsNull bool
40+
HasCheckConstraints bool
4041
}
4142

4243
func (t pyType) Annotation(isFuncSignature bool) *pyast.Node {
43-
ann := poet.Name(t.InnerType)
44+
typ := t.InnerType
45+
if t.HasCheckConstraints {
46+
typ = MODELS_FILENAME + "." + t.InnerType
47+
}
48+
ann := poet.Name(typ)
4449
if t.IsArray {
4550
ann = subscriptNode("List", ann)
4651
}
@@ -255,9 +260,10 @@ func (q Query) ArgDictNode() *pyast.Node {
255260
func makePyType(req *plugin.GenerateRequest, col *plugin.Column) pyType {
256261
typ := pyInnerType(req, col)
257262
return pyType{
258-
InnerType: typ,
259-
IsArray: col.IsArray,
260-
IsNull: !col.NotNull,
263+
InnerType: typ,
264+
IsArray: col.IsArray,
265+
IsNull: !col.NotNull,
266+
HasCheckConstraints: len(col.CheckConstraints) > 0,
261267
}
262268
}
263269

0 commit comments

Comments
 (0)
0