UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

51 lines (50 loc) 1.24 kB
export class FieldInfoMap { _obj; _arr; constructor() { Object.defineProperty(this, '_obj', { enumerable: false, configurable: false, writable: true, value: {}, }); Object.defineProperty(this, '_arr', { enumerable: false, configurable: false, writable: true, value: [], }); } add(field) { const idx = field.index != null ? field.index : this._arr.length; this._arr[idx] = field; field.index = idx; const _obj = this._arr.reduce((a, f) => { a[f.name.toUpperCase()] = f; return a; }, {}); Object.defineProperty(this, '_obj', { enumerable: false, configurable: false, writable: true, value: _obj, }); } get(k) { if (typeof k === 'number') return this._arr[k]; return this._obj[k.toUpperCase()]; } entries() { return Object.entries(this._obj); } keys() { return Object.keys(this._obj); } values() { return [...this._arr]; } toJSON() { return { ...this._obj }; } }