@@ -39,32 +39,36 @@ async function queryData(
3939 sql : string ,
4040 parameters ?: readonly any [ ] ,
4141) : Promise < QueryResult < any > > {
42- const stmt = ( await core
42+ const iterator = core
4343 . sqlite
4444 . statements ( core . pointer , sql ) [ Symbol . asyncIterator ] ( )
45- . next ( ) ) . value
45+ const { value : stmt } = await iterator . next ( )
4646
47- if ( parameters ?. length ) {
48- core . sqlite . bind_collection ( stmt , parameters )
49- }
47+ try {
48+ if ( parameters ?. length ) {
49+ core . sqlite . bind_collection ( stmt , parameters )
50+ }
5051
51- const size = core . sqlite . column_count ( stmt )
52- if ( size === 0 ) {
53- await core . sqlite . step ( stmt )
54- return {
55- rows : [ ] ,
56- insertId : parseBigInt ( lastInsertRowIdCore ( core ) ) ,
57- numAffectedRows : parseBigInt ( changesCore ( core ) ) ,
52+ const size = core . sqlite . column_count ( stmt )
53+ if ( size === 0 ) {
54+ await core . sqlite . step ( stmt )
55+ return {
56+ rows : [ ] ,
57+ insertId : parseBigInt ( lastInsertRowIdCore ( core ) ) ,
58+ numAffectedRows : parseBigInt ( changesCore ( core ) ) ,
59+ }
5860 }
59- }
6061
61- const mapRow = createRowMapper ( core . sqlite , stmt )
62- const result = [ ]
63- let idx = 0
64- while ( await core . sqlite . step ( stmt ) === SQLITE_ROW ) {
65- result [ idx ++ ] = mapRow ( core . sqlite . row ( stmt ) )
62+ const mapRow = createRowMapper ( core . sqlite , stmt )
63+ const result = [ ]
64+ let idx = 0
65+ while ( await core . sqlite . step ( stmt ) === SQLITE_ROW ) {
66+ result [ idx ++ ] = mapRow ( core . sqlite . row ( stmt ) )
67+ }
68+ return { rows : result }
69+ } finally {
70+ await iterator . return ?.( )
6671 }
67- return { rows : result }
6872}
6973
7074async function * iterateDate (
0 commit comments