UNPKG

node-firebird-driver

Version:
71 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractResultSet = void 0; /** AbstractResultSet implementation. */ class AbstractResultSet { constructor(statement, transaction) { this.statement = statement; this.transaction = transaction; this.finished = false; this.diposeStatementOnClose = false; } /** Closes this result set. */ async close() { this.check(); if (this.diposeStatementOnClose) { this.diposeStatementOnClose = false; await this.statement.dispose(); return; } await this.internalClose(); this.statement.resultSet = undefined; this.statement = undefined; } /** * Fetchs data from this result set as [col1, col2, ..., colN][]. * * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call. * * If result set has no more rows, returns an empty array. */ async fetch(options) { this.check(); if (this.finished) return []; const fetchRet = await this.internalFetch(options || this.defaultFetchOptions || this.statement.defaultFetchOptions || this.statement.attachment.defaultFetchOptions || this.statement.attachment.client.defaultFetchOptions); if (fetchRet.finished) this.finished = true; return fetchRet.rows; } /** * Fetchs data from this result set as T[]. * Where <T> represents your object interface. * * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call. * * If result set has no more rows, returns an empty array. */ async fetchAsObject(options) { const array = await this.fetch(options); const cols = (await this.statement?.columnLabels) || []; return array.map(row => { const obj = {}; // Loop on row column value. row.forEach((v, idx) => { const col = cols[idx]; obj[col] = v; }); return obj; }); } get isValid() { return !!this.statement; } check() { if (!this.isValid) throw new Error('ResultSet is already closed.'); } } exports.AbstractResultSet = AbstractResultSet; //# sourceMappingURL=resultset.js.map