@ronin/compiler 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.js +182 -108
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
@@ -5919,6 +5919,10 @@ type ModelTriggerField<T extends Array<ModelField> = Array<ModelField>> = {
|
|
5919
5919
|
slug: T[number]['slug'];
|
5920
5920
|
};
|
5921
5921
|
type ModelTrigger<T extends Array<ModelField> = Array<ModelField>> = {
|
5922
|
+
/**
|
5923
|
+
* The identifier of the trigger.
|
5924
|
+
*/
|
5925
|
+
slug?: string;
|
5922
5926
|
/** The type of query for which the trigger should fire. */
|
5923
5927
|
action: 'INSERT' | 'UPDATE' | 'DELETE';
|
5924
5928
|
/** When the trigger should fire in the case that a matching query is executed. */
|
@@ -5957,17 +5961,25 @@ interface Model<T extends Array<ModelField> = Array<ModelField>> {
|
|
5957
5961
|
*/
|
5958
5962
|
tableAlias?: string;
|
5959
5963
|
/**
|
5960
|
-
*
|
5961
|
-
*
|
5962
|
-
* the associative model should be mounted on the source model.
|
5964
|
+
* Details that identify the model as a model that was automatically created by RONIN,
|
5965
|
+
* instead of being manually created by a developer.
|
5963
5966
|
*/
|
5964
|
-
|
5967
|
+
system?: {
|
5968
|
+
/** The model that caused the system model to get created. */
|
5969
|
+
model: string | 'root';
|
5970
|
+
/**
|
5971
|
+
* If the model is used to associate two models with each other (in the case of
|
5972
|
+
* many-cardinality link fields), this property should contain the field slug to
|
5973
|
+
* which the associative model should be mounted on the source model.
|
5974
|
+
*/
|
5975
|
+
associationSlug?: string;
|
5976
|
+
};
|
5965
5977
|
fields: T;
|
5966
5978
|
indexes?: Array<ModelIndex<T>>;
|
5967
5979
|
triggers?: Array<ModelTrigger<T>>;
|
5968
5980
|
presets?: Array<ModelPreset>;
|
5969
5981
|
}
|
5970
|
-
type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | '
|
5982
|
+
type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | 'table' | 'tableAlias'> & {
|
5971
5983
|
slug: Required<Model['slug']>;
|
5972
5984
|
identifiers?: Partial<Model['identifiers']>;
|
5973
5985
|
};
|
package/dist/index.js
CHANGED
@@ -20,6 +20,12 @@ var RONIN_MODEL_FIELD_REGEX = new RegExp(
|
|
20
20
|
`${RONIN_MODEL_SYMBOLS.FIELD}[_a-zA-Z0-9]+`,
|
21
21
|
"g"
|
22
22
|
);
|
23
|
+
var MODEL_ENTITY_ERROR_CODES = {
|
24
|
+
field: "FIELD_NOT_FOUND",
|
25
|
+
index: "INDEX_NOT_FOUND",
|
26
|
+
trigger: "TRIGGER_NOT_FOUND",
|
27
|
+
preset: "PRESET_NOT_FOUND"
|
28
|
+
};
|
23
29
|
var RoninError = class extends Error {
|
24
30
|
code;
|
25
31
|
field;
|
@@ -459,67 +465,67 @@ var SYSTEM_FIELDS = [
|
|
459
465
|
slug: "ronin.updatedBy"
|
460
466
|
}
|
461
467
|
];
|
462
|
-
var
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
var
|
492
|
-
const
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
468
|
+
var ROOT_MODEL = {
|
469
|
+
slug: "model",
|
470
|
+
identifiers: {
|
471
|
+
name: "name",
|
472
|
+
slug: "slug"
|
473
|
+
},
|
474
|
+
// This name mimics the `sqlite_schema` table in SQLite.
|
475
|
+
table: "ronin_schema",
|
476
|
+
// Indicates that the model was automatically generated by RONIN.
|
477
|
+
system: { model: "root" },
|
478
|
+
fields: [
|
479
|
+
{ slug: "name", type: "string" },
|
480
|
+
{ slug: "pluralName", type: "string" },
|
481
|
+
{ slug: "slug", type: "string" },
|
482
|
+
{ slug: "pluralSlug", type: "string" },
|
483
|
+
{ slug: "idPrefix", type: "string" },
|
484
|
+
{ slug: "table", type: "string" },
|
485
|
+
{ slug: "identifiers", type: "group" },
|
486
|
+
{ slug: "identifiers.name", type: "string" },
|
487
|
+
{ slug: "identifiers.slug", type: "string" },
|
488
|
+
// Providing an empty object as a default value allows us to use `json_insert`
|
489
|
+
// without needing to fall back to an empty object in the insertion statement,
|
490
|
+
// which makes the statement shorter.
|
491
|
+
{ slug: "fields", type: "json", defaultValue: "{}" },
|
492
|
+
{ slug: "indexes", type: "json", defaultValue: "{}" },
|
493
|
+
{ slug: "triggers", type: "json", defaultValue: "{}" },
|
494
|
+
{ slug: "presets", type: "json", defaultValue: "{}" }
|
495
|
+
]
|
496
|
+
};
|
497
|
+
var getSystemModels = (models, model) => {
|
498
|
+
const addedModels = [];
|
499
|
+
for (const field of model.fields || []) {
|
500
|
+
if (field.type === "link" && !field.slug.startsWith("ronin.")) {
|
501
|
+
const relatedModel = getModelBySlug(models, field.target);
|
502
|
+
let fieldSlug = relatedModel.slug;
|
503
|
+
if (field.kind === "many") {
|
504
|
+
fieldSlug = composeAssociationModelSlug(model, field);
|
505
|
+
addedModels.push({
|
506
|
+
pluralSlug: fieldSlug,
|
507
|
+
slug: fieldSlug,
|
508
|
+
system: {
|
509
|
+
model: model.slug,
|
510
|
+
associationSlug: field.slug
|
511
|
+
},
|
512
|
+
fields: [
|
513
|
+
{
|
514
|
+
slug: "source",
|
515
|
+
type: "link",
|
516
|
+
target: model.slug
|
517
|
+
},
|
518
|
+
{
|
519
|
+
slug: "target",
|
520
|
+
type: "link",
|
521
|
+
target: relatedModel.slug
|
522
|
+
}
|
523
|
+
]
|
524
|
+
});
|
518
525
|
}
|
519
526
|
}
|
520
|
-
|
521
|
-
|
522
|
-
return [...SYSTEM_MODELS, ...associativeModels, ...models];
|
527
|
+
}
|
528
|
+
return addedModels;
|
523
529
|
};
|
524
530
|
var addDefaultModelPresets = (list, model) => {
|
525
531
|
const defaultPresets = [];
|
@@ -561,7 +567,7 @@ var addDefaultModelPresets = (list, model) => {
|
|
561
567
|
for (const childMatch of childModels) {
|
562
568
|
const { model: childModel, field: childField } = childMatch;
|
563
569
|
const pluralSlug = childModel.pluralSlug;
|
564
|
-
const presetSlug = childModel.associationSlug || pluralSlug;
|
570
|
+
const presetSlug = childModel.system?.associationSlug || pluralSlug;
|
565
571
|
defaultPresets.push({
|
566
572
|
instructions: {
|
567
573
|
including: {
|
@@ -617,6 +623,7 @@ var getFieldStatement = (models, model, field) => {
|
|
617
623
|
statement += ` GENERATED ALWAYS AS (${parseFieldExpression(model, "to", symbol?.value)}) ${kind}`;
|
618
624
|
}
|
619
625
|
if (field.type === "link") {
|
626
|
+
if (field.kind === "many") return null;
|
620
627
|
const actions = field.actions || {};
|
621
628
|
const targetTable = getModelBySlug(models, field.target).table;
|
622
629
|
statement += ` REFERENCES ${targetTable}("id")`;
|
@@ -641,6 +648,14 @@ var formatModelEntity = (type, entities) => {
|
|
641
648
|
});
|
642
649
|
return entries ? Object.fromEntries(entries) : void 0;
|
643
650
|
};
|
651
|
+
var composeSystemModelStatement = (models, dependencyStatements, action, systemModel) => {
|
652
|
+
const { system: _, ...systemModelClean } = systemModel;
|
653
|
+
const query = {
|
654
|
+
[action]: { model: action === "create" ? systemModelClean : systemModelClean.slug }
|
655
|
+
};
|
656
|
+
const statement = compileQueryInput(query, models, []);
|
657
|
+
dependencyStatements.push(...statement.dependencies);
|
658
|
+
};
|
644
659
|
var transformMetaQuery = (models, dependencyStatements, statementParams, query) => {
|
645
660
|
const { queryType } = splitQuery(query);
|
646
661
|
const subAltering = query.alter && !("to" in query.alter);
|
@@ -669,16 +684,16 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
669
684
|
}
|
670
685
|
}
|
671
686
|
if (!(modelSlug && slug)) return query;
|
672
|
-
const tableAction = ["model", "index", "trigger"].includes(entity) ? action.toUpperCase() : "ALTER";
|
673
|
-
const tableName = convertToSnakeCase(pluralize(modelSlug));
|
674
687
|
const model = action === "create" && entity === "model" ? null : getModelBySlug(models, modelSlug);
|
675
|
-
const statement = `${tableAction} TABLE "${tableName}"`;
|
676
688
|
if (entity === "model") {
|
677
689
|
let queryTypeDetails;
|
678
690
|
if (action === "create") {
|
679
691
|
const newModel = jsonValue;
|
680
692
|
const modelWithFields = addDefaultModelFields(newModel, true);
|
681
|
-
const modelWithPresets = addDefaultModelPresets(
|
693
|
+
const modelWithPresets = addDefaultModelPresets(
|
694
|
+
[...models, modelWithFields],
|
695
|
+
modelWithFields
|
696
|
+
);
|
682
697
|
const entities = Object.fromEntries(
|
683
698
|
Object.entries(PLURAL_MODEL_ENTITIES).map(([type, pluralType2]) => {
|
684
699
|
const list = modelWithPresets[pluralType2];
|
@@ -687,7 +702,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
687
702
|
);
|
688
703
|
const columns = modelWithPresets.fields.map((field2) => getFieldStatement(models, modelWithPresets, field2)).filter(Boolean);
|
689
704
|
dependencyStatements.push({
|
690
|
-
statement:
|
705
|
+
statement: `CREATE TABLE "${modelWithPresets.table}" (${columns.join(", ")})`,
|
691
706
|
params: []
|
692
707
|
});
|
693
708
|
models.push(modelWithPresets);
|
@@ -696,16 +711,23 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
696
711
|
if (entities[entity2]) finalModel[entity2] = entities[entity2];
|
697
712
|
}
|
698
713
|
queryTypeDetails = { to: finalModel };
|
714
|
+
getSystemModels(models, modelWithPresets).map((systemModel) => {
|
715
|
+
return composeSystemModelStatement(
|
716
|
+
models,
|
717
|
+
dependencyStatements,
|
718
|
+
"create",
|
719
|
+
systemModel
|
720
|
+
);
|
721
|
+
});
|
699
722
|
}
|
700
723
|
if (action === "alter" && model) {
|
701
724
|
const newModel = jsonValue;
|
702
725
|
const modelWithFields = addDefaultModelFields(newModel, false);
|
703
726
|
const modelWithPresets = addDefaultModelPresets(models, modelWithFields);
|
704
|
-
const
|
705
|
-
if (
|
706
|
-
const newTable = convertToSnakeCase(newSlug);
|
727
|
+
const newTableName = modelWithPresets.table;
|
728
|
+
if (newTableName) {
|
707
729
|
dependencyStatements.push({
|
708
|
-
statement:
|
730
|
+
statement: `ALTER TABLE "${model.table}" RENAME TO "${newTableName}"`,
|
709
731
|
params: []
|
710
732
|
});
|
711
733
|
}
|
@@ -719,8 +741,16 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
719
741
|
}
|
720
742
|
if (action === "drop" && model) {
|
721
743
|
models.splice(models.indexOf(model), 1);
|
722
|
-
dependencyStatements.push({ statement
|
744
|
+
dependencyStatements.push({ statement: `DROP TABLE "${model.table}"`, params: [] });
|
723
745
|
queryTypeDetails = { with: { slug } };
|
746
|
+
models.filter(({ system }) => system?.model === model.slug).map((systemModel) => {
|
747
|
+
return composeSystemModelStatement(
|
748
|
+
models,
|
749
|
+
dependencyStatements,
|
750
|
+
"drop",
|
751
|
+
systemModel
|
752
|
+
);
|
753
|
+
});
|
724
754
|
}
|
725
755
|
const queryTypeAction = action === "create" ? "add" : action === "alter" ? "set" : "remove";
|
726
756
|
return {
|
@@ -729,14 +759,30 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
729
759
|
}
|
730
760
|
};
|
731
761
|
}
|
732
|
-
|
762
|
+
const existingModel = model;
|
763
|
+
const pluralType = PLURAL_MODEL_ENTITIES[entity];
|
764
|
+
const targetEntityIndex = existingModel[pluralType]?.findIndex(
|
765
|
+
(entity2) => entity2.slug === slug
|
766
|
+
);
|
767
|
+
if ((action === "alter" || action === "drop") && (typeof targetEntityIndex === "undefined" || targetEntityIndex === -1)) {
|
768
|
+
throw new RoninError({
|
769
|
+
message: `No ${entity} with slug "${slug}" defined in model "${existingModel.name}".`,
|
770
|
+
code: MODEL_ENTITY_ERROR_CODES[entity]
|
771
|
+
});
|
772
|
+
}
|
773
|
+
const existingEntity = existingModel[pluralType]?.[targetEntityIndex];
|
774
|
+
if (entity === "field") {
|
775
|
+
const statement = `ALTER TABLE "${existingModel.table}"`;
|
733
776
|
if (action === "create") {
|
734
777
|
const field2 = jsonValue;
|
735
778
|
field2.type = field2.type || "string";
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
779
|
+
const fieldStatement = getFieldStatement(models, existingModel, field2);
|
780
|
+
if (fieldStatement) {
|
781
|
+
dependencyStatements.push({
|
782
|
+
statement: `${statement} ADD COLUMN ${fieldStatement}`,
|
783
|
+
params: []
|
784
|
+
});
|
785
|
+
}
|
740
786
|
} else if (action === "alter") {
|
741
787
|
const newSlug = jsonValue?.slug;
|
742
788
|
if (newSlug) {
|
@@ -746,41 +792,45 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
746
792
|
});
|
747
793
|
}
|
748
794
|
} else if (action === "drop") {
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
795
|
+
const existingField = existingEntity;
|
796
|
+
if (!(existingField.type === "link" && existingField.kind === "many")) {
|
797
|
+
dependencyStatements.push({
|
798
|
+
statement: `${statement} DROP COLUMN "${slug}"`,
|
799
|
+
params: []
|
800
|
+
});
|
801
|
+
}
|
753
802
|
}
|
754
803
|
}
|
755
|
-
|
804
|
+
const statementAction = action.toUpperCase();
|
805
|
+
if (entity === "index") {
|
756
806
|
const index = jsonValue;
|
757
807
|
const indexName = convertToSnakeCase(slug);
|
758
808
|
const params = [];
|
759
|
-
let
|
809
|
+
let statement = `${statementAction}${index?.unique ? " UNIQUE" : ""} INDEX "${indexName}"`;
|
760
810
|
if (action === "create") {
|
761
811
|
const columns = index.fields.map((field2) => {
|
762
812
|
let fieldSelector = "";
|
763
813
|
if ("slug" in field2) {
|
764
|
-
({ fieldSelector } = getFieldFromModel(
|
814
|
+
({ fieldSelector } = getFieldFromModel(existingModel, field2.slug, "to"));
|
765
815
|
} else if ("expression" in field2) {
|
766
|
-
fieldSelector = parseFieldExpression(
|
816
|
+
fieldSelector = parseFieldExpression(existingModel, "to", field2.expression);
|
767
817
|
}
|
768
818
|
if (field2.collation) fieldSelector += ` COLLATE ${field2.collation}`;
|
769
819
|
if (field2.order) fieldSelector += ` ${field2.order}`;
|
770
820
|
return fieldSelector;
|
771
821
|
});
|
772
|
-
|
822
|
+
statement += ` ON "${existingModel.table}" (${columns.join(", ")})`;
|
773
823
|
if (index.filter) {
|
774
|
-
const withStatement = handleWith(models,
|
775
|
-
|
824
|
+
const withStatement = handleWith(models, existingModel, params, index.filter);
|
825
|
+
statement += ` WHERE (${withStatement})`;
|
776
826
|
}
|
777
827
|
}
|
778
|
-
dependencyStatements.push({ statement
|
828
|
+
dependencyStatements.push({ statement, params });
|
779
829
|
}
|
780
|
-
if (entity === "trigger"
|
830
|
+
if (entity === "trigger") {
|
781
831
|
const triggerName = convertToSnakeCase(slug);
|
782
832
|
const params = [];
|
783
|
-
let
|
833
|
+
let statement = `${statementAction} TRIGGER "${triggerName}"`;
|
784
834
|
if (action === "create") {
|
785
835
|
const trigger = jsonValue;
|
786
836
|
const statementParts = [`${trigger.when} ${trigger.action}`];
|
@@ -793,11 +843,11 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
793
843
|
});
|
794
844
|
}
|
795
845
|
const fieldSelectors = trigger.fields.map((field2) => {
|
796
|
-
return getFieldFromModel(
|
846
|
+
return getFieldFromModel(existingModel, field2.slug, "to").fieldSelector;
|
797
847
|
});
|
798
848
|
statementParts.push(`OF (${fieldSelectors.join(", ")})`);
|
799
849
|
}
|
800
|
-
statementParts.push("ON", `"${
|
850
|
+
statementParts.push("ON", `"${existingModel.table}"`);
|
801
851
|
if (trigger.filter || trigger.effects.some((query2) => findInObject(query2, RONIN_MODEL_SYMBOLS.FIELD))) {
|
802
852
|
statementParts.push("FOR EACH ROW");
|
803
853
|
}
|
@@ -805,7 +855,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
805
855
|
const tableAlias = trigger.action === "DELETE" ? RONIN_MODEL_SYMBOLS.FIELD_PARENT_OLD : RONIN_MODEL_SYMBOLS.FIELD_PARENT_NEW;
|
806
856
|
const withStatement = handleWith(
|
807
857
|
models,
|
808
|
-
{ ...
|
858
|
+
{ ...existingModel, tableAlias },
|
809
859
|
params,
|
810
860
|
trigger.filter
|
811
861
|
);
|
@@ -814,34 +864,55 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
814
864
|
const effectStatements = trigger.effects.map((effectQuery) => {
|
815
865
|
return compileQueryInput(effectQuery, models, params, {
|
816
866
|
returning: false,
|
817
|
-
parentModel:
|
867
|
+
parentModel: existingModel
|
818
868
|
}).main.statement;
|
819
869
|
});
|
820
870
|
if (effectStatements.length > 1) statementParts.push("BEGIN");
|
821
871
|
statementParts.push(effectStatements.join("; "));
|
822
872
|
if (effectStatements.length > 1) statementParts.push("END");
|
823
|
-
|
873
|
+
statement += ` ${statementParts.join(" ")}`;
|
824
874
|
}
|
825
|
-
dependencyStatements.push({ statement
|
875
|
+
dependencyStatements.push({ statement, params });
|
826
876
|
}
|
827
|
-
const pluralType = PLURAL_MODEL_ENTITIES[entity];
|
828
877
|
const field = `${RONIN_MODEL_SYMBOLS.FIELD}${pluralType}`;
|
829
878
|
let json;
|
830
879
|
switch (action) {
|
831
880
|
case "create": {
|
832
881
|
const value = prepareStatementValue(statementParams, jsonValue);
|
833
882
|
json = `json_insert(${field}, '$.${slug}', ${value})`;
|
883
|
+
existingModel[pluralType] = [
|
884
|
+
...existingModel[pluralType] || [],
|
885
|
+
jsonValue
|
886
|
+
];
|
834
887
|
break;
|
835
888
|
}
|
836
889
|
case "alter": {
|
837
890
|
const value = prepareStatementValue(statementParams, jsonValue);
|
838
891
|
json = `json_set(${field}, '$.${slug}', json_patch(json_extract(${field}, '$.${slug}'), ${value}))`;
|
892
|
+
const targetEntity = existingModel[pluralType];
|
893
|
+
targetEntity[targetEntityIndex] = jsonValue;
|
839
894
|
break;
|
840
895
|
}
|
841
896
|
case "drop": {
|
842
897
|
json = `json_remove(${field}, '$.${slug}')`;
|
898
|
+
const targetEntity = existingModel[pluralType];
|
899
|
+
targetEntity.splice(targetEntityIndex, 1);
|
843
900
|
}
|
844
901
|
}
|
902
|
+
const currentSystemModels = models.filter(({ system }) => {
|
903
|
+
return system?.model === existingModel.slug;
|
904
|
+
});
|
905
|
+
const newSystemModels = getSystemModels(models, existingModel);
|
906
|
+
for (const systemModel of currentSystemModels) {
|
907
|
+
const exists = newSystemModels.find((model2) => model2.slug === systemModel.slug);
|
908
|
+
if (exists) continue;
|
909
|
+
composeSystemModelStatement(models, dependencyStatements, "drop", systemModel);
|
910
|
+
}
|
911
|
+
for (const systemModel of newSystemModels) {
|
912
|
+
const exists = currentSystemModels.find((model2) => model2.slug === systemModel.slug);
|
913
|
+
if (exists) continue;
|
914
|
+
composeSystemModelStatement(models, dependencyStatements, "create", systemModel);
|
915
|
+
}
|
845
916
|
return {
|
846
917
|
set: {
|
847
918
|
model: {
|
@@ -1212,13 +1283,19 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1212
1283
|
};
|
1213
1284
|
|
1214
1285
|
// src/utils/index.ts
|
1215
|
-
var compileQueryInput = (
|
1286
|
+
var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
1287
|
+
const dependencyStatements = [];
|
1288
|
+
const query = transformMetaQuery(
|
1289
|
+
models,
|
1290
|
+
dependencyStatements,
|
1291
|
+
statementParams,
|
1292
|
+
defaultQuery
|
1293
|
+
);
|
1216
1294
|
const parsedQuery = splitQuery(query);
|
1217
1295
|
const { queryType, queryModel, queryInstructions } = parsedQuery;
|
1218
1296
|
const model = getModelBySlug(models, queryModel);
|
1219
1297
|
const single = queryModel !== model.pluralSlug;
|
1220
1298
|
let instructions = formatIdentifiers(model, queryInstructions);
|
1221
|
-
const dependencyStatements = [];
|
1222
1299
|
const returning = options?.returning ?? true;
|
1223
1300
|
if (instructions && Object.hasOwn(instructions, "for")) {
|
1224
1301
|
instructions = handleFor(model, instructions);
|
@@ -1370,7 +1447,11 @@ var Transaction = class {
|
|
1370
1447
|
* @returns The composed SQL statements.
|
1371
1448
|
*/
|
1372
1449
|
compileQueries = (queries, models, options) => {
|
1373
|
-
const modelList =
|
1450
|
+
const modelList = [
|
1451
|
+
ROOT_MODEL,
|
1452
|
+
...models.flatMap((model) => getSystemModels(models, model)),
|
1453
|
+
...models
|
1454
|
+
].map((model) => {
|
1374
1455
|
return addDefaultModelFields(model, true);
|
1375
1456
|
});
|
1376
1457
|
const modelListWithPresets = modelList.map((model) => {
|
@@ -1379,17 +1460,10 @@ var Transaction = class {
|
|
1379
1460
|
const dependencyStatements = [];
|
1380
1461
|
const mainStatements = [];
|
1381
1462
|
for (const query of queries) {
|
1382
|
-
const statementValues = options?.inlineParams ? null : [];
|
1383
|
-
const transformedQuery = transformMetaQuery(
|
1384
|
-
modelListWithPresets,
|
1385
|
-
dependencyStatements,
|
1386
|
-
statementValues,
|
1387
|
-
query
|
1388
|
-
);
|
1389
1463
|
const result = compileQueryInput(
|
1390
|
-
|
1464
|
+
query,
|
1391
1465
|
modelListWithPresets,
|
1392
|
-
|
1466
|
+
options?.inlineParams ? null : []
|
1393
1467
|
);
|
1394
1468
|
dependencyStatements.push(...result.dependencies);
|
1395
1469
|
mainStatements.push(result.main);
|