@@ -150,6 +150,47 @@ class Config {
150150 toString() {
151151 return JSONbig.stringify(this.data, null, 4);
152152 }
153+
154+ _getDBEntities(entityType) {
155+ if (!this.has(entityType)) {
156+ return [];
157+ }
158+ return this.get(entityType);
159+ }
160+
161+ _getDBEntity(entityType, $id) {
162+ if (!this.has(entityType)) {
163+ return {};
164+ }
165+
166+ let entities = this.get(entityType);
167+ for (let i = 0; i < entities.length; i++) {
168+ if (entities[i]['$id'] == $id) {
169+ return entities[i];
170+ }
171+ }
172+
173+ return {};
174+ }
175+
176+ _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
177+ props = whitelistKeys(props, keysSet, nestedKeys);
178+
179+ if (!this.has(entityType)) {
180+ this.set(entityType, []);
181+ }
182+
183+ let entities = this.get(entityType);
184+ for (let i = 0; i < entities.length; i++) {
185+ if (entities[i]['$id'] == props['$id']) {
186+ entities[i] = props;
187+ this.set(entityType, entities);
188+ return;
189+ }
190+ }
191+ entities.push(props);
192+ this.set(entityType, entities);
193+ }
153194}
154195
155196class Local extends Config {
@@ -464,45 +505,28 @@ class Local extends Config {
464505 this.set("topics", topics);
465506 }
466507
467- getDatabases() {
468- if (!this.has("databases")) {
469- return [];
470- }
471- return this.get("databases");
508+ getTablesDBs() {
509+ return this._getDBEntities("tablesDB");
472510 }
473511
474- getDatabase($id) {
475- if (!this.has("databases")) {
476- return {};
477- }
512+ getTablesDB($id) {
513+ return this._getDBEntity("tablesDB", $id);
514+ }
515+
516+ addTablesDB(props) {
517+ this._addDBEntity("tablesDB", props, KeysDatabase);
518+ }
478519
479- let databases = this.get("databases");
480- for (let i = 0; i < databases.length; i++) {
481- if (databases[i]['$id'] == $id) {
482- return databases[i];
483- }
484- }
520+ getDatabases() {
521+ return this._getDBEntities("databases");
522+ }
485523
486- return {};
524+ getDatabase($id) {
525+ return this._getDBEntity("databases", $id);
487526 }
488527
489528 addDatabase(props) {
490- props = whitelistKeys(props, KeysDatabase);
491-
492- if (!this.has("databases")) {
493- this.set("databases", []);
494- }
495-
496- let databases = this.get("databases");
497- for (let i = 0; i < databases.length; i++) {
498- if (databases[i]['$id'] == props['$id']) {
499- databases[i] = props;
500- this.set("databases", databases);
501- return;
502- }
503- }
504- databases.push(props);
505- this.set("databases", databases);
529+ this._addDBEntity("databases", props, KeysDatabase);
506530 }
507531
508532 getTeams() {
0 commit comments