turbine-orm 0.34.0 → 0.36.0
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 +18 -16
- package/dist/cjs/cli/index.js +109 -16
- package/dist/cjs/cli/migrate.js +78 -3
- package/dist/cjs/cli/studio-ui.generated.js +1 -1
- package/dist/cjs/cli/studio.js +333 -22
- package/dist/cjs/cli/ui.js +7 -1
- package/dist/cjs/client.js +26 -4
- package/dist/cjs/dialect.js +2 -1
- package/dist/cjs/errors.js +41 -1
- package/dist/cjs/generate.js +23 -2
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/mssql.js +27 -5
- package/dist/cjs/mysql.js +4 -0
- package/dist/cjs/powdb.js +197 -25
- package/dist/cjs/powql.js +515 -51
- package/dist/cjs/query/aggregates.js +683 -0
- package/dist/cjs/query/batched-loader.js +2 -0
- package/dist/cjs/query/builder.js +361 -4508
- package/dist/cjs/query/filters.js +12 -0
- package/dist/cjs/query/relations.js +1698 -0
- package/dist/cjs/query/where-compile.js +180 -0
- package/dist/cjs/query/where.js +1491 -0
- package/dist/cjs/query/writes.js +680 -0
- package/dist/cjs/schema-builder.js +6 -0
- package/dist/cjs/schema-metadata.js +4 -0
- package/dist/cjs/schema-sql.js +265 -3
- package/dist/cjs/sqlite.js +4 -1
- package/dist/cli/index.d.ts +8 -2
- package/dist/cli/index.js +111 -18
- package/dist/cli/migrate.d.ts +24 -1
- package/dist/cli/migrate.js +77 -3
- package/dist/cli/studio-ui.generated.js +1 -1
- package/dist/cli/studio.d.ts +46 -13
- package/dist/cli/studio.js +331 -23
- package/dist/cli/ui.js +7 -1
- package/dist/client.d.ts +32 -5
- package/dist/client.js +26 -4
- package/dist/dialect.d.ts +28 -6
- package/dist/dialect.js +2 -1
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +39 -0
- package/dist/generate.js +23 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mssql.js +27 -5
- package/dist/mysql.js +4 -0
- package/dist/powdb.d.ts +135 -9
- package/dist/powdb.js +197 -25
- package/dist/powql.d.ts +166 -4
- package/dist/powql.js +516 -52
- package/dist/query/aggregates.d.ts +74 -0
- package/dist/query/aggregates.js +641 -0
- package/dist/query/batched-loader.d.ts +6 -0
- package/dist/query/batched-loader.js +2 -0
- package/dist/query/builder.d.ts +98 -830
- package/dist/query/builder.js +366 -4513
- package/dist/query/deferred.d.ts +13 -2
- package/dist/query/filters.d.ts +7 -0
- package/dist/query/filters.js +11 -0
- package/dist/query/relations.d.ts +441 -0
- package/dist/query/relations.js +1627 -0
- package/dist/query/types.d.ts +25 -6
- package/dist/query/where-compile.d.ts +139 -0
- package/dist/query/where-compile.js +175 -0
- package/dist/query/where.d.ts +494 -0
- package/dist/query/where.js +1431 -0
- package/dist/query/writes.d.ts +131 -0
- package/dist/query/writes.js +626 -0
- package/dist/schema-builder.d.ts +18 -3
- package/dist/schema-builder.js +6 -0
- package/dist/schema-metadata.js +4 -0
- package/dist/schema-sql.d.ts +60 -3
- package/dist/schema-sql.js +261 -4
- package/dist/schema.d.ts +10 -0
- package/dist/sqlite.js +4 -1
- package/package.json +4 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* turbine-orm: aggregate / groupBy compilation (extracted from builder.ts)
|
|
3
|
+
*
|
|
4
|
+
* buildAggregate + buildGroupBy and their helpers (HAVING clauses, groupBy
|
|
5
|
+
* ordering, DISTINCT-ON sources, JSON-path aggregate targets). All functions
|
|
6
|
+
* take a {@link BuilderCtx} first argument; WHERE compilation is reused from
|
|
7
|
+
* where.ts (via `whereMod`), and the shared orderBy / row-parse primitives
|
|
8
|
+
* stay class-resident, reached through the ctx. See builder.ts for the thin
|
|
9
|
+
* delegating methods (buildGroupBy / buildAggregate).
|
|
10
|
+
*/
|
|
11
|
+
import type { DeferredQuery } from './deferred.js';
|
|
12
|
+
import type { AggregateArgs, AggregateResult, GroupByArgs, GroupByOrderBy, HavingClause, HavingFilter } from './types.js';
|
|
13
|
+
import type { BuilderCtx } from './where.js';
|
|
14
|
+
export declare function buildGroupBy<T extends object>(qi: BuilderCtx, args: GroupByArgs<T>): DeferredQuery<Record<string, unknown>[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Compile a groupBy `orderBy` into an ORDER BY body. Unlike findMany ORDER BY
|
|
17
|
+
* ({@link buildOrderBy}, which validates keys against the table's physical
|
|
18
|
+
* columns), groupBy ordering targets the columns the RESULT actually
|
|
19
|
+
* contains: plain by-fields, JSON group-key aliases, and requested aggregates
|
|
20
|
+
* (`_count` / `_sum` / `_avg` / `_min` / `_max`). Each key re-emits the exact
|
|
21
|
+
* SELECT expression that produced it (`byOrderExprs` / `aggOrderExprs`),
|
|
22
|
+
* mirroring how HAVING re-emits aggregate expressions, so no dialect ever has
|
|
23
|
+
* to accept a SELECT-alias reference in ORDER BY, and any already-bound
|
|
24
|
+
* JSON-path placeholder is reused verbatim (ORDER BY is the last clause, so
|
|
25
|
+
* no `$n` renumbering). An aggregate key that was not requested, or an unknown
|
|
26
|
+
* by-key, throws {@link ValidationError} E003 listing the valid keys.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildGroupByOrderBy(qi: BuilderCtx, orderBy: GroupByOrderBy, byOrderExprs: Map<string, string>, aggOrderExprs: Map<string, string>): string;
|
|
29
|
+
/**
|
|
30
|
+
* Validate a JSON-path target (group key or aggregate target) in groupBy:
|
|
31
|
+
* the field must resolve to a real json/jsonb column and the path must be a
|
|
32
|
+
* non-empty array of keys/indexes. Returns the resolved snake_case column.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveJsonPathTarget(qi: BuilderCtx, context: string, field: string, path: (string | number)[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Build the `distinctOn` row source for groupBy (PostgreSQL only: other
|
|
37
|
+
* engines throw {@link UnsupportedFeatureError} E017):
|
|
38
|
+
*
|
|
39
|
+
* ```sql
|
|
40
|
+
* (SELECT DISTINCT ON ("c1") * FROM "table"<WHERE> ORDER BY "c1", <orderBy>) AS "table"
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The wrapper is aliased as the table name so every outer expression (group
|
|
44
|
+
* keys, aggregates, HAVING, ORDER BY) is byte-identical to the plain path.
|
|
45
|
+
* `distinctOn.orderBy` is required (it decides which row survives) and
|
|
46
|
+
* supports plain columns, {@link OrderBySpec} nulls, and JSON-path specs;
|
|
47
|
+
* JSON paths push their text[] param here, after the WHERE params.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildDistinctOnSource<T extends object>(qi: BuilderCtx, distinctOn: NonNullable<GroupByArgs<T>['distinctOn']>, whereSql: string, params: unknown[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* Build the SQL fragments for a {@link HavingClause}.
|
|
52
|
+
*
|
|
53
|
+
* Each aggregate expression (`COUNT(*)`, `SUM("col")`, etc.) is constructed
|
|
54
|
+
* from a **schema-validated, quoted** column identifier: `qi.toColumn()`
|
|
55
|
+
* throws {@link ValidationError} for unknown fields and `qi.q()` quotes via
|
|
56
|
+
* the dialect, so no unvalidated identifier ever reaches the SQL string. Every
|
|
57
|
+
* comparison value is pushed onto the shared `params` array and referenced by
|
|
58
|
+
* a `$N` placeholder via {@link buildHavingNumericClauses} — there is no string
|
|
59
|
+
* interpolation of user values.
|
|
60
|
+
*
|
|
61
|
+
* `jsonAggExprs` (from {@link buildGroupBy}) maps `alias:aggKey` to the
|
|
62
|
+
* exact aggregate expression a JSON-path aggregate emitted in SELECT
|
|
63
|
+
* (including its already-bound path placeholder), so HAVING on a JSON-path
|
|
64
|
+
* aggregate alias reuses the same expression instead of resolving the alias
|
|
65
|
+
* as a column.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildHavingClauses<T extends object>(qi: BuilderCtx, having: HavingClause<T>, params: unknown[], jsonAggExprs?: Map<string, string>): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Convert a single having filter into one or more parameterized SQL
|
|
70
|
+
* comparisons against the given aggregate expression. A bare number is
|
|
71
|
+
* shorthand for equality. Unknown operator keys throw {@link ValidationError}.
|
|
72
|
+
*/
|
|
73
|
+
export declare function buildHavingNumericClauses(qi: BuilderCtx, expr: string, filter: HavingFilter, params: unknown[]): string[];
|
|
74
|
+
export declare function buildAggregate<T extends object>(qi: BuilderCtx, args: AggregateArgs<T>): DeferredQuery<AggregateResult<T>>;
|