@saltcorn/history-control 0.5.4 → 0.5.5
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/common.js +20 -6
- package/package.json +1 -1
- package/table-provider.js +6 -1
package/common.js
CHANGED
|
@@ -40,17 +40,31 @@ const get_where_vals = (table_name, whereFull) => {
|
|
|
40
40
|
const runQuery = async (table, whereFull, opts) => {
|
|
41
41
|
const schemaPrefix = db.getTenantSchemaPrefix();
|
|
42
42
|
const { where, values } = get_where_vals(table.name, whereFull);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
let joinTs = [],
|
|
44
|
+
joinF = [];
|
|
45
|
+
// console.log(table.fields);
|
|
46
|
+
|
|
47
|
+
Object.entries(opts?.joinFields || {}).forEach(([nm, { ref, target }]) => {
|
|
48
|
+
const keyField = table.getField(ref);
|
|
49
|
+
const reftable_name = `${schemaPrefix}"${
|
|
50
|
+
ref === "_userid" ? "users" : db.sqlsanitize(keyField.reftable_name)
|
|
51
|
+
}"`;
|
|
52
|
+
joinF.push(`${reftable_name}."${target}" as "${nm}"`);
|
|
53
|
+
joinTs.push(`${reftable_name} on h."${ref}" = ${reftable_name}."id"`);
|
|
54
|
+
});
|
|
55
|
+
const sql = `select
|
|
56
|
+
_version || '_'|| h.id as _version_id,
|
|
45
57
|
_version = (select max(ih._version) from ${schemaPrefix}"${db.sqlsanitize(
|
|
46
58
|
table.name
|
|
47
59
|
)}__history" ih where ih.id = h.id) as _is_latest,
|
|
48
60
|
not exists(select id from ${schemaPrefix}"${db.sqlsanitize(
|
|
49
61
|
table.name
|
|
50
|
-
)}" t where t.id = h.id) as _deleted,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
)}" t where t.id = h.id) as _deleted,
|
|
63
|
+
*${
|
|
64
|
+
joinF.length ? `, ${joinF.join()}` : ``
|
|
65
|
+
} from ${schemaPrefix}"${db.sqlsanitize(table.name)}__history" h ${
|
|
66
|
+
joinTs.length ? ` JOIN ${joinTs.join(" JOIN ")}` : ``
|
|
67
|
+
} ${where.length ? ` ${where}` : ""}${
|
|
54
68
|
opts.orderBy && opts.orderBy !== "_version_id"
|
|
55
69
|
? ` order by "${db.sqlsanitize(opts.orderBy)}"${
|
|
56
70
|
opts.orderDesc ? " DESC" : ""
|
package/package.json
CHANGED
package/table-provider.js
CHANGED
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
{ name: "_is_latest", label: "Is latest", type: "Bool" },
|
|
67
67
|
{ name: "_deleted", label: "Deleted", type: "Bool" },
|
|
68
68
|
{ name: "_time", label: "Time", type: "Date" },
|
|
69
|
-
{ name: "_userid", label: "User ID", type: "
|
|
69
|
+
{ name: "_userid", label: "User ID", type: "Key to users" },
|
|
70
70
|
{
|
|
71
71
|
name: "_restore_of_version",
|
|
72
72
|
label: "Restore of version",
|
|
@@ -98,6 +98,11 @@ module.exports = {
|
|
|
98
98
|
const qres = await runQuery(table, where, opts);
|
|
99
99
|
return qres.rows;
|
|
100
100
|
},
|
|
101
|
+
getJoinedRows: async (opts) => {
|
|
102
|
+
const table = Table.findOne({ name: cfg.table });
|
|
103
|
+
const qres = await runQuery(table, opts?.where || {}, opts);
|
|
104
|
+
return qres.rows;
|
|
105
|
+
},
|
|
101
106
|
};
|
|
102
107
|
},
|
|
103
108
|
},
|