goby-database 2.2.24 → 2.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -76,7 +76,10 @@ export default class Project {
76
76
  property_id: number;
77
77
  value: any;
78
78
  }[]): void;
79
- action_make_relations(relations: [input_1: ItemRelationSide, input_2: ItemRelationSide][]): void;
79
+ action_edit_relations(relations: {
80
+ change: 'add' | 'remove';
81
+ sides: [input_1: ItemRelationSide, input_2: ItemRelationSide];
82
+ }[]): void;
80
83
  retrieve_class_items({ class_id, class_name, class_data, pagination }: {
81
84
  class_id: number;
82
85
  class_name?: string;
package/dist/index.js CHANGED
@@ -772,24 +772,33 @@ export default class Project {
772
772
  };
773
773
  }
774
774
  }
775
- action_make_relations(relations) {
775
+ action_edit_relations(relations) {
776
776
  // NOTE: changes to make to this in the future:
777
777
  // - for input readability, allow class_name and prop_name as input options, assuming they’re enforced as unique, and use them to look up IDs
778
778
  // - enforce max_values here
779
779
  var _a;
780
- for (let [input_1, input_2] of relations) {
781
- let column_names = {
780
+ for (let { change, sides } of relations) {
781
+ const [input_1, input_2] = sides;
782
+ const column_names = {
782
783
  input_1: junction_col_name(input_1.class_id, input_1.prop_id),
783
784
  input_2: junction_col_name(input_2.class_id, input_2.prop_id)
784
785
  };
785
- let junction_id = (_a = this.junction_cache.find(j => full_relation_match(j.sides, [input_1, input_2]))) === null || _a === void 0 ? void 0 : _a.id;
786
- const date_added = Date.now();
786
+ const junction_id = (_a = this.junction_cache.find(j => full_relation_match(j.sides, [input_1, input_2]))) === null || _a === void 0 ? void 0 : _a.id;
787
787
  if (junction_id) {
788
- this.db.prepare(`
789
- INSERT INTO junction_${junction_id}
790
- ("${column_names.input_1}", "${column_names.input_2}",date_added)
791
- VALUES (${input_1.item_id},${input_2.item_id},${date_added})
792
- `).run();
788
+ if (change == 'add') {
789
+ const date_added = Date.now();
790
+ this.db.prepare(`
791
+ INSERT INTO junction_${junction_id}
792
+ ("${column_names.input_1}", "${column_names.input_2}",date_added)
793
+ VALUES (${input_1.item_id},${input_2.item_id},${date_added})
794
+ `).run();
795
+ }
796
+ else if (change == 'remove') {
797
+ this.db.prepare(`
798
+ DELETE FROM junction_${junction_id}
799
+ WHERE "${column_names.input_1}" = ${input_1.item_id}
800
+ AND "${column_names.input_2}" = ${input_2.item_id}`).run();
801
+ }
793
802
  }
794
803
  else {
795
804
  throw Error('Something went wrong - junction table for relationship not found');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goby-database",
3
- "version": "2.2.24",
3
+ "version": "2.2.25",
4
4
  "description": "This will hold the core better-sqlite3-powered application for creating and modifying goby databases",
5
5
  "main": "dist/index.js",
6
6
  "files": [