@ronin/compiler 0.4.0 → 0.5.0
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/README.md +23 -17
- package/dist/index.d.ts +9 -14228
- package/dist/index.js +93 -75
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -96,19 +96,19 @@ var splitQuery = (query) => {
|
|
96
96
|
};
|
97
97
|
|
98
98
|
// src/utils/statement.ts
|
99
|
-
var prepareStatementValue = (
|
99
|
+
var prepareStatementValue = (statementParams, value) => {
|
100
100
|
if (value === null) return "NULL";
|
101
|
-
if (!
|
101
|
+
if (!statementParams) return JSON.stringify(value);
|
102
102
|
let formattedValue = value;
|
103
103
|
if (Array.isArray(value) || isObject(value)) {
|
104
104
|
formattedValue = JSON.stringify(value);
|
105
105
|
} else if (typeof value === "boolean") {
|
106
106
|
formattedValue = value ? 1 : 0;
|
107
107
|
}
|
108
|
-
const index =
|
108
|
+
const index = statementParams.push(formattedValue);
|
109
109
|
return `?${index}`;
|
110
110
|
};
|
111
|
-
var composeFieldValues = (schemas, schema,
|
111
|
+
var composeFieldValues = (schemas, schema, statementParams, instructionName, value, options) => {
|
112
112
|
const { field: schemaField, fieldSelector: selector } = getFieldFromSchema(
|
113
113
|
schema,
|
114
114
|
options.fieldSlug,
|
@@ -123,8 +123,8 @@ var composeFieldValues = (schemas, schema, statementValues, instructionName, val
|
|
123
123
|
conditionValue = `(${compileQueryInput(
|
124
124
|
value[RONIN_SCHEMA_SYMBOLS.QUERY],
|
125
125
|
schemas,
|
126
|
-
|
127
|
-
).
|
126
|
+
statementParams
|
127
|
+
).main.statement})`;
|
128
128
|
} else if (typeof value === "string" && value.startsWith(RONIN_SCHEMA_SYMBOLS.FIELD)) {
|
129
129
|
let targetTable = `"${options.rootTable}"`;
|
130
130
|
let toReplace = RONIN_SCHEMA_SYMBOLS.FIELD;
|
@@ -140,21 +140,21 @@ var composeFieldValues = (schemas, schema, statementValues, instructionName, val
|
|
140
140
|
} else if (schemaField.type === "json" && instructionName === "to") {
|
141
141
|
conditionSelector = `"${schemaField.slug}"`;
|
142
142
|
if (collectStatementValue) {
|
143
|
-
const preparedValue = prepareStatementValue(
|
143
|
+
const preparedValue = prepareStatementValue(statementParams, value);
|
144
144
|
conditionValue = `IIF(${conditionSelector} IS NULL, ${preparedValue}, json_patch(${conditionSelector}, ${preparedValue}))`;
|
145
145
|
}
|
146
146
|
} else if (collectStatementValue) {
|
147
|
-
conditionValue = prepareStatementValue(
|
147
|
+
conditionValue = prepareStatementValue(statementParams, value);
|
148
148
|
}
|
149
149
|
if (options.type === "fields") return conditionSelector;
|
150
150
|
if (options.type === "values") return conditionValue;
|
151
151
|
return `${conditionSelector} ${WITH_CONDITIONS[options.condition || "being"](conditionValue, value)}`;
|
152
152
|
};
|
153
|
-
var composeConditions = (schemas, schema,
|
153
|
+
var composeConditions = (schemas, schema, statementParams, instructionName, value, options) => {
|
154
154
|
const isNested = isObject(value) && Object.keys(value).length > 0;
|
155
155
|
if (isNested && Object.keys(value).every((key) => key in WITH_CONDITIONS)) {
|
156
156
|
const conditions = Object.entries(value).map(
|
157
|
-
([conditionType, checkValue]) => composeConditions(schemas, schema,
|
157
|
+
([conditionType, checkValue]) => composeConditions(schemas, schema, statementParams, instructionName, checkValue, {
|
158
158
|
...options,
|
159
159
|
condition: conditionType
|
160
160
|
})
|
@@ -175,7 +175,7 @@ var composeConditions = (schemas, schema, statementValues, instructionName, valu
|
|
175
175
|
return composeFieldValues(
|
176
176
|
schemas,
|
177
177
|
schema,
|
178
|
-
|
178
|
+
statementParams,
|
179
179
|
instructionName,
|
180
180
|
value,
|
181
181
|
{ ...options, fieldSlug: options.fieldSlug }
|
@@ -204,7 +204,7 @@ var composeConditions = (schemas, schema, statementValues, instructionName, valu
|
|
204
204
|
return composeConditions(
|
205
205
|
schemas,
|
206
206
|
schema,
|
207
|
-
|
207
|
+
statementParams,
|
208
208
|
instructionName,
|
209
209
|
recordTarget,
|
210
210
|
options
|
@@ -214,7 +214,7 @@ var composeConditions = (schemas, schema, statementValues, instructionName, valu
|
|
214
214
|
if (isNested) {
|
215
215
|
const conditions = Object.entries(value).map(([field, value2]) => {
|
216
216
|
const nestedFieldSlug = options.fieldSlug ? `${options.fieldSlug}.${field}` : field;
|
217
|
-
return composeConditions(schemas, schema,
|
217
|
+
return composeConditions(schemas, schema, statementParams, instructionName, value2, {
|
218
218
|
...options,
|
219
219
|
fieldSlug: nestedFieldSlug
|
220
220
|
});
|
@@ -228,7 +228,7 @@ var composeConditions = (schemas, schema, statementValues, instructionName, valu
|
|
228
228
|
(filter) => composeConditions(
|
229
229
|
schemas,
|
230
230
|
schema,
|
231
|
-
|
231
|
+
statementParams,
|
232
232
|
instructionName,
|
233
233
|
filter,
|
234
234
|
options
|
@@ -287,11 +287,11 @@ var WITH_CONDITIONS = {
|
|
287
287
|
lessThan: (value) => `< ${value}`,
|
288
288
|
lessOrEqual: (value) => `<= ${value}`
|
289
289
|
};
|
290
|
-
var handleWith = (schemas, schema,
|
290
|
+
var handleWith = (schemas, schema, statementParams, instruction, rootTable) => {
|
291
291
|
const subStatement = composeConditions(
|
292
292
|
schemas,
|
293
293
|
schema,
|
294
|
-
|
294
|
+
statementParams,
|
295
295
|
"with",
|
296
296
|
instruction,
|
297
297
|
{ rootTable }
|
@@ -601,7 +601,7 @@ var getFieldStatement = (field) => {
|
|
601
601
|
}
|
602
602
|
return statement;
|
603
603
|
};
|
604
|
-
var addSchemaQueries = (schemas,
|
604
|
+
var addSchemaQueries = (schemas, queryDetails, dependencyStatements) => {
|
605
605
|
const {
|
606
606
|
queryType,
|
607
607
|
querySchema,
|
@@ -653,30 +653,33 @@ var addSchemaQueries = (schemas, statementValues, queryDetails, writeStatements)
|
|
653
653
|
fields: ["schema.slug"]
|
654
654
|
});
|
655
655
|
}
|
656
|
-
const
|
656
|
+
const usableSlug = kind === "schemas" ? slug : schemaSlug;
|
657
|
+
const tableName = convertToSnakeCase(pluralize(usableSlug));
|
658
|
+
const targetSchema = kind === "schemas" && queryType === "create" ? null : getSchemaBySlug(schemas, usableSlug);
|
657
659
|
if (kind === "indexes") {
|
658
660
|
const indexName = convertToSnakeCase(slug);
|
659
661
|
const unique = instructionList?.unique;
|
660
662
|
const filterQuery = instructionList?.filter;
|
663
|
+
const params = [];
|
661
664
|
let statement2 = `${tableAction}${unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
|
662
665
|
if (queryType === "create") {
|
663
666
|
statement2 += ` ON "${tableName}"`;
|
664
667
|
if (filterQuery) {
|
665
|
-
const targetSchema = getSchemaBySlug(schemas, schemaSlug);
|
666
668
|
const withStatement = handleWith(
|
667
669
|
schemas,
|
668
670
|
targetSchema,
|
669
|
-
|
671
|
+
params,
|
670
672
|
filterQuery
|
671
673
|
);
|
672
674
|
statement2 += ` WHERE (${withStatement})`;
|
673
675
|
}
|
674
676
|
}
|
675
|
-
|
677
|
+
dependencyStatements.push({ statement: statement2, params });
|
676
678
|
return queryInstructions;
|
677
679
|
}
|
678
680
|
if (kind === "triggers") {
|
679
681
|
const triggerName = convertToSnakeCase(slug);
|
682
|
+
const params = [];
|
680
683
|
let statement2 = `${tableAction} TRIGGER "${triggerName}"`;
|
681
684
|
if (queryType === "create") {
|
682
685
|
const cause = slugToName(instructionList?.cause).toUpperCase();
|
@@ -687,28 +690,27 @@ var addSchemaQueries = (schemas, statementValues, queryDetails, writeStatements)
|
|
687
690
|
statementParts.push("FOR EACH ROW");
|
688
691
|
}
|
689
692
|
if (filterQuery) {
|
690
|
-
const targetSchema = getSchemaBySlug(schemas, schemaSlug);
|
691
693
|
const tablePlaceholder = cause.endsWith("DELETE") ? RONIN_SCHEMA_SYMBOLS.FIELD_OLD : RONIN_SCHEMA_SYMBOLS.FIELD_NEW;
|
692
694
|
const withStatement = handleWith(
|
693
695
|
schemas,
|
694
696
|
targetSchema,
|
695
|
-
|
697
|
+
params,
|
696
698
|
filterQuery,
|
697
699
|
tablePlaceholder
|
698
700
|
);
|
699
701
|
statementParts.push("WHEN", `(${withStatement})`);
|
700
702
|
}
|
701
703
|
const effectStatements = effectQueries.map((effectQuery) => {
|
702
|
-
return compileQueryInput(effectQuery, schemas,
|
703
|
-
|
704
|
-
}).
|
704
|
+
return compileQueryInput(effectQuery, schemas, params, {
|
705
|
+
returning: false
|
706
|
+
}).main.statement;
|
705
707
|
});
|
706
708
|
if (effectStatements.length > 1) statementParts.push("BEGIN");
|
707
709
|
statementParts.push(effectStatements.join("; "));
|
708
710
|
if (effectStatements.length > 1) statementParts.push("END");
|
709
711
|
statement2 += ` ${statementParts.join(" ")}`;
|
710
712
|
}
|
711
|
-
|
713
|
+
dependencyStatements.push({ statement: statement2, params });
|
712
714
|
return queryInstructions;
|
713
715
|
}
|
714
716
|
let statement = `${tableAction} TABLE "${tableName}"`;
|
@@ -721,14 +723,18 @@ var addSchemaQueries = (schemas, statementValues, queryDetails, writeStatements)
|
|
721
723
|
if (queryType === "create") {
|
722
724
|
const columns = fields.map(getFieldStatement).filter(Boolean);
|
723
725
|
statement += ` (${columns.join(", ")})`;
|
726
|
+
schemas.push(queryInstructions.to);
|
724
727
|
} else if (queryType === "set") {
|
725
728
|
const newSlug = queryInstructions.to?.pluralSlug;
|
726
729
|
if (newSlug) {
|
727
730
|
const newTable = convertToSnakeCase(newSlug);
|
728
731
|
statement += ` RENAME TO "${newTable}"`;
|
729
732
|
}
|
733
|
+
Object.assign(targetSchema, queryInstructions.to);
|
734
|
+
} else if (queryType === "drop") {
|
735
|
+
schemas.splice(schemas.indexOf(targetSchema), 1);
|
730
736
|
}
|
731
|
-
|
737
|
+
dependencyStatements.push({ statement, params: [] });
|
732
738
|
return queryInstructions;
|
733
739
|
}
|
734
740
|
if (kind === "fields") {
|
@@ -749,7 +755,7 @@ var addSchemaQueries = (schemas, statementValues, queryDetails, writeStatements)
|
|
749
755
|
} else if (queryType === "drop") {
|
750
756
|
statement += ` DROP COLUMN "${slug}"`;
|
751
757
|
}
|
752
|
-
|
758
|
+
dependencyStatements.push({ statement, params: [] });
|
753
759
|
}
|
754
760
|
return queryInstructions;
|
755
761
|
};
|
@@ -773,7 +779,7 @@ var pluralize = (word) => {
|
|
773
779
|
// src/instructions/before-after.ts
|
774
780
|
var CURSOR_SEPARATOR = ",";
|
775
781
|
var CURSOR_NULL_PLACEHOLDER = "RONIN_NULL";
|
776
|
-
var handleBeforeOrAfter = (schema,
|
782
|
+
var handleBeforeOrAfter = (schema, statementParams, instructions, rootTable) => {
|
777
783
|
if (!(instructions.before || instructions.after)) {
|
778
784
|
throw new RoninError({
|
779
785
|
message: "The `before` or `after` instruction must not be empty.",
|
@@ -799,15 +805,15 @@ var handleBeforeOrAfter = (schema, statementValues, instructions, rootTable) =>
|
|
799
805
|
}
|
800
806
|
const { field } = getFieldFromSchema(schema, key, "orderedBy");
|
801
807
|
if (field.type === "boolean") {
|
802
|
-
return prepareStatementValue(
|
808
|
+
return prepareStatementValue(statementParams, value === "true");
|
803
809
|
}
|
804
810
|
if (field.type === "number") {
|
805
|
-
return prepareStatementValue(
|
811
|
+
return prepareStatementValue(statementParams, Number.parseInt(value));
|
806
812
|
}
|
807
813
|
if (field.type === "date") {
|
808
814
|
return `'${new Date(Number.parseInt(value)).toJSON()}'`;
|
809
815
|
}
|
810
|
-
return prepareStatementValue(
|
816
|
+
return prepareStatementValue(statementParams, value);
|
811
817
|
});
|
812
818
|
const compareOperators = [
|
813
819
|
// Reverse the comparison operators if we're querying for records before.
|
@@ -850,7 +856,7 @@ var handleBeforeOrAfter = (schema, statementValues, instructions, rootTable) =>
|
|
850
856
|
};
|
851
857
|
|
852
858
|
// src/instructions/for.ts
|
853
|
-
var handleFor = (schemas, schema,
|
859
|
+
var handleFor = (schemas, schema, statementParams, instruction, rootTable) => {
|
854
860
|
let statement = "";
|
855
861
|
if (!instruction) return statement;
|
856
862
|
for (const shortcut in instruction) {
|
@@ -871,7 +877,7 @@ var handleFor = (schemas, schema, statementValues, instruction, rootTable) => {
|
|
871
877
|
const subStatement = composeConditions(
|
872
878
|
schemas,
|
873
879
|
schema,
|
874
|
-
|
880
|
+
statementParams,
|
875
881
|
"for",
|
876
882
|
replacedForFilter,
|
877
883
|
{ rootTable }
|
@@ -882,7 +888,7 @@ var handleFor = (schemas, schema, statementValues, instruction, rootTable) => {
|
|
882
888
|
};
|
883
889
|
|
884
890
|
// src/instructions/including.ts
|
885
|
-
var handleIncluding = (schemas,
|
891
|
+
var handleIncluding = (schemas, statementParams, schema, instruction, rootTable) => {
|
886
892
|
let statement = "";
|
887
893
|
let rootTableSubQuery;
|
888
894
|
let rootTableName = rootTable;
|
@@ -916,9 +922,9 @@ var handleIncluding = (schemas, statementValues, schema, instruction, rootTable)
|
|
916
922
|
}
|
917
923
|
},
|
918
924
|
schemas,
|
919
|
-
|
925
|
+
statementParams
|
920
926
|
);
|
921
|
-
relatedTableSelector = `(${subSelect.
|
927
|
+
relatedTableSelector = `(${subSelect.main.statement})`;
|
922
928
|
}
|
923
929
|
statement += `${joinType} JOIN ${relatedTableSelector} as ${tableAlias}`;
|
924
930
|
if (joinType === "LEFT") {
|
@@ -929,7 +935,7 @@ var handleIncluding = (schemas, statementValues, schema, instruction, rootTable)
|
|
929
935
|
const subStatement = composeConditions(
|
930
936
|
schemas,
|
931
937
|
relatedSchema,
|
932
|
-
|
938
|
+
statementParams,
|
933
939
|
"including",
|
934
940
|
queryInstructions?.with,
|
935
941
|
{
|
@@ -983,7 +989,7 @@ var handleOrderedBy = (schema, instruction, rootTable) => {
|
|
983
989
|
};
|
984
990
|
|
985
991
|
// src/instructions/selecting.ts
|
986
|
-
var handleSelecting = (schema,
|
992
|
+
var handleSelecting = (schema, statementParams, instructions) => {
|
987
993
|
let statement = instructions.selecting ? instructions.selecting.map((slug) => {
|
988
994
|
return getFieldFromSchema(schema, slug, "selecting").fieldSelector;
|
989
995
|
}).join(", ") : "*";
|
@@ -994,14 +1000,14 @@ var handleSelecting = (schema, statementValues, instructions) => {
|
|
994
1000
|
).filter(([_, value]) => {
|
995
1001
|
return !(isObject(value) && Object.hasOwn(value, RONIN_SCHEMA_SYMBOLS.QUERY));
|
996
1002
|
}).map(([key, value]) => {
|
997
|
-
return `${prepareStatementValue(
|
1003
|
+
return `${prepareStatementValue(statementParams, value)} as "${key}"`;
|
998
1004
|
}).join(", ");
|
999
1005
|
}
|
1000
1006
|
return statement;
|
1001
1007
|
};
|
1002
1008
|
|
1003
1009
|
// src/instructions/to.ts
|
1004
|
-
var handleTo = (schemas, schema,
|
1010
|
+
var handleTo = (schemas, schema, statementParams, queryType, dependencyStatements, instructions, rootTable) => {
|
1005
1011
|
const currentTime = (/* @__PURE__ */ new Date()).toISOString();
|
1006
1012
|
const { with: withInstruction, to: toInstruction } = instructions;
|
1007
1013
|
const defaultFields = {};
|
@@ -1043,7 +1049,7 @@ var handleTo = (schemas, schema, statementValues, queryType, writeStatements, in
|
|
1043
1049
|
...subQueryInstructions.including
|
1044
1050
|
};
|
1045
1051
|
}
|
1046
|
-
return compileQueryInput(subQuery, schemas,
|
1052
|
+
return compileQueryInput(subQuery, schemas, statementParams).main.statement;
|
1047
1053
|
}
|
1048
1054
|
Object.assign(toInstruction, defaultFields);
|
1049
1055
|
for (const fieldSlug in toInstruction) {
|
@@ -1059,29 +1065,28 @@ var handleTo = (schemas, schema, statementValues, queryType, writeStatements, in
|
|
1059
1065
|
const source = queryType === "create" ? { id: toInstruction.id } : withInstruction;
|
1060
1066
|
const recordDetails = { source };
|
1061
1067
|
if (value) recordDetails.target = value;
|
1062
|
-
|
1068
|
+
return compileQueryInput(
|
1063
1069
|
{
|
1064
1070
|
[subQueryType]: {
|
1065
1071
|
[associativeSchemaSlug]: subQueryType === "create" ? { to: recordDetails } : { with: recordDetails }
|
1066
1072
|
}
|
1067
1073
|
},
|
1068
1074
|
schemas,
|
1069
|
-
|
1070
|
-
{
|
1071
|
-
);
|
1072
|
-
return readStatement;
|
1075
|
+
[],
|
1076
|
+
{ returning: false }
|
1077
|
+
).main;
|
1073
1078
|
};
|
1074
1079
|
if (Array.isArray(fieldValue)) {
|
1075
|
-
|
1080
|
+
dependencyStatements.push(composeStatement("drop"));
|
1076
1081
|
for (const record of fieldValue) {
|
1077
|
-
|
1082
|
+
dependencyStatements.push(composeStatement("create", record));
|
1078
1083
|
}
|
1079
1084
|
} else if (isObject(fieldValue)) {
|
1080
1085
|
for (const recordToAdd of fieldValue.containing || []) {
|
1081
|
-
|
1086
|
+
dependencyStatements.push(composeStatement("create", recordToAdd));
|
1082
1087
|
}
|
1083
1088
|
for (const recordToRemove of fieldValue.notContaining || []) {
|
1084
|
-
|
1089
|
+
dependencyStatements.push(composeStatement("drop", recordToRemove));
|
1085
1090
|
}
|
1086
1091
|
}
|
1087
1092
|
}
|
@@ -1089,7 +1094,7 @@ var handleTo = (schemas, schema, statementValues, queryType, writeStatements, in
|
|
1089
1094
|
let statement = composeConditions(
|
1090
1095
|
schemas,
|
1091
1096
|
schema,
|
1092
|
-
|
1097
|
+
statementParams,
|
1093
1098
|
"to",
|
1094
1099
|
toInstruction,
|
1095
1100
|
{
|
@@ -1101,7 +1106,7 @@ var handleTo = (schemas, schema, statementValues, queryType, writeStatements, in
|
|
1101
1106
|
const deepStatement = composeConditions(
|
1102
1107
|
schemas,
|
1103
1108
|
schema,
|
1104
|
-
|
1109
|
+
statementParams,
|
1105
1110
|
"to",
|
1106
1111
|
toInstruction,
|
1107
1112
|
{
|
@@ -1117,22 +1122,21 @@ var handleTo = (schemas, schema, statementValues, queryType, writeStatements, in
|
|
1117
1122
|
};
|
1118
1123
|
|
1119
1124
|
// src/utils/index.ts
|
1120
|
-
var compileQueryInput = (query,
|
1125
|
+
var compileQueryInput = (query, schemas, statementParams, options) => {
|
1121
1126
|
const parsedQuery = splitQuery(query);
|
1122
1127
|
const { queryType, querySchema, queryInstructions } = parsedQuery;
|
1123
|
-
const schemas = addSystemSchemas(defaultSchemas);
|
1124
1128
|
const schema = getSchemaBySlug(schemas, querySchema);
|
1125
1129
|
const single = querySchema !== schema.pluralSlug;
|
1126
1130
|
let instructions = formatIdentifiers(schema, queryInstructions);
|
1127
1131
|
let table = getTableForSchema(schema);
|
1128
|
-
const
|
1132
|
+
const dependencyStatements = [];
|
1133
|
+
const returning = options?.returning ?? true;
|
1129
1134
|
instructions = addSchemaQueries(
|
1130
1135
|
schemas,
|
1131
|
-
statementValues,
|
1132
1136
|
{ queryType, querySchema, queryInstructions: instructions },
|
1133
|
-
|
1137
|
+
dependencyStatements
|
1134
1138
|
);
|
1135
|
-
const columns = handleSelecting(schema,
|
1139
|
+
const columns = handleSelecting(schema, statementParams, {
|
1136
1140
|
selecting: instructions?.selecting,
|
1137
1141
|
including: instructions?.including
|
1138
1142
|
});
|
@@ -1161,7 +1165,7 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1161
1165
|
statement: including,
|
1162
1166
|
rootTableSubQuery,
|
1163
1167
|
rootTableName
|
1164
|
-
} = handleIncluding(schemas,
|
1168
|
+
} = handleIncluding(schemas, statementParams, schema, instructions?.including, table);
|
1165
1169
|
if (rootTableSubQuery && rootTableName) {
|
1166
1170
|
table = rootTableName;
|
1167
1171
|
statement += `(${rootTableSubQuery}) as ${rootTableName} `;
|
@@ -1184,9 +1188,9 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1184
1188
|
const toStatement = handleTo(
|
1185
1189
|
schemas,
|
1186
1190
|
schema,
|
1187
|
-
|
1191
|
+
statementParams,
|
1188
1192
|
queryType,
|
1189
|
-
|
1193
|
+
dependencyStatements,
|
1190
1194
|
{ with: instructions.with, to: instructions.to },
|
1191
1195
|
isJoining ? table : void 0
|
1192
1196
|
);
|
@@ -1197,7 +1201,7 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1197
1201
|
const withStatement = handleWith(
|
1198
1202
|
schemas,
|
1199
1203
|
schema,
|
1200
|
-
|
1204
|
+
statementParams,
|
1201
1205
|
instructions?.with,
|
1202
1206
|
isJoining ? table : void 0
|
1203
1207
|
);
|
@@ -1207,7 +1211,7 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1207
1211
|
const forStatement = handleFor(
|
1208
1212
|
schemas,
|
1209
1213
|
schema,
|
1210
|
-
|
1214
|
+
statementParams,
|
1211
1215
|
instructions?.for,
|
1212
1216
|
isJoining ? table : void 0
|
1213
1217
|
);
|
@@ -1235,7 +1239,7 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1235
1239
|
}
|
1236
1240
|
const beforeAndAfterStatement = handleBeforeOrAfter(
|
1237
1241
|
schema,
|
1238
|
-
|
1242
|
+
statementParams,
|
1239
1243
|
{
|
1240
1244
|
before: instructions.before,
|
1241
1245
|
after: instructions.after,
|
@@ -1264,22 +1268,36 @@ var compileQueryInput = (query, defaultSchemas, statementValues, options) => {
|
|
1264
1268
|
if (queryType === "get" && !isJoiningMultipleRows) {
|
1265
1269
|
statement += handleLimitedTo(single, instructions?.limitedTo);
|
1266
1270
|
}
|
1267
|
-
if (["create", "set", "drop"].includes(queryType) &&
|
1271
|
+
if (["create", "set", "drop"].includes(queryType) && returning) {
|
1268
1272
|
statement += "RETURNING * ";
|
1269
1273
|
}
|
1270
|
-
const
|
1274
|
+
const mainStatement = {
|
1275
|
+
statement: statement.trimEnd(),
|
1276
|
+
params: statementParams || []
|
1277
|
+
};
|
1278
|
+
if (returning) mainStatement.returning = true;
|
1271
1279
|
return {
|
1272
|
-
|
1273
|
-
|
1274
|
-
values: statementValues || []
|
1280
|
+
dependencies: dependencyStatements,
|
1281
|
+
main: mainStatement
|
1275
1282
|
};
|
1276
1283
|
};
|
1277
1284
|
|
1278
1285
|
// src/index.ts
|
1279
|
-
var
|
1280
|
-
const
|
1281
|
-
|
1286
|
+
var compileQueries = (queries, schemas, options) => {
|
1287
|
+
const schemaList = addSystemSchemas(schemas);
|
1288
|
+
const dependencyStatements = [];
|
1289
|
+
const mainStatements = [];
|
1290
|
+
for (const query of queries) {
|
1291
|
+
const result = compileQueryInput(
|
1292
|
+
query,
|
1293
|
+
schemaList,
|
1294
|
+
options?.inlineValues ? null : []
|
1295
|
+
);
|
1296
|
+
dependencyStatements.push(...result.dependencies);
|
1297
|
+
mainStatements.push(result.main);
|
1298
|
+
}
|
1299
|
+
return [...dependencyStatements, ...mainStatements];
|
1282
1300
|
};
|
1283
1301
|
export {
|
1284
|
-
|
1302
|
+
compileQueries
|
1285
1303
|
};
|