@ronin/compiler 0.12.2 → 0.12.3-leo-ron-1071-experimental-253
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 +1 -1
- package/dist/index.js +24 -12
- package/package.json +1 -1
package/README.md
CHANGED
@@ -76,7 +76,7 @@ const results: Array<Result> = transaction.formatResults(objectResults, false);
|
|
76
76
|
|
77
77
|
Before you can run any statements generated by the compiler that are altering the database schema, you need to create the table of the so-called "root model", which is used to store metadata for all other models.
|
78
78
|
|
79
|
-
This table is called `ronin_schema`, which mimics the default `sqlite_schema` table provided by SQLite. You can generate its respective SQL statements like
|
79
|
+
This table is called `ronin_schema`, which mimics the default `sqlite_schema` table provided by SQLite. You can generate its respective SQL statements like this:
|
80
80
|
|
81
81
|
```typescript
|
82
82
|
import { Transaction, ROOT_MODEL } from '@ronin/compiler';
|
package/dist/index.js
CHANGED
@@ -435,7 +435,7 @@ var pluralize = (word) => {
|
|
435
435
|
}
|
436
436
|
return `${word}s`;
|
437
437
|
};
|
438
|
-
var
|
438
|
+
var modelAttributes = [
|
439
439
|
["pluralSlug", "slug", pluralize],
|
440
440
|
["name", "slug", slugToName],
|
441
441
|
["pluralName", "pluralSlug", slugToName],
|
@@ -444,7 +444,7 @@ var modelSettings = [
|
|
444
444
|
];
|
445
445
|
var addDefaultModelFields = (model, isNew) => {
|
446
446
|
const copiedModel = { ...model };
|
447
|
-
for (const [setting, base, generator] of
|
447
|
+
for (const [setting, base, generator] of modelAttributes) {
|
448
448
|
if (copiedModel[setting] || !copiedModel[base]) continue;
|
449
449
|
copiedModel[setting] = generator(copiedModel[base]);
|
450
450
|
}
|
@@ -732,23 +732,30 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
732
732
|
[...models, modelWithFields],
|
733
733
|
modelWithFields
|
734
734
|
);
|
735
|
+
modelWithPresets.fields = modelWithPresets.fields.map((field2) => ({
|
736
|
+
...field2,
|
737
|
+
// Default field type.
|
738
|
+
type: field2.type || "string",
|
739
|
+
// Default field name.
|
740
|
+
name: field2.name || slugToName(field2.slug)
|
741
|
+
}));
|
742
|
+
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
735
743
|
const entities = Object.fromEntries(
|
736
744
|
Object.entries(PLURAL_MODEL_ENTITIES).map(([type, pluralType2]) => {
|
737
745
|
const list = modelWithPresets[pluralType2];
|
738
746
|
return [pluralType2, formatModelEntity(type, list)];
|
739
747
|
})
|
740
748
|
);
|
741
|
-
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
742
749
|
dependencyStatements.push({
|
743
750
|
statement: `CREATE TABLE "${modelWithPresets.table}" (${columns.join(", ")})`,
|
744
751
|
params: []
|
745
752
|
});
|
746
753
|
models.push(modelWithPresets);
|
747
|
-
const
|
754
|
+
const modelWithObjects = Object.assign({}, modelWithPresets);
|
748
755
|
for (const entity2 in entities) {
|
749
|
-
if (entities[entity2])
|
756
|
+
if (entities[entity2]) modelWithObjects[entity2] = entities[entity2];
|
750
757
|
}
|
751
|
-
queryTypeDetails = { to:
|
758
|
+
queryTypeDetails = { to: modelWithObjects };
|
752
759
|
getSystemModels(models, modelWithPresets).map((systemModel) => {
|
753
760
|
return handleSystemModel(models, dependencyStatements, "create", systemModel);
|
754
761
|
});
|
@@ -809,6 +816,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
809
816
|
if (action === "create") {
|
810
817
|
const field2 = jsonValue;
|
811
818
|
field2.type = field2.type || "string";
|
819
|
+
field2.name = field2.name || slugToName(field2.slug);
|
812
820
|
const fieldStatement = getFieldStatement(models, existingModel, field2);
|
813
821
|
if (fieldStatement) {
|
814
822
|
dependencyStatements.push({
|
@@ -817,12 +825,16 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
817
825
|
});
|
818
826
|
}
|
819
827
|
} else if (action === "alter") {
|
820
|
-
const
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
828
|
+
const field2 = jsonValue;
|
829
|
+
const newSlug = field2.slug;
|
830
|
+
if (newSlug) {
|
831
|
+
field2.name = field2.name || slugToName(field2.slug);
|
832
|
+
if (!existingLinkField) {
|
833
|
+
dependencyStatements.push({
|
834
|
+
statement: `${statement} RENAME COLUMN "${slug}" TO "${newSlug}"`,
|
835
|
+
params: []
|
836
|
+
});
|
837
|
+
}
|
826
838
|
}
|
827
839
|
} else if (action === "drop" && !existingLinkField) {
|
828
840
|
dependencyStatements.push({
|