@c9up/atlas 0.3.10 → 0.3.12
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/db.darwin-arm64.node +0 -0
- package/db.darwin-x64.node +0 -0
- package/db.linux-arm64-gnu.node +0 -0
- package/db.linux-x64-gnu.node +0 -0
- package/db.win32-x64-msvc.node +0 -0
- package/dist/AtlasProvider.d.ts +1 -0
- package/dist/AtlasProvider.d.ts.map +1 -1
- package/dist/AtlasProvider.js +52 -13
- package/dist/AtlasProvider.js.map +1 -1
- package/dist/BaseRepository.d.ts.map +1 -1
- package/dist/BaseRepository.js +30 -12
- package/dist/BaseRepository.js.map +1 -1
- package/dist/ModelQuery.d.ts.map +1 -1
- package/dist/ModelQuery.js +34 -13
- package/dist/ModelQuery.js.map +1 -1
- package/dist/augmentations.d.ts +44 -0
- package/dist/augmentations.d.ts.map +1 -0
- package/dist/augmentations.js +19 -0
- package/dist/augmentations.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/query/DatabaseQueryBuilder.d.ts.map +1 -1
- package/dist/query/DatabaseQueryBuilder.js +24 -8
- package/dist/query/DatabaseQueryBuilder.js.map +1 -1
- package/dist/query/QueryBuilder.js +15 -1
- package/dist/query/QueryBuilder.js.map +1 -1
- package/dist/schema/MigrationRunner.d.ts.map +1 -1
- package/dist/schema/MigrationRunner.js +112 -7
- package/dist/schema/MigrationRunner.js.map +1 -1
- package/dist/schema/SchemaCheck.d.ts.map +1 -1
- package/dist/schema/SchemaCheck.js +19 -7
- package/dist/schema/SchemaCheck.js.map +1 -1
- package/dist/testing/DatabaseCleanup.js +15 -1
- package/dist/testing/DatabaseCleanup.js.map +1 -1
- package/dist/testing/Factory.js +2 -2
- package/dist/testing/Factory.js.map +1 -1
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +10 -5
- package/scripts/build-napi-types.mjs +4 -3
- package/scripts/generate-napi-types.mjs +9 -6
- package/src/AtlasProvider.ts +65 -18
- package/src/BaseRepository.ts +30 -12
- package/src/ModelQuery.ts +37 -11
- package/src/augmentations.ts +49 -0
- package/src/index.ts +1 -0
- package/src/query/DatabaseQueryBuilder.ts +25 -8
- package/src/query/QueryBuilder.ts +16 -1
- package/src/schema/MigrationRunner.ts +124 -11
- package/src/schema/SchemaCheck.ts +27 -10
- package/src/testing/DatabaseCleanup.ts +16 -1
- package/src/testing/Factory.ts +2 -2
package/dist/ModelQuery.js
CHANGED
|
@@ -619,8 +619,10 @@ export class ModelQuery {
|
|
|
619
619
|
// `col as alias` — resolve the (bare) column part to its DB name, keep the
|
|
620
620
|
// alias verbatim, so `select('label as name')` honours a columnName override.
|
|
621
621
|
const aliased = col.match(/^([A-Za-z_][A-Za-z0-9_]*)\s+as\s+([A-Za-z_][A-Za-z0-9_]*)$/i);
|
|
622
|
-
|
|
623
|
-
|
|
622
|
+
const [, aliasSource, aliasName] = aliased ?? [];
|
|
623
|
+
if (aliasSource !== undefined && aliasName !== undefined) {
|
|
624
|
+
return `${this.#resolveColumn(aliasSource)} AS ${aliasName}`;
|
|
625
|
+
}
|
|
624
626
|
return col;
|
|
625
627
|
}
|
|
626
628
|
where(columnOrCb, operatorOrValue, value) {
|
|
@@ -2003,7 +2005,11 @@ export class ModelQuery {
|
|
|
2003
2005
|
if (rows.length > 1) {
|
|
2004
2006
|
throw new Error(`Expected exactly one ${this.#tableName} but the query matched multiple rows (sole()).`);
|
|
2005
2007
|
}
|
|
2006
|
-
|
|
2008
|
+
const [only] = rows;
|
|
2009
|
+
if (only === undefined) {
|
|
2010
|
+
throw new Error(`Expected exactly one ${this.#tableName} but the query matched none (sole()).`);
|
|
2011
|
+
}
|
|
2012
|
+
return only;
|
|
2007
2013
|
}
|
|
2008
2014
|
/**
|
|
2009
2015
|
* Thenable — `await someQuery` is equivalent to `await someQuery.exec()`.
|
|
@@ -2155,7 +2161,7 @@ export class ModelQuery {
|
|
|
2155
2161
|
*/
|
|
2156
2162
|
#compiledNative() {
|
|
2157
2163
|
const compiled = compileStatementNative(this.#buildSpec(), this.#dialect);
|
|
2158
|
-
const sql = this.#commentPrefix() + compiled
|
|
2164
|
+
const sql = this.#commentPrefix() + onlyStatement(compiled);
|
|
2159
2165
|
return { sql, params: compiled.params };
|
|
2160
2166
|
}
|
|
2161
2167
|
/**
|
|
@@ -2806,7 +2812,7 @@ export class ModelQuery {
|
|
|
2806
2812
|
lockMode: null,
|
|
2807
2813
|
};
|
|
2808
2814
|
const compiled = compileStatementNative(spec, this.#dialect);
|
|
2809
|
-
return this.#db.query(compiled
|
|
2815
|
+
return this.#db.query(onlyStatement(compiled), compiled.params);
|
|
2810
2816
|
}
|
|
2811
2817
|
/**
|
|
2812
2818
|
* Run a relation preload against the related table, applying the relation's
|
|
@@ -3287,13 +3293,14 @@ export class ModelQuery {
|
|
|
3287
3293
|
}
|
|
3288
3294
|
// Build the disjunctive tuple comparison as a nested group of WHEREs.
|
|
3289
3295
|
clone.where((q) => {
|
|
3290
|
-
for (
|
|
3296
|
+
for (const [i, col] of cols.entries()) {
|
|
3291
3297
|
q.orWhere((inner) => {
|
|
3292
|
-
for (
|
|
3293
|
-
inner.where(
|
|
3298
|
+
for (const [j, earlier] of cols.slice(0, i).entries()) {
|
|
3299
|
+
inner.where(earlier, decoded.v[j]);
|
|
3300
|
+
}
|
|
3294
3301
|
// The comparison has to follow the walk: `>` reads forward
|
|
3295
3302
|
// through an ascending order, `<` through a descending one.
|
|
3296
|
-
inner.where(
|
|
3303
|
+
inner.where(col, descending ? "<" : ">", decoded.v[i]);
|
|
3297
3304
|
});
|
|
3298
3305
|
}
|
|
3299
3306
|
});
|
|
@@ -3771,7 +3778,7 @@ export class ModelQuery {
|
|
|
3771
3778
|
ctes: this.#compiledCtes(),
|
|
3772
3779
|
};
|
|
3773
3780
|
const compiled = compileStatementNative(spec, this.#dialect);
|
|
3774
|
-
const r = await this.#raceTimeout(this.#db.execute(this.#commentPrefix() + compiled
|
|
3781
|
+
const r = await this.#raceTimeout(this.#db.execute(this.#commentPrefix() + onlyStatement(compiled), compiled.params, this.#meta("dml")));
|
|
3775
3782
|
return r.rowsAffected ?? 0;
|
|
3776
3783
|
}
|
|
3777
3784
|
/**
|
|
@@ -3815,7 +3822,7 @@ export class ModelQuery {
|
|
|
3815
3822
|
/** Compile a DML spec with the comment prefix — for a lazy builder's `.toSQL()`. */
|
|
3816
3823
|
#compileDmlSpec(spec) {
|
|
3817
3824
|
const compiled = compileStatementNative(spec, this.#dialect);
|
|
3818
|
-
const sql = this.#commentPrefix() + compiled
|
|
3825
|
+
const sql = this.#commentPrefix() + onlyStatement(compiled);
|
|
3819
3826
|
return { sql, bindings: compiled.params, params: compiled.params };
|
|
3820
3827
|
}
|
|
3821
3828
|
/** Hooks a lazy DML builder delegates back to (upsert clauses are N/A on a model query). */
|
|
@@ -3858,9 +3865,9 @@ export class ModelQuery {
|
|
|
3858
3865
|
async #runDml(spec, returning) {
|
|
3859
3866
|
const compiled = compileStatementNative(spec, this.#dialect);
|
|
3860
3867
|
if (returning && returning.length > 0) {
|
|
3861
|
-
return this.#raceTimeout(this.#db.query(this.#commentPrefix() + compiled
|
|
3868
|
+
return this.#raceTimeout(this.#db.query(this.#commentPrefix() + onlyStatement(compiled), compiled.params, this.#meta("dml")));
|
|
3862
3869
|
}
|
|
3863
|
-
const r = await this.#raceTimeout(this.#db.execute(this.#commentPrefix() + compiled
|
|
3870
|
+
const r = await this.#raceTimeout(this.#db.execute(this.#commentPrefix() + onlyStatement(compiled), compiled.params, this.#meta("dml")));
|
|
3864
3871
|
return r.rowsAffected ?? 0;
|
|
3865
3872
|
}
|
|
3866
3873
|
/**
|
|
@@ -3966,4 +3973,18 @@ export class ModelQuery {
|
|
|
3966
3973
|
_a = ModelQuery;
|
|
3967
3974
|
/** `col as alias` — the Lucid aggregate spelling. */
|
|
3968
3975
|
const ALIASED = /^(.*?)\s+as\s+(\S+)$/i;
|
|
3976
|
+
/**
|
|
3977
|
+
* The single statement a compile produced.
|
|
3978
|
+
*
|
|
3979
|
+
* `compileStatementNative` answers a list because a few specs expand to more
|
|
3980
|
+
* than one; the callers here compile specs that do not, and this is where that
|
|
3981
|
+
* is stated instead of reading index zero as a value that might not be there.
|
|
3982
|
+
*/
|
|
3983
|
+
function onlyStatement(compiled) {
|
|
3984
|
+
const [statement] = compiled.statements;
|
|
3985
|
+
if (statement === undefined) {
|
|
3986
|
+
throw new Error("atlas: the query compiler produced no statement");
|
|
3987
|
+
}
|
|
3988
|
+
return statement;
|
|
3989
|
+
}
|
|
3969
3990
|
//# sourceMappingURL=ModelQuery.js.map
|