@budibase/backend-core 2.32.4 → 2.32.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/dist/index.js +36 -10
- package/dist/index.js.map +2 -2
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/src/sql/sql.js +38 -6
- package/dist/src/sql/sql.js.map +1 -1
- package/package.json +4 -4
- package/src/sql/sql.ts +45 -10
package/dist/index.js
CHANGED
|
@@ -68058,7 +68058,6 @@ var sqlTable_default = SqlTableQueryBuilder;
|
|
|
68058
68058
|
|
|
68059
68059
|
// src/sql/sql.ts
|
|
68060
68060
|
var import_lodash3 = require("lodash");
|
|
68061
|
-
var MAX_SQS_RELATIONSHIP_FIELDS = 63;
|
|
68062
68061
|
function getBaseLimit() {
|
|
68063
68062
|
const envLimit = environment_default.SQL_MAX_ROWS ? parseInt(environment_default.SQL_MAX_ROWS) : null;
|
|
68064
68063
|
return envLimit || 5e3;
|
|
@@ -68067,6 +68066,19 @@ function getRelationshipLimit() {
|
|
|
68067
68066
|
const envLimit = environment_default.SQL_MAX_RELATED_ROWS ? parseInt(environment_default.SQL_MAX_RELATED_ROWS) : null;
|
|
68068
68067
|
return envLimit || 500;
|
|
68069
68068
|
}
|
|
68069
|
+
function prioritisedArraySort(toSort, priorities) {
|
|
68070
|
+
return toSort.sort((a, b) => {
|
|
68071
|
+
const aPriority = priorities.find((field) => field && a.endsWith(field));
|
|
68072
|
+
const bPriority = priorities.find((field) => field && b.endsWith(field));
|
|
68073
|
+
if (aPriority && !bPriority) {
|
|
68074
|
+
return -1;
|
|
68075
|
+
}
|
|
68076
|
+
if (!aPriority && bPriority) {
|
|
68077
|
+
return 1;
|
|
68078
|
+
}
|
|
68079
|
+
return a.localeCompare(b);
|
|
68080
|
+
});
|
|
68081
|
+
}
|
|
68070
68082
|
function getTableName(table) {
|
|
68071
68083
|
if (table?.sourceType === "internal" /* INTERNAL */ || table?.sourceId === INTERNAL_TABLE_SOURCE_ID) {
|
|
68072
68084
|
return table?._id;
|
|
@@ -68707,10 +68719,20 @@ var InternalBuilder = class {
|
|
|
68707
68719
|
const separator = this.client === "oracledb" /* ORACLE */ ? " VALUE " : ",";
|
|
68708
68720
|
return `'${unaliased}'${separator}${tableField}`;
|
|
68709
68721
|
}
|
|
68722
|
+
maxFunctionParameters() {
|
|
68723
|
+
switch (this.client) {
|
|
68724
|
+
case "sqlite3" /* SQL_LITE */:
|
|
68725
|
+
return 127;
|
|
68726
|
+
case "pg" /* POSTGRES */:
|
|
68727
|
+
return 100;
|
|
68728
|
+
default:
|
|
68729
|
+
return 200;
|
|
68730
|
+
}
|
|
68731
|
+
}
|
|
68710
68732
|
addJsonRelationships(query, fromTable, relationships) {
|
|
68711
68733
|
const sqlClient = this.client;
|
|
68712
68734
|
const knex3 = this.knex;
|
|
68713
|
-
const { resource, tableAliases: aliases, endpoint } = this.query;
|
|
68735
|
+
const { resource, tableAliases: aliases, endpoint, meta } = this.query;
|
|
68714
68736
|
const fields = resource?.fields || [];
|
|
68715
68737
|
for (let relationship of relationships) {
|
|
68716
68738
|
const {
|
|
@@ -68724,20 +68746,24 @@ var InternalBuilder = class {
|
|
|
68724
68746
|
if (!toTable || !fromTable) {
|
|
68725
68747
|
continue;
|
|
68726
68748
|
}
|
|
68749
|
+
const relatedTable = meta.tables?.[toTable];
|
|
68727
68750
|
const toAlias = aliases?.[toTable] || toTable, fromAlias = aliases?.[fromTable] || fromTable;
|
|
68728
68751
|
let toTableWithSchema = this.tableNameWithSchema(toTable, {
|
|
68729
68752
|
alias: toAlias,
|
|
68730
68753
|
schema: endpoint.schema
|
|
68731
68754
|
});
|
|
68732
|
-
|
|
68733
|
-
|
|
68755
|
+
const requiredFields = [
|
|
68756
|
+
...relatedTable?.primary || [],
|
|
68757
|
+
relatedTable?.primaryDisplay
|
|
68758
|
+
].filter((field) => field);
|
|
68759
|
+
let relationshipFields = prioritisedArraySort(
|
|
68760
|
+
fields.filter((field) => field.split(".")[0] === toAlias),
|
|
68761
|
+
requiredFields
|
|
68762
|
+
);
|
|
68763
|
+
relationshipFields = relationshipFields.slice(
|
|
68764
|
+
0,
|
|
68765
|
+
Math.floor(this.maxFunctionParameters() / 2)
|
|
68734
68766
|
);
|
|
68735
|
-
if (this.client === "sqlite3" /* SQL_LITE */) {
|
|
68736
|
-
relationshipFields = relationshipFields.slice(
|
|
68737
|
-
0,
|
|
68738
|
-
MAX_SQS_RELATIONSHIP_FIELDS
|
|
68739
|
-
);
|
|
68740
|
-
}
|
|
68741
68767
|
const fieldList = relationshipFields.map((field) => this.buildJsonField(field)).join(",");
|
|
68742
68768
|
const primaryKey = `${toAlias}.${toPrimary || toKey}`;
|
|
68743
68769
|
let subQuery = knex3.from(toTableWithSchema).limit(getRelationshipLimit()).orderBy(primaryKey);
|