@ronin/compiler 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +30 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -684,7 +684,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
684
684
|
return [pluralType2, formatModelEntity(type, list)];
|
685
685
|
})
|
686
686
|
);
|
687
|
-
const columns = modelWithPresets.fields.map((
|
687
|
+
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
688
688
|
dependencyStatements.push({
|
689
689
|
statement: `${statement} (${columns.join(", ")})`,
|
690
690
|
params: []
|
@@ -730,10 +730,10 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
730
730
|
}
|
731
731
|
if (entity === "field" && model) {
|
732
732
|
if (action === "create") {
|
733
|
-
const
|
734
|
-
|
733
|
+
const field2 = jsonValue;
|
734
|
+
field2.type = field2.type || "string";
|
735
735
|
dependencyStatements.push({
|
736
|
-
statement: `${statement} ADD COLUMN ${getFieldStatement(models, model,
|
736
|
+
statement: `${statement} ADD COLUMN ${getFieldStatement(models, model, field2)}`,
|
737
737
|
params: []
|
738
738
|
});
|
739
739
|
} else if (action === "alter") {
|
@@ -757,15 +757,15 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
757
757
|
const params = [];
|
758
758
|
let statement2 = `${tableAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
|
759
759
|
if (action === "create") {
|
760
|
-
const columns = index.fields.map((
|
760
|
+
const columns = index.fields.map((field2) => {
|
761
761
|
let fieldSelector = "";
|
762
|
-
if ("slug" in
|
763
|
-
({ fieldSelector } = getFieldFromModel(model,
|
764
|
-
} else if ("expression" in
|
765
|
-
fieldSelector = parseFieldExpression(model, "to",
|
762
|
+
if ("slug" in field2) {
|
763
|
+
({ fieldSelector } = getFieldFromModel(model, field2.slug, "to"));
|
764
|
+
} else if ("expression" in field2) {
|
765
|
+
fieldSelector = parseFieldExpression(model, "to", field2.expression);
|
766
766
|
}
|
767
|
-
if (
|
768
|
-
if (
|
767
|
+
if (field2.collation) fieldSelector += ` COLLATE ${field2.collation}`;
|
768
|
+
if (field2.order) fieldSelector += ` ${field2.order}`;
|
769
769
|
return fieldSelector;
|
770
770
|
});
|
771
771
|
statement2 += ` ON "${tableName}" (${columns.join(", ")})`;
|
@@ -791,8 +791,8 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
791
791
|
fields: ["action"]
|
792
792
|
});
|
793
793
|
}
|
794
|
-
const fieldSelectors = trigger.fields.map((
|
795
|
-
return getFieldFromModel(model,
|
794
|
+
const fieldSelectors = trigger.fields.map((field2) => {
|
795
|
+
return getFieldFromModel(model, field2.slug, "to").fieldSelector;
|
796
796
|
});
|
797
797
|
statementParts.push(`OF (${fieldSelectors.join(", ")})`);
|
798
798
|
}
|
@@ -824,10 +824,23 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
824
824
|
dependencyStatements.push({ statement: statement2, params });
|
825
825
|
}
|
826
826
|
const pluralType = PLURAL_MODEL_ENTITIES[entity];
|
827
|
-
const
|
828
|
-
let json
|
829
|
-
|
830
|
-
|
827
|
+
const field = `${RONIN_MODEL_SYMBOLS.FIELD}${pluralType}`;
|
828
|
+
let json;
|
829
|
+
switch (action) {
|
830
|
+
case "create": {
|
831
|
+
const value = prepareStatementValue(statementParams, jsonValue);
|
832
|
+
json = `json_insert(${field}, '$.${slug}', ${value})`;
|
833
|
+
break;
|
834
|
+
}
|
835
|
+
case "alter": {
|
836
|
+
const value = prepareStatementValue(statementParams, jsonValue);
|
837
|
+
json = `json_set(${field}, '$.${slug}', json_patch(json_extract(${field}, '$.${slug}'), ${value}))`;
|
838
|
+
break;
|
839
|
+
}
|
840
|
+
case "drop": {
|
841
|
+
json = `json_remove(${field}, '$.${slug}')`;
|
842
|
+
}
|
843
|
+
}
|
831
844
|
return {
|
832
845
|
set: {
|
833
846
|
model: {
|