@@ -47,13 +47,13 @@ func AsyncpgBuildQueryResults(body *builders.IndentStringBuilder) string {
4747 return "QueryResults"
4848}
4949
50- func AsyncpgBuildPyQueryFunc (query * core.Query , body * builders.IndentStringBuilder , args []core.FunctionArg , retType core.PyType , isClass bool ) error {
50+ func AsyncpgBuildPyQueryFunc (query * core.Query , body * builders.IndentStringBuilder , args []core.FunctionArg , retType core.PyType , conf * core. Config ) error {
5151 indentLevel := 0
5252 params := fmt .Sprintf ("conn: %s" , AsyncpgConn )
5353 conn := "conn"
5454 asyncFunc := "async "
5555 docstringConnType := AsyncpgConn
56- if isClass {
56+ if conf . EmitClasses {
5757 params = "self"
5858 conn = "self._conn"
5959 indentLevel = 1
@@ -84,27 +84,38 @@ func AsyncpgBuildPyQueryFunc(query *core.Query, body *builders.IndentStringBuild
8484 } else if query .Cmd == metadata .CmdExecRows {
8585 body .WriteLine (fmt .Sprintf (") -> %s:" , retType .Type ))
8686 body .WriteQueryFunctionDocstring (indentLevel + 1 , query , docstringConnType , args , retType )
87- body .WriteIndentedString (indentLevel + 1 , fmt .Sprintf ("result = await %s.execute(%s" , conn , query .ConstantName ))
87+ body .WriteIndentedString (indentLevel + 1 , fmt .Sprintf ("r = await %s.execute(%s" , conn , query .ConstantName ))
8888 asyncpgWriteParams (query , body )
8989 body .WriteLine (")" )
90- body .WriteIndentedLine (indentLevel + 1 , "return int(result.split()[-1]) if result.split()[-1].isdigit() else 0" )
90+ if conf .Speedups {
91+ body .WriteIndentedLine (indentLevel + 1 , "return int(n) if (n := r.split()[-1]).isdigit() else 0" )
92+ } else {
93+ body .WriteIndentedLine (indentLevel + 1 , "return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0" )
94+ }
9195 } else if query .Cmd == metadata .CmdCopyFrom {
9296 body .WriteLine (fmt .Sprintf (") -> %s:" , retType .Type ))
9397 body .WriteQueryFunctionDocstring (indentLevel + 1 , query , docstringConnType , args , retType )
9498 body .WriteIndentedLine (indentLevel + 1 , "records = [" )
9599 params := ""
100+ columns := ``
96101 for i , arg := range query .Args [0 ].Table .Columns {
97102 if i == len (query .Args [0 ].Table .Columns )- 1 && i != 0 {
98103 params += fmt .Sprintf ("%s.%s" , "param" , arg .Name )
104+ columns += fmt .Sprintf (`"%s"` , arg .Name )
99105 } else {
100106 params += fmt .Sprintf ("%s.%s, " , "param" , arg .Name )
107+ columns += fmt .Sprintf (`"%s", ` , arg .Name )
101108 }
102109 }
103110 body .WriteIndentedLine (indentLevel + 2 , fmt .Sprintf ("(%s)" , params ))
104111 body .WriteIndentedLine (indentLevel + 2 , fmt .Sprintf ("for param in %s" , query .Args [0 ].Name ))
105112 body .WriteIndentedLine (indentLevel + 1 , "]" )
106- body .WriteIndentedLine (indentLevel + 1 , fmt .Sprintf (`result = await %s.copy_records_to_table("%s", records=records)` , conn , query .Table .Name ))
107- body .WriteIndentedLine (indentLevel + 1 , "return int(result.split()[-1]) if result.split()[-1].isdigit() else 0" )
113+ body .WriteIndentedLine (indentLevel + 1 , fmt .Sprintf (`r = await %s.copy_records_to_table("%s", columns=[%s], records=records)` , conn , query .Table .Name , columns ))
114+ if conf .Speedups {
115+ body .WriteIndentedLine (indentLevel + 1 , "return int(n) if (n := r.split()[-1]).isdigit() else 0" )
116+ } else {
117+ body .WriteIndentedLine (indentLevel + 1 , "return int(n) if (p := r.split()) and (n := p[-1]).isdigit() else 0" )
118+ }
108119 } else if query .Cmd == metadata .CmdOne {
109120 body .WriteLine (fmt .Sprintf (") -> %s | None:" , retType .Type ))
110121 body .WriteQueryFunctionDocstring (indentLevel + 1 , query , docstringConnType , args , retType )
0 commit comments