@worker-tools/deno-kv-storage
Version:
An implementation of the StorageArea (1,2,3) interface for Deno with an extensible system for supporting various database backends.
66 lines • 1.82 kB
JavaScript
import { Empty } from "./rows.js";
export class RowObjects {
/**
* RowObjects
*
* RowObjects represent a set of results
* from a query in the form of an object.
* They are iterable and yield objects.
*
* This class is not exported from the module
* and the only correct way to obtain a `RowObjects`
* object is by making a database query
* and using the `asObject()` method on the `Rows` result.
*/
constructor(rows) {
Object.defineProperty(this, "_rows", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_columns", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._rows = rows;
if (rows !== Empty) {
this._columns = this._rows.columns();
}
}
/**
* RowObjects.return
*
* Implements the closing iterator
* protocol. See also:
* https://exploringjs.com/es6/ch_iteration.html#sec_closing-iterators
*/
return() {
this._rows.return();
return { done: true, value: null };
}
/**
* RowObjects.next
*
* Implements the iterator protocol.
*/
next() {
const { value, done } = this._rows.next();
if (done) {
return { value: null, done: true };
}
else {
const rowAsObject = {};
for (let i = 0; i < value.length; i++) {
rowAsObject[this._columns[i].name] = value[i];
}
return { value: rowAsObject, done: false };
}
}
[Symbol.iterator]() {
return this;
}
}
//# sourceMappingURL=row_objects.js.map