UNPKG

@flexvertex/flexvertex-driver

Version:

The official FlexVertex Node.js driver

75 lines (60 loc) 1.91 kB
import { JSONParse, JSONStringify } from 'json-with-bigint'; import { FlexCommons } from '../commons/FlexCommons.js'; import { FlexObject } from '../objects/FlexObject.js'; import { FlexResult } from '../schema/FlexResult.js'; /** * Holds the returned status of a SQL query. * @hideconstructor */ export class FlexResultSet extends FlexResult { #count = 0; #limit = -1; #objectArray = new Array(); constructor(schema, responseData) { super(schema, responseData); if(!(responseData === undefined)) { if(!(responseData.Count === undefined)) this.#count = responseData.Count; if(!(responseData.Limit === undefined)) this.#limit = responseData.Limit; if(!(responseData.Objects === undefined)) { for(const o of responseData.Objects) { if(FlexCommons.isDefined(o.ObjectKey)) { this.#objectArray.push(o); } else { if(o.Metadata === undefined) throw "FlexResultSet() Metadata is undefined!"; if(o.Metadata.Class === undefined) throw "FlexResultSet() Metadata.Class is undefined!"; // console.log("-- o = " + JSONStringify(o)); let obj = new FlexObject(schema, o.Metadata.Class); // obj.className = o.class; obj.objectKey = o.Metadata.ObjectKey; obj.attributes = o.Attributes; obj.properties = o.Properties; this.#objectArray.push(obj); } } } } } /** * @property {number} count - The number of FlexObjects returned from the query */ get count() { return this.#count; } /** * @property {number} limit - The limit applied to the query */ get limit() { return this.#limit; } // get count() { return this.#objectArray.length; } /** * @property {FlexObject[]} objects - An array of FlexObjects returned from the query */ get objects() { return this.#objectArray; } }