Skip to content

Commit

Permalink
Implement exec rows and exec result
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy committed Dec 15, 2021
1 parent 963cf0d commit cc8cf38
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/codegen/python/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,15 @@ func buildQueryTree(ctx *pyTmplCtx, i *importer, source string) *pyast.Node {
f.Body = append(f.Body, exec)
f.Returns = poet.Constant(nil)
case ":execrows":
f.Body = append(f.Body,
assignNode("result", exec),
poet.Return(poet.Attribute(poet.Name("result"), "rowcount")),
)
f.Returns = poet.Name("int")
case ":execresult":
f.Body = append(f.Body,
poet.Return(exec),
)
f.Returns = typeRefNode("sqlalchemy", "engine", "Result")
default:
panic("unknown cmd " + q.Cmd)
Expand Down Expand Up @@ -1089,8 +1096,15 @@ func buildQueryTree(ctx *pyTmplCtx, i *importer, source string) *pyast.Node {
f.Body = append(f.Body, poet.Await(exec))
f.Returns = poet.Constant(nil)
case ":execrows":
f.Body = append(f.Body,
assignNode("result", poet.Await(exec)),
poet.Return(poet.Attribute(poet.Name("result"), "rowcount")),
)
f.Returns = poet.Name("int")
case ":execresult":
f.Body = append(f.Body,
poet.Return(poet.Await(exec)),
)
f.Returns = typeRefNode("sqlalchemy", "engine", "Result")
default:
panic("unknown cmd " + q.Cmd)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Code generated by sqlc. DO NOT EDIT.


import dataclasses




@dataclasses.dataclass()
class Bar:
id: int


Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Code generated by sqlc. DO NOT EDIT.


import dataclasses




@dataclasses.dataclass()
class Bar:
id: int


0 comments on commit cc8cf38

Please sign in to comment.