UNPKG

@sqb/sqljs

Version:

SQB serialization extension for sql.js driver

29 lines (28 loc) 661 B
export class SqljsCursor { constructor(stmt, opts) { this._rowType = opts.rowType; this._stmt = stmt; } get isClosed() { return !this._stmt; } get rowType() { return this._rowType; } async close() { if (!this._stmt) return; this._stmt.free(); this._stmt = undefined; } async fetch(nRows) { if (!this._stmt) return; const stmt = this._stmt; const rows = []; while (nRows-- && stmt.step()) { rows.push(this.rowType === 'object' ? stmt.getAsObject() : stmt.get()); } return rows; } }