@@ -97,7 +97,21 @@ proc genQueryIterator(sql: string, body: NimNode): NimNode =
97
97
result = body.copy()
98
98
let db_ident = genSym(nskParam, " db" )
99
99
let st_ident = genSym(nskVar, " st" )
100
- let rettype = result [3 ][0 ]
100
+
101
+ let rettype = block :
102
+ case result [3 ][0 ].kind
103
+ of nnkTupleTy:
104
+ result [3 ][0 ]
105
+ of nnkSym:
106
+ let typeDef = result [3 ][0 ].getImpl
107
+ typeDef.expectKind nnkTypeDef
108
+ let tuplDef = typeDef[2 ]
109
+ tuplDef.expectKind nnkTupleTy
110
+ tuplDef
111
+ else :
112
+ error " Expected a tuple type" , result [3 ][0 ]
113
+ nil
114
+
101
115
injectDbDecl(result , db_ident)
102
116
result [6 ] = nnkStmtList.genTree(procbody):
103
117
injectDbFetch(procbody, sql, db_ident, st_ident)
@@ -207,8 +221,12 @@ macro importdb*(sql: static string, body: typed) =
207
221
error(" Expected int, tuple, Option[tuple]" )
208
222
return
209
223
of nnkIteratorDef:
210
- body[3 ][0 ].expectKind nnkTupleTy
211
- result = genQueryIterator(sql, body)
224
+ let retType = body[3 ][0 ]
225
+ case retType.kind
226
+ of nnkTupleTy, nnkSym:
227
+ result = genQueryIterator(sql, body)
228
+ else :
229
+ error(" Expected a tuple type" , retType)
212
230
else :
213
231
error(" Expected proc or iterator, got " & $ body.kind, body)
214
232
return
0 commit comments