(table: string, columns: Column[], limit: number, offset: number, whereClause?: Record<string, any>)
| 288 | } |
| 289 | |
| 290 | async getRows(table: string, columns: Column[], limit: number, offset: number, whereClause?: Record<string, any>): Promise<QueryResponse | undefined> { |
| 291 | try { |
| 292 | const db = this.getConnection(); |
| 293 | if (!db) { |
| 294 | return Promise.reject('Cannot connect to database') |
| 295 | } |
| 296 | |
| 297 | const columnNames = columns.map(col => this.escapeIdentifier(col.name)).join(', '); |
| 298 | let query = `SELECT ${columnNames} FROM ${this.escapeIdentifier(table)}`; |
| 299 | const params: any[] = []; |
| 300 | |
| 301 | if (whereClause && Object.keys(whereClause).length > 0) { |
| 302 | const { whereString, whereParams } = this.buildWhereClause(whereClause, columns); |
| 303 | query += whereString.trim() ? ` WHERE ${whereString}` : ''; |
| 304 | params.push(...whereParams); |
| 305 | } |
| 306 | |
| 307 | query += ` LIMIT ? OFFSET ?`; |
| 308 | params.push(limit, offset); |
| 309 | |
| 310 | return new Promise<QueryResponse | undefined>((resolve, reject) => { |
| 311 | db.all(query, params, (err, rows: any[]) => { |
| 312 | if (err) { |
| 313 | reportError(`SQLite get rows error: ${err}`); |
| 314 | reject(err); |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | resolve({ rows, sql: query }); |
| 319 | }); |
| 320 | }); |
| 321 | } catch (err) { |
| 322 | reportError(`SQLite get rows error: ${err}`); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | async getVersion(): Promise<string> { |
| 327 | try { |
nothing calls this directly
no test coverage detected