| 47 | } |
| 48 | |
| 49 | async executeQuery<R>(compiledQuery: any): Promise<QueryResult<R>> { |
| 50 | const { sql, parameters } = compiledQuery; |
| 51 | const stmt = this.#db.prepare(sql); |
| 52 | |
| 53 | if (stmt.reader) { |
| 54 | return { |
| 55 | rows: stmt.all(parameters) as R[], |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | const query = sql.trim().toLowerCase(); |
| 60 | |
| 61 | /* v8 ignore next */ |
| 62 | if ( |
| 63 | query.startsWith('select') || |
| 64 | ((query.startsWith('insert into') || query.startsWith('update ')) && query.includes(' returning ')) |
| 65 | ) { |
| 66 | return { |
| 67 | rows: stmt.all(parameters) as R[], |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | const { changes, lastInsertRowid } = stmt.run(parameters); |
| 72 | return { |
| 73 | numAffectedRows: changes as any, |
| 74 | insertId: lastInsertRowid as any, |
| 75 | rows: [], |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | async *streamQuery<R>(compiledQuery: any): AsyncIterableIterator<QueryResult<R>> { |
| 80 | const { sql, parameters } = compiledQuery; |