@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.
Files changed (2) hide show
  1. package/dist/index.js +30 -17
  2. 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((field) => getFieldStatement(models, modelWithPresets, field)).filter(Boolean);
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 field = jsonValue;
734
- field.type = field.type || "string";
733
+ const field2 = jsonValue;
734
+ field2.type = field2.type || "string";
735
735
  dependencyStatements.push({
736
- statement: `${statement} ADD COLUMN ${getFieldStatement(models, model, field)}`,
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((field) => {
760
+ const columns = index.fields.map((field2) => {
761
761
  let fieldSelector = "";
762
- if ("slug" in field) {
763
- ({ fieldSelector } = getFieldFromModel(model, field.slug, "to"));
764
- } else if ("expression" in field) {
765
- fieldSelector = parseFieldExpression(model, "to", field.expression);
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 (field.collation) fieldSelector += ` COLLATE ${field.collation}`;
768
- if (field.order) fieldSelector += ` ${field.order}`;
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((field) => {
795
- return getFieldFromModel(model, field.slug, "to").fieldSelector;
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 jsonAction = action === "create" ? "insert" : action === "alter" ? "patch" : "remove";
828
- let json = `json_${jsonAction}(${RONIN_MODEL_SYMBOLS.FIELD}${pluralType}, '$.${slug}'`;
829
- if (jsonValue) json += `, ${prepareStatementValue(statementParams, jsonValue)}`;
830
- json += ")";
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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {