@@ -89,7 +89,7 @@ proc fillPar(ret, st_ident: NimNode): NimNode =
89
89
bindSym " getColumn"
90
90
),
91
91
newLit idx,
92
- it[1 ]
92
+ nnkBracketExpr.newTree(newIdentNode( " typedesc " ), it[1 ])
93
93
)
94
94
)
95
95
@@ -114,7 +114,7 @@ proc genQueryProcedure(sql: string, body, tupdef: NimNode, opt: static bool): Ni
114
114
let rettype = when opt:
115
115
result [3 ][0 ][1 ]
116
116
else :
117
- result [ 3 ][ 0 ]
117
+ tupdef
118
118
injectDbDecl(result , db_ident)
119
119
result [6 ] = nnkStmtList.genTree(procbody):
120
120
injectDbFetch(procbody, sql, db_ident, st_ident)
@@ -180,16 +180,23 @@ proc genCreateProcedure(sql: string, body: NimNode): NimNode =
180
180
nnkCall.newTree(bindSym " newException" , ident " SQLiteError" , newLit " Invalid statement" )
181
181
)
182
182
183
- macro importdb* (sql: static string , body: untyped ) =
183
+ macro importdb* (sql: static string , body: typed ) =
184
184
case body.kind:
185
185
of nnkProcDef:
186
186
let ret = body[3 ][0 ]
187
187
case ret.kind:
188
188
of nnkEmpty:
189
189
result = genCreateProcedure(sql, body)
190
- of nnkIdent:
191
- ret.expectIdent " int"
192
- result = genUpdateProcedure(sql, body)
190
+ of nnkSym:
191
+ case ret.strVal:
192
+ of " int" :
193
+ result = genUpdateProcedure(sql, body)
194
+ else :
195
+ let typImpl = ret.getImpl
196
+ typImpl.expectKind nnkTypeDef
197
+ let tuplImpl = typImpl[2 ]
198
+ tuplImpl.expectKind nnkTupleTy
199
+ result = genQueryProcedure(sql, body, tuplImpl, false )
193
200
of nnkBracketExpr:
194
201
ret[0 ].expectIdent " Option"
195
202
ret[1 ].expectKind nnkTupleTy
@@ -205,6 +212,14 @@ macro importdb*(sql: static string, body: untyped) =
205
212
else :
206
213
error(" Expected proc or iterator, got " & $ body.kind, body)
207
214
return
215
+
216
+ if result [0 ].isExported:
217
+ result [0 ] = nnkPostfix.newTree(
218
+ " *" .ident,
219
+ result [0 ].strVal.ident
220
+ )
221
+ else :
222
+ result [0 ] = result [0 ].strVal.ident
208
223
209
224
proc db_begin_deferred() {.importdb: " BEGIN DEFERRED" .}
210
225
proc db_begin_immediate() {.importdb: " BEGIN IMMEDIATE" .}
0 commit comments