@ronin/compiler 0.10.2-leo-ron-1083-experimental-211 → 0.10.2-leo-ron-1083-experimental-213
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -70,6 +70,24 @@ executed and their results can be formatted by the compiler as well:
|
|
70
70
|
const results: Array<Result> = transaction.prepareResults(rows);
|
71
71
|
```
|
72
72
|
|
73
|
+
#### Root Model
|
74
|
+
|
75
|
+
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.
|
76
|
+
|
77
|
+
This table is called `ronin_master`, which mimics the default `sqlite_master` table provided by SQLite. You can generate its respective SQL statements like so:
|
78
|
+
|
79
|
+
```typescript
|
80
|
+
import { Transaction, ROOT_MODEL } from '@ronin/compiler';
|
81
|
+
|
82
|
+
const transaction = new Transaction([
|
83
|
+
{
|
84
|
+
create: { model: ROOT_MODEL }
|
85
|
+
}
|
86
|
+
]);
|
87
|
+
```
|
88
|
+
|
89
|
+
Afterward, run the statements located in `transaction.statements` to create the table for the root model. Once that is done, your database is prepared to run any statements generated by the compiler.
|
90
|
+
|
73
91
|
#### Types
|
74
92
|
|
75
93
|
In total, the following types are being exported:
|
@@ -110,12 +128,13 @@ new Transaction(queries, {
|
|
110
128
|
// names themselves are aliased.
|
111
129
|
//
|
112
130
|
// This ensures the cleanest possible SQL statements in conjunction with the default
|
113
|
-
// behavior of
|
114
|
-
//
|
131
|
+
// behavior of SQL databases, where the result of a statement is a list (array) of
|
132
|
+
// values, which are inherently not prone to conflicts.
|
115
133
|
//
|
116
134
|
// If the driver being used instead returns an object for every row, the driver must
|
117
135
|
// ensure the uniqueness of every key in that object, which means prefixing duplicated
|
118
136
|
// column names with the name of the respective table, if multiple tables are joined.
|
137
|
+
//
|
119
138
|
// Drivers that return objects for rows offer this behavior as an option that is
|
120
139
|
// usually called "expand columns". If the driver being used does not offer such an
|
121
140
|
// option, you can instead activate the option in the compiler, which results in longer
|
@@ -134,7 +153,7 @@ bun run dev
|
|
134
153
|
|
135
154
|
Whenever you make a change to the source code, it will then automatically be transpiled again.
|
136
155
|
|
137
|
-
###
|
156
|
+
### Architecture
|
138
157
|
|
139
158
|
The interface of creating new `Transaction` instances (thereby creating new transactions) was chosen in order to define the smallest workload unit that the compiler can operate on.
|
140
159
|
|
package/dist/index.d.ts
CHANGED
@@ -5979,7 +5979,7 @@ interface Model<T extends Array<ModelField> = Array<ModelField>> {
|
|
5979
5979
|
triggers?: Array<ModelTrigger<T>>;
|
5980
5980
|
presets?: Array<ModelPreset>;
|
5981
5981
|
}
|
5982
|
-
type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | '
|
5982
|
+
type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial<Model<T>>, 'slug' | 'identifiers' | 'system' | 'tableAlias'> & {
|
5983
5983
|
slug: Required<Model['slug']>;
|
5984
5984
|
identifiers?: Partial<Model['identifiers']>;
|
5985
5985
|
};
|
@@ -6035,4 +6035,6 @@ declare class Transaction {
|
|
6035
6035
|
prepareResults(results: Array<Array<Row>>): Array<Result>;
|
6036
6036
|
}
|
6037
6037
|
|
6038
|
-
|
6038
|
+
declare const CLEAN_ROOT_MODEL: PublicModel;
|
6039
|
+
|
6040
|
+
export { type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, type Query, CLEAN_ROOT_MODEL as ROOT_MODEL, type Result, type Statement, Transaction };
|
package/dist/index.js
CHANGED
@@ -93,6 +93,9 @@ var flatten = (obj, prefix = "", res = {}) => {
|
|
93
93
|
}
|
94
94
|
return res;
|
95
95
|
};
|
96
|
+
var omit = (obj, properties) => Object.fromEntries(
|
97
|
+
Object.entries(obj).filter(([key]) => !properties.includes(key))
|
98
|
+
);
|
96
99
|
var expand = (obj) => {
|
97
100
|
return Object.entries(obj).reduce((res, [key, val]) => {
|
98
101
|
key.split(".").reduce((acc, part, i, arr) => {
|
@@ -693,7 +696,7 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
693
696
|
if (!(modelSlug && slug)) return query;
|
694
697
|
const model = action === "create" && entity === "model" ? null : getModelBySlug(models, modelSlug);
|
695
698
|
if (entity === "model") {
|
696
|
-
let queryTypeDetails;
|
699
|
+
let queryTypeDetails = {};
|
697
700
|
if (action === "create") {
|
698
701
|
const newModel = jsonValue;
|
699
702
|
const modelWithFields = addDefaultModelFields(newModel, true);
|
@@ -749,6 +752,8 @@ var transformMetaQuery = (models, dependencyStatements, statementParams, query)
|
|
749
752
|
return handleSystemModel(models, dependencyStatements, "drop", systemModel);
|
750
753
|
});
|
751
754
|
}
|
755
|
+
const modelSlug2 = "to" in queryTypeDetails ? queryTypeDetails?.to?.slug : "with" in queryTypeDetails ? queryTypeDetails?.with?.slug : void 0;
|
756
|
+
if (modelSlug2 === "model") return null;
|
752
757
|
const queryTypeAction = action === "create" ? "add" : action === "alter" ? "set" : "remove";
|
753
758
|
return {
|
754
759
|
[queryTypeAction]: {
|
@@ -1340,6 +1345,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
|
|
1340
1345
|
statementParams,
|
1341
1346
|
defaultQuery
|
1342
1347
|
);
|
1348
|
+
if (query === null) return { dependencies: [], main: dependencyStatements[0] };
|
1343
1349
|
const parsedQuery = splitQuery(query);
|
1344
1350
|
const { queryType, queryModel, queryInstructions } = parsedQuery;
|
1345
1351
|
const model = getModelBySlug(models, queryModel);
|
@@ -1577,6 +1583,8 @@ var Transaction = class {
|
|
1577
1583
|
});
|
1578
1584
|
}
|
1579
1585
|
};
|
1586
|
+
var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
|
1580
1587
|
export {
|
1588
|
+
CLEAN_ROOT_MODEL as ROOT_MODEL,
|
1581
1589
|
Transaction
|
1582
1590
|
};
|
package/package.json
CHANGED