goby-database 2.2.30 → 2.2.32
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 +5 -1
- package/dist/index.js +82 -24
- package/package.json +7 -1
package/dist/index.d.ts
CHANGED
|
@@ -97,7 +97,11 @@ export default class Project {
|
|
|
97
97
|
*/
|
|
98
98
|
action_edit_relations(relations: {
|
|
99
99
|
change: 'add' | 'remove';
|
|
100
|
-
sides: [input_1: ItemRelationSide
|
|
100
|
+
sides: [input_1: ItemRelationSide & {
|
|
101
|
+
order?: number;
|
|
102
|
+
}, input_2: ItemRelationSide & {
|
|
103
|
+
order?: number;
|
|
104
|
+
}];
|
|
101
105
|
}[]): void;
|
|
102
106
|
retrieve_class_items({ class_id, class_name, class_data, pagination }: {
|
|
103
107
|
class_id: number;
|
package/dist/index.js
CHANGED
|
@@ -599,12 +599,20 @@ export default class Project {
|
|
|
599
599
|
let id = (_a = this.db.prepare('SELECT id FROM system_junctionlist ORDER BY id DESC').get()) === null || _a === void 0 ? void 0 : _a.id;
|
|
600
600
|
if (typeof id !== 'number')
|
|
601
601
|
throw new Error('Something went wrong creating a new relationship');
|
|
602
|
+
const side_0_col = junction_col_name(sides[0].class_id, sides[0].prop_id);
|
|
603
|
+
const side_1_col = junction_col_name(sides[1].class_id, sides[1].prop_id);
|
|
604
|
+
const columns = [
|
|
605
|
+
`"${side_0_col}" INTEGER`,
|
|
606
|
+
`"${side_1_col}" INTEGER`,
|
|
607
|
+
];
|
|
608
|
+
// for each side, check if it has a prop
|
|
609
|
+
// if it does, add column for its order
|
|
610
|
+
if (defined(sides[0].prop_id))
|
|
611
|
+
columns.push(`"${side_0_col}_order" REAL`);
|
|
612
|
+
if (defined(sides[1].prop_id))
|
|
613
|
+
columns.push(`"${side_1_col}_order" REAL`);
|
|
602
614
|
// creates table
|
|
603
|
-
this.create_table('junction', id,
|
|
604
|
-
`"${junction_col_name(sides[0].class_id, sides[0].prop_id)}" INTEGER`,
|
|
605
|
-
`"${junction_col_name(sides[1].class_id, sides[1].prop_id)}" INTEGER`,
|
|
606
|
-
`date_added INTEGER`
|
|
607
|
-
]);
|
|
615
|
+
this.create_table('junction', id, columns);
|
|
608
616
|
return id;
|
|
609
617
|
}
|
|
610
618
|
transfer_connections(source, target) {
|
|
@@ -780,25 +788,70 @@ export default class Project {
|
|
|
780
788
|
input_2: junction_col_name(input_2.class_id, input_2.prop_id)
|
|
781
789
|
};
|
|
782
790
|
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;
|
|
783
|
-
if (junction_id) {
|
|
784
|
-
if (change == 'add') {
|
|
785
|
-
const date_added = Date.now();
|
|
786
|
-
this.db.prepare(`
|
|
787
|
-
INSERT INTO junction_${junction_id}
|
|
788
|
-
("${column_names.input_1}", "${column_names.input_2}",date_added)
|
|
789
|
-
VALUES (${input_1.item_id},${input_2.item_id},${date_added})
|
|
790
|
-
`).run();
|
|
791
|
-
}
|
|
792
|
-
else if (change == 'remove') {
|
|
793
|
-
this.db.prepare(`
|
|
794
|
-
DELETE FROM junction_${junction_id}
|
|
795
|
-
WHERE "${column_names.input_1}" = ${input_1.item_id}
|
|
796
|
-
AND "${column_names.input_2}" = ${input_2.item_id}`).run();
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
else {
|
|
791
|
+
if (!defined(junction_id)) {
|
|
800
792
|
throw Error('Something went wrong - junction table for relationship not found');
|
|
801
793
|
}
|
|
794
|
+
if (change == 'add') {
|
|
795
|
+
const column_value_set = [
|
|
796
|
+
{
|
|
797
|
+
column: `"${column_names.input_1}"`,
|
|
798
|
+
value: input_1.item_id
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
column: `"${column_names.input_2}"`,
|
|
802
|
+
value: input_2.item_id
|
|
803
|
+
}
|
|
804
|
+
];
|
|
805
|
+
sides.forEach((side, s) => {
|
|
806
|
+
var _a, _b, _c;
|
|
807
|
+
// for each side, check if it has a prop id
|
|
808
|
+
if (defined(side.prop_id)) {
|
|
809
|
+
// if it does, prepare to add a column entry for it
|
|
810
|
+
const column = `"${s == 0 ? column_names.input_1 : column_names.input_2}_order"`;
|
|
811
|
+
let value = 0;
|
|
812
|
+
// check if it has an order set
|
|
813
|
+
if (defined(side.order)) {
|
|
814
|
+
// if so, use that for the column entry
|
|
815
|
+
value = side.order;
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
// if not, you have to do a lookup of that property value for that item, and get the last order value
|
|
819
|
+
const class_data = this.lookup_class(side.class_id);
|
|
820
|
+
const item = (_a = this.retrieve_class_items({
|
|
821
|
+
class_id: side.class_id,
|
|
822
|
+
class_data,
|
|
823
|
+
pagination: {
|
|
824
|
+
item_range: [side.item_id],
|
|
825
|
+
property_range: [side.prop_id]
|
|
826
|
+
}
|
|
827
|
+
}).loaded) === null || _a === void 0 ? void 0 : _a[0];
|
|
828
|
+
const prop_name = (_b = class_data.properties.find((p) => p.id == side.prop_id)) === null || _b === void 0 ? void 0 : _b.name;
|
|
829
|
+
const prop_selections = defined(prop_name) && item ? item[`user_${prop_name}`] : [];
|
|
830
|
+
if (Array.isArray(prop_selections)) {
|
|
831
|
+
const last_item_order = (_c = prop_selections === null || prop_selections === void 0 ? void 0 : prop_selections.at(-1)) === null || _c === void 0 ? void 0 : _c.system_order;
|
|
832
|
+
if (typeof last_item_order == 'number') {
|
|
833
|
+
value = last_item_order + 1000;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
column_value_set.push({
|
|
838
|
+
column,
|
|
839
|
+
value
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
this.db.prepare(`
|
|
844
|
+
INSERT INTO junction_${junction_id}
|
|
845
|
+
(${column_value_set.map((a) => a.column).join(',')})
|
|
846
|
+
VALUES (${column_value_set.map((a) => a.value).join(',')})
|
|
847
|
+
`).run();
|
|
848
|
+
}
|
|
849
|
+
else if (change == 'remove') {
|
|
850
|
+
this.db.prepare(`
|
|
851
|
+
DELETE FROM junction_${junction_id}
|
|
852
|
+
WHERE "${column_names.input_1}" = ${input_1.item_id}
|
|
853
|
+
AND "${column_names.input_2}" = ${input_2.item_id}`).run();
|
|
854
|
+
}
|
|
802
855
|
}
|
|
803
856
|
// NOTE: should this trigger a refresh to items?
|
|
804
857
|
}
|
|
@@ -890,7 +943,12 @@ export default class Project {
|
|
|
890
943
|
let target_select = `
|
|
891
944
|
SELECT
|
|
892
945
|
"${property_junction_column_name}",
|
|
893
|
-
json_object(
|
|
946
|
+
json_object(
|
|
947
|
+
'class_id',${target.class_id},
|
|
948
|
+
'system_id',junction."${target_junction_column_name}",
|
|
949
|
+
'system_order',junction."${property_junction_column_name}_order"
|
|
950
|
+
${label_sql_string}
|
|
951
|
+
) AS target_data, junction."${property_junction_column_name}_order" AS relation_order
|
|
894
952
|
FROM junction_${junction_id} AS junction
|
|
895
953
|
LEFT JOIN "class_${target_class === null || target_class === void 0 ? void 0 : target_class.name}" AS target_class ON junction."${target_junction_column_name}" = target_class.system_id
|
|
896
954
|
`;
|
|
@@ -908,7 +966,7 @@ export default class Project {
|
|
|
908
966
|
${target_selects.join(`
|
|
909
967
|
UNION
|
|
910
968
|
`)}
|
|
911
|
-
ORDER BY
|
|
969
|
+
ORDER BY relation_order
|
|
912
970
|
)
|
|
913
971
|
GROUP BY "${property_junction_column_name}"
|
|
914
972
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "goby-database",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.32",
|
|
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
|
+
"repository":{
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/goby-garden/goby-database.git"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
6
12
|
"files": [
|
|
7
13
|
"/dist",
|
|
8
14
|
"!dist/index.js.map",
|