neoorm 0.4.7 → 0.5.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 +6 -6
- package/dist/codegen/emit-includes.d.ts.map +1 -1
- package/dist/codegen/emit-includes.js +3 -1
- package/dist/codegen/emit-includes.js.map +1 -1
- package/dist/dialect/postgres.d.ts.map +1 -1
- package/dist/dialect/postgres.js +8 -4
- package/dist/dialect/postgres.js.map +1 -1
- package/dist/dialect/sqlite.d.ts.map +1 -1
- package/dist/dialect/sqlite.js +14 -4
- package/dist/dialect/sqlite.js.map +1 -1
- package/dist/dialect/types.d.ts +4 -1
- package/dist/dialect/types.d.ts.map +1 -1
- package/dist/plugins/builtin.d.ts +6 -2
- package/dist/plugins/builtin.d.ts.map +1 -1
- package/dist/plugins/builtin.js.map +1 -1
- package/dist/runtime/client.d.ts +44 -6
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +13 -10
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/query/aggregate.d.ts +3 -1
- package/dist/runtime/query/aggregate.d.ts.map +1 -1
- package/dist/runtime/query/aggregate.js +19 -5
- package/dist/runtime/query/aggregate.js.map +1 -1
- package/dist/runtime/query/compile.d.ts +49 -10
- package/dist/runtime/query/compile.d.ts.map +1 -1
- package/dist/runtime/query/compile.js +666 -68
- package/dist/runtime/query/compile.js.map +1 -1
- package/dist/runtime/query/count.d.ts +10 -2
- package/dist/runtime/query/count.d.ts.map +1 -1
- package/dist/runtime/query/count.js +39 -3
- package/dist/runtime/query/count.js.map +1 -1
- package/dist/runtime/query/create.d.ts +2 -0
- package/dist/runtime/query/create.d.ts.map +1 -1
- package/dist/runtime/query/create.js +7 -4
- package/dist/runtime/query/create.js.map +1 -1
- package/dist/runtime/query/cursor.d.ts +2 -1
- package/dist/runtime/query/cursor.d.ts.map +1 -1
- package/dist/runtime/query/cursor.js +21 -2
- package/dist/runtime/query/cursor.js.map +1 -1
- package/dist/runtime/query/delete.d.ts +3 -0
- package/dist/runtime/query/delete.d.ts.map +1 -1
- package/dist/runtime/query/delete.js +18 -3
- package/dist/runtime/query/delete.js.map +1 -1
- package/dist/runtime/query/find-or-create.d.ts.map +1 -1
- package/dist/runtime/query/find-or-create.js +3 -3
- package/dist/runtime/query/find-or-create.js.map +1 -1
- package/dist/runtime/query/find.d.ts +17 -9
- package/dist/runtime/query/find.d.ts.map +1 -1
- package/dist/runtime/query/find.js +118 -53
- package/dist/runtime/query/find.js.map +1 -1
- package/dist/runtime/query/group-by.d.ts +23 -0
- package/dist/runtime/query/group-by.d.ts.map +1 -0
- package/dist/runtime/query/group-by.js +54 -0
- package/dist/runtime/query/group-by.js.map +1 -0
- package/dist/runtime/query/paginate.d.ts +3 -0
- package/dist/runtime/query/paginate.d.ts.map +1 -1
- package/dist/runtime/query/paginate.js +34 -12
- package/dist/runtime/query/paginate.js.map +1 -1
- package/dist/runtime/query/projection.d.ts +19 -0
- package/dist/runtime/query/projection.d.ts.map +1 -0
- package/dist/runtime/query/projection.js +125 -0
- package/dist/runtime/query/projection.js.map +1 -0
- package/dist/runtime/query/relation-planner.d.ts +15 -5
- package/dist/runtime/query/relation-planner.d.ts.map +1 -1
- package/dist/runtime/query/relation-planner.js +103 -43
- package/dist/runtime/query/relation-planner.js.map +1 -1
- package/dist/runtime/query/table-index.d.ts +1 -0
- package/dist/runtime/query/table-index.d.ts.map +1 -1
- package/dist/runtime/query/table-index.js +1 -0
- package/dist/runtime/query/table-index.js.map +1 -1
- package/dist/runtime/query/update.d.ts +4 -0
- package/dist/runtime/query/update.d.ts.map +1 -1
- package/dist/runtime/query/update.js +55 -25
- package/dist/runtime/query/update.js.map +1 -1
- package/dist/runtime/query/upsert.d.ts.map +1 -1
- package/dist/runtime/query/upsert.js +8 -9
- package/dist/runtime/query/upsert.js.map +1 -1
- package/dist/runtime/types.d.ts +23 -11
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/schema/column-where.d.ts +3 -0
- package/dist/schema/column-where.d.ts.map +1 -1
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/relation-types.d.ts +17 -8
- package/dist/schema/relation-types.d.ts.map +1 -1
- package/dist/schema/types.d.ts +117 -16
- package/dist/schema/types.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { postgresDialect } from "../../dialect/postgres.js";
|
|
2
|
-
import { buildDeleteManyQuery, buildDeleteQuery, compileWhere, getCachedDeleteManyQuery, getCachedWhereClause, isImpossibleWhere, mapRowToTs, } from "./compile.js";
|
|
3
|
-
import { runExecute, runQueryOne } from "./execute.js";
|
|
2
|
+
import { buildDeleteManyQuery, buildDeleteQuery, buildSelectColumns, compileWhere, getCachedDeleteManyQuery, getCachedWhereClause, isImpossibleWhere, mapRowToTs, mapRowsToTs, } from "./compile.js";
|
|
3
|
+
import { runExecute, runQuery, runQueryOne, } from "./execute.js";
|
|
4
4
|
import { loadRelations } from "./find.js";
|
|
5
5
|
import { resolvePkWhere } from "./primary-key.js";
|
|
6
6
|
import { getTableIndex } from "./table-index.js";
|
|
@@ -38,7 +38,7 @@ export async function deleteManyRecords(executor, runtime, tableAccessor, args)
|
|
|
38
38
|
const table = manifest.tables[tableAccessor];
|
|
39
39
|
if (!table)
|
|
40
40
|
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
41
|
-
const { sql: whereSql, params, impossible } = getCachedWhereClause(manifest, table, args?.where, dialect, 1, runtime.tableIndex);
|
|
41
|
+
const { sql: whereSql, params, impossible, } = getCachedWhereClause(manifest, table, args?.where, dialect, 1, runtime.tableIndex);
|
|
42
42
|
if (impossible || isImpossibleWhere(whereSql)) {
|
|
43
43
|
return 0;
|
|
44
44
|
}
|
|
@@ -47,6 +47,21 @@ export async function deleteManyRecords(executor, runtime, tableAccessor, args)
|
|
|
47
47
|
const { rowCount } = await runExecute(executor, runtime, { operation: "delete", tableAccessor }, query, params);
|
|
48
48
|
return rowCount;
|
|
49
49
|
}
|
|
50
|
+
export async function deleteManyAndReturnRecords(executor, runtime, tableAccessor, args) {
|
|
51
|
+
const dialect = runtime.dialect ?? postgresDialect;
|
|
52
|
+
const { manifest } = runtime;
|
|
53
|
+
const table = manifest.tables[tableAccessor];
|
|
54
|
+
if (!table)
|
|
55
|
+
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
56
|
+
const { sql: whereSql, params, impossible, } = getCachedWhereClause(manifest, table, args?.where, dialect, 1, runtime.tableIndex);
|
|
57
|
+
if (impossible || isImpossibleWhere(whereSql)) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
61
|
+
const query = getCachedDeleteManyQuery(tableIndex, table, whereSql);
|
|
62
|
+
const rows = await runQuery(executor, runtime, { operation: "delete", tableAccessor }, `${query} RETURNING ${buildSelectColumns(table, undefined, runtime.tableIndex)}`, params);
|
|
63
|
+
return mapRowsToTs(tableIndex, table, rows);
|
|
64
|
+
}
|
|
50
65
|
export async function deleteById(executor, runtime, tableAccessor, id) {
|
|
51
66
|
const { manifest } = runtime;
|
|
52
67
|
const table = manifest.tables[tableAccessor];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/runtime/query/delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/runtime/query/delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EA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c,CAAC;
|
|
1
|
+
{"version":3,"file":"find-or-create.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/find-or-create.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS/C,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,cAAc,CAAC;AAC9D,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAKpE,MAAM,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,YAAY,EACrB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE;IACL,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACjC,GACC,OAAO,CAAC,kBAAkB,CAAC,CAkF7B;AA+DD,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,YAAY,EACrB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE;IACL,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,GACC,OAAO,CAAC,MAAM,CAAC,CASjB"}
|
|
@@ -2,9 +2,9 @@ import { postgresDialect } from "../../dialect/postgres.js";
|
|
|
2
2
|
import { buildFindOrCreateQuery, compileWhere, dataToSqlValues, FIND_OR_CREATE_FLAG, mapRowToTs, } from "./compile.js";
|
|
3
3
|
import { runCreate } from "./create.js";
|
|
4
4
|
import { runQueryOne } from "./execute.js";
|
|
5
|
-
import { getTableIndex } from "./table-index.js";
|
|
6
5
|
import { findMany, loadRelations } from "./find.js";
|
|
7
6
|
import { fillMissingPrimaryKeys, rowScalarPkValue } from "./primary-key.js";
|
|
7
|
+
import { getTableIndex } from "./table-index.js";
|
|
8
8
|
import { assertUniqueWhere } from "./unique.js";
|
|
9
9
|
export async function findOrCreateRecord(executor, runtime, tableAccessor, args) {
|
|
10
10
|
const dialect = runtime.dialect ?? postgresDialect;
|
|
@@ -47,7 +47,7 @@ async function findOrCreateSqlite(executor, runtime, tableAccessor, args, create
|
|
|
47
47
|
};
|
|
48
48
|
const existing = await findMany(executor, runtime, tableAccessor, {
|
|
49
49
|
where: args.where,
|
|
50
|
-
|
|
50
|
+
take: 1,
|
|
51
51
|
});
|
|
52
52
|
if (existing.length > 0) {
|
|
53
53
|
const existingRow = existing[0];
|
|
@@ -65,7 +65,7 @@ async function findOrCreateSqlite(executor, runtime, tableAccessor, args, create
|
|
|
65
65
|
catch {
|
|
66
66
|
const retry = await findMany(executor, runtime, tableAccessor, {
|
|
67
67
|
where: args.where,
|
|
68
|
-
|
|
68
|
+
take: 1,
|
|
69
69
|
});
|
|
70
70
|
if (retry.length > 0) {
|
|
71
71
|
const retryRow = retry[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-or-create.js","sourceRoot":"","sources":["../../../src/runtime/query/find-or-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EACN,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,UAAU,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAqB,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"find-or-create.js","sourceRoot":"","sources":["../../../src/runtime/query/find-or-create.ts"],"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CAAC,kBAAkB,aAAa,EAAE,CAAC,CAAC;QAC/D,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -5,8 +5,10 @@ import { type QueryRuntime } from "./execute.js";
|
|
|
5
5
|
import { type RelationLoadPlan } from "./relation-planner.js";
|
|
6
6
|
type RelationSpec = {
|
|
7
7
|
select?: readonly string[] | Record<string, boolean | undefined>;
|
|
8
|
+
where?: Record<string, unknown>;
|
|
8
9
|
orderBy?: OrderByInput;
|
|
9
|
-
|
|
10
|
+
take?: number;
|
|
11
|
+
skip?: number;
|
|
10
12
|
with?: Record<string, WithInput>;
|
|
11
13
|
};
|
|
12
14
|
export type WithInput = boolean | RelationSpec | {
|
|
@@ -15,18 +17,24 @@ export type WithInput = boolean | RelationSpec | {
|
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
export declare function hydrateAndLoadRelations(executor: Executor, runtime: QueryRuntime, table: ManifestTable, rawRows: Record<string, unknown>[], withSpec: Record<string, WithInput> | undefined, plan?: RelationLoadPlan): Promise<Record<string, unknown>[]>;
|
|
18
|
-
|
|
19
|
-
export declare function findMany(executor: Executor, runtime: QueryRuntime, tableAccessor: string, args?: {
|
|
20
|
+
type FindManyArgs = {
|
|
20
21
|
where?: Record<string, unknown>;
|
|
21
22
|
orderBy?: OrderByInput;
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
take?: number;
|
|
24
|
+
skip?: number;
|
|
24
25
|
distinct?: readonly string[] | Record<string, boolean | undefined>;
|
|
26
|
+
select?: readonly string[] | Record<string, boolean | undefined>;
|
|
27
|
+
omit?: readonly string[] | Record<string, boolean | undefined>;
|
|
25
28
|
with?: Record<string, WithInput>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
};
|
|
30
|
+
type FindByIdArgs = {
|
|
31
|
+
select?: readonly string[] | Record<string, boolean | undefined>;
|
|
32
|
+
omit?: readonly string[] | Record<string, boolean | undefined>;
|
|
29
33
|
with?: Record<string, WithInput>;
|
|
30
|
-
}
|
|
34
|
+
};
|
|
35
|
+
export declare function loadRelations(executor: Executor, runtime: QueryRuntime, table: ManifestTable, rows: Record<string, unknown>[], withSpec: Record<string, WithInput> | undefined): Promise<Record<string, unknown>[]>;
|
|
36
|
+
export declare function findMany(executor: Executor, runtime: QueryRuntime, tableAccessor: string, args?: FindManyArgs): Promise<Record<string, unknown>[]>;
|
|
37
|
+
export declare function findFirst(executor: Executor, runtime: QueryRuntime, tableAccessor: string, args?: Parameters<typeof findMany>[3]): Promise<Record<string, unknown> | null>;
|
|
38
|
+
export declare function findById(executor: Executor, runtime: QueryRuntime, tableAccessor: string, id: string | Record<string, unknown>, args?: FindByIdArgs): Promise<Record<string, unknown> | null>;
|
|
31
39
|
export {};
|
|
32
40
|
//# sourceMappingURL=find.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/find.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGX,aAAa,EACb,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/runtime/query/find.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGX,aAAa,EACb,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAcN,KAAK,YAAY,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,cAAc,CAAC;AAgBxE,OAAO,EAQN,KAAK,gBAAgB,EAGrB,MAAM,uBAAuB,CAAC;AAG/B,KAAK,YAAY,GAAG;IACnB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;IACjE,KAAK,CAAC,E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EAAE,YAAY,EACrB,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,IAAI,CAAC,EAAE,YAAY,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAyIzC"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { postgresDialect, quoteIdentifier, tableRef, } from "../../dialect/postgres.js";
|
|
2
|
-
import { buildFindByIdQuery, buildFindManyQuery, buildSelectColumns, compileOrderBy, compileWhere, getCachedFindManyQuery, getCachedOrderByClause, getCachedWhereClause, isImpossibleWhere, mapRowToTs, mapRowsToTs, normalizeLimitOffset, normalizeSelectColumns, } from "./compile.js";
|
|
3
2
|
import { rebaseParamRefs } from "../../sql/template.js";
|
|
3
|
+
import { buildFindByIdQuery, buildFindManyQuery, buildSelectColumns, compileOrderBy, compileWhere, getCachedFindManyQuery, getCachedOrderByClause, getCachedWhereClause, isImpossibleWhere, mapRowsToTs, mapRowToTs, normalizeLimitOffset, normalizeSelectColumns, } from "./compile.js";
|
|
4
4
|
import { runQuery, runQueryOne } from "./execute.js";
|
|
5
|
-
import { findM2M, findRelation, tableOwnsFkColumn
|
|
5
|
+
import { findM2M, findRelation, tableOwnsFkColumn } from "./manifest-lookup.js";
|
|
6
6
|
import { primaryKeyTsNames, requireScalarPrimaryKey, resolvePkWhere, rowPkKey, targetRelationPkSql, } from "./primary-key.js";
|
|
7
|
-
import {
|
|
7
|
+
import { projectFindRow, projectFindRows, projectionSignature, resolveParentProjection, } from "./projection.js";
|
|
8
8
|
import { buildCountAggregateGroupBy, buildPlanExtraSelectCols, compileCountOrderBy, getCachedFindByIdWithQuery, getCachedRelationPlan, hydrateRowsWithPlan, planRelationLoad, withShapeSignature, } from "./relation-planner.js";
|
|
9
|
+
import { columnBySqlName, getTableIndex } from "./table-index.js";
|
|
9
10
|
function isRelationSpec(withSpec) {
|
|
10
11
|
if (typeof withSpec !== "object" || withSpec === null)
|
|
11
12
|
return false;
|
|
12
13
|
return ("select" in withSpec ||
|
|
14
|
+
"where" in withSpec ||
|
|
13
15
|
"orderBy" in withSpec ||
|
|
14
|
-
"
|
|
16
|
+
"take" in withSpec ||
|
|
17
|
+
"skip" in withSpec ||
|
|
15
18
|
"with" in withSpec);
|
|
16
19
|
}
|
|
17
20
|
function validateDistinctOrderBy(distinct, orderBy) {
|
|
@@ -44,6 +47,20 @@ function splitWithSpec(withSpec) {
|
|
|
44
47
|
result.countSpec = countSpec;
|
|
45
48
|
return result;
|
|
46
49
|
}
|
|
50
|
+
function compileBatchedRelationWhere(runtime, targetTable, whereFilter, parentIdCount, tableAlias) {
|
|
51
|
+
if (!whereFilter || Object.keys(whereFilter).length === 0) {
|
|
52
|
+
return { extraWhere: "", extraParams: [] };
|
|
53
|
+
}
|
|
54
|
+
const dialect = runtime.dialect ?? postgresDialect;
|
|
55
|
+
const compiled = compileWhere(runtime.manifest, targetTable, whereFilter, dialect, 1, runtime.tableIndex, false, tableAlias);
|
|
56
|
+
if (!compiled.sql)
|
|
57
|
+
return { extraWhere: "", extraParams: [] };
|
|
58
|
+
const adjusted = rebaseParamRefs(compiled.sql, parentIdCount);
|
|
59
|
+
return {
|
|
60
|
+
extraWhere: ` AND ${adjusted.replace(/^WHERE\s+/i, "")}`,
|
|
61
|
+
extraParams: compiled.params,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
47
64
|
async function loadRelationCounts(executor, runtime, parentTable, parentRows, countSpec) {
|
|
48
65
|
if (parentRows.length === 0)
|
|
49
66
|
return;
|
|
@@ -57,7 +74,8 @@ async function loadRelationCounts(executor, runtime, parentTable, parentRows, co
|
|
|
57
74
|
const counts = await countRelationLinks(executor, runtime, parentTable, relationName, parentIds, whereFilter);
|
|
58
75
|
for (const parent of parentRows) {
|
|
59
76
|
const parentKey = rowPkKey(parent, parentTable);
|
|
60
|
-
const bucket = parent["_count"] ??
|
|
77
|
+
const bucket = parent["_count"] ??
|
|
78
|
+
{};
|
|
61
79
|
bucket[relationName] = counts.get(parentKey) ?? 0;
|
|
62
80
|
parent["_count"] = bucket;
|
|
63
81
|
}
|
|
@@ -164,7 +182,8 @@ async function loadOneRelation(executor, runtime, parentTable, parentRows, relat
|
|
|
164
182
|
if (!targetPkTsName) {
|
|
165
183
|
throw new Error(`No primary key defined for table "${targetTable.accessor}"`);
|
|
166
184
|
}
|
|
167
|
-
const
|
|
185
|
+
const { extraWhere, extraParams } = compileBatchedRelationWhere(runtime, targetTable, nestedSpec?.where, fkValues.length);
|
|
186
|
+
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor: targetTable.accessor }, `SELECT ${selectCols} FROM ${tableRef(targetTable)} WHERE ${targetPkCol} IN (${placeholders})${extraWhere}`, [...fkValues, ...extraParams]);
|
|
168
187
|
const targetTableIndex = getTableIndex(runtime.tableIndex, targetTable.accessor);
|
|
169
188
|
const mapped = mapRowsToTs(targetTableIndex, targetTable, rows);
|
|
170
189
|
const byId = new Map(mapped.map((r) => [String(r[targetPkTsName]), r]));
|
|
@@ -179,13 +198,18 @@ async function loadOneRelation(executor, runtime, parentTable, parentRows, relat
|
|
|
179
198
|
const placeholders = parentIds.map((_, i) => `$${i + 1}`).join(", ");
|
|
180
199
|
const selectCols = columnsForSelect(targetTable, withSpec);
|
|
181
200
|
let sql = `SELECT ${selectCols} FROM ${tableRef(targetTable)} WHERE ${fkCol} IN (${placeholders})`;
|
|
201
|
+
const { extraWhere, extraParams } = compileBatchedRelationWhere(runtime, targetTable, nestedSpec?.where, parentIds.length);
|
|
202
|
+
sql += extraWhere;
|
|
182
203
|
if (nestedSpec?.orderBy) {
|
|
183
204
|
sql += ` ${compileOrderBy(targetTable, nestedSpec.orderBy, undefined, runtime.tableIndex)}`;
|
|
184
205
|
}
|
|
185
|
-
if (nestedSpec?.
|
|
186
|
-
sql += ` LIMIT ${normalizeLimitOffset(nestedSpec.
|
|
206
|
+
if (nestedSpec?.take !== undefined) {
|
|
207
|
+
sql += ` LIMIT ${normalizeLimitOffset(nestedSpec.take, "take")}`;
|
|
208
|
+
}
|
|
209
|
+
if (nestedSpec?.skip !== undefined) {
|
|
210
|
+
sql += ` OFFSET ${normalizeLimitOffset(nestedSpec.skip, "skip")}`;
|
|
187
211
|
}
|
|
188
|
-
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor: targetTable.accessor }, sql, parentIds);
|
|
212
|
+
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor: targetTable.accessor }, sql, [...parentIds, ...extraParams]);
|
|
189
213
|
const targetTableIndex = getTableIndex(runtime.tableIndex, targetTable.accessor);
|
|
190
214
|
const mapped = mapRowsToTs(targetTableIndex, targetTable, rows);
|
|
191
215
|
const fkTargetCol = columnBySqlName(targetTableIndex, targetTable, relation.fkSqlColumn);
|
|
@@ -221,7 +245,7 @@ async function loadOneRelation(executor, runtime, parentTable, parentRows, relat
|
|
|
221
245
|
await loadNestedRelations(executor, runtime, targetTable, childRows, nestedSpec.with);
|
|
222
246
|
}
|
|
223
247
|
}
|
|
224
|
-
async function loadM2MRelation(executor, runtime, parentTable, parentRows, m2m, relationName,
|
|
248
|
+
async function loadM2MRelation(executor, runtime, parentTable, parentRows, m2m, relationName, withSpec) {
|
|
225
249
|
const { manifest } = runtime;
|
|
226
250
|
const isLeft = m2m.leftAccessor === parentTable.accessor;
|
|
227
251
|
const targetAccessor = isLeft ? m2m.rightAccessor : m2m.leftAccessor;
|
|
@@ -237,17 +261,28 @@ async function loadM2MRelation(executor, runtime, parentTable, parentRows, m2m,
|
|
|
237
261
|
if (parentIds.length === 0)
|
|
238
262
|
return;
|
|
239
263
|
const placeholders = parentIds.map((_, i) => `$${i + 1}`).join(", ");
|
|
264
|
+
const nestedSpec = isRelationSpec(withSpec) ? withSpec : undefined;
|
|
240
265
|
const selectCols = targetTable.columns
|
|
241
|
-
.map((c) => quoteIdentifier(c.sqlName))
|
|
266
|
+
.map((c) => `t.${quoteIdentifier(c.sqlName)}`)
|
|
242
267
|
.join(", ");
|
|
243
268
|
const targetPkCol = quoteIdentifier(targetRelationPkSql(targetTable));
|
|
244
|
-
const
|
|
245
|
-
|
|
269
|
+
const { extraWhere, extraParams } = compileBatchedRelationWhere(runtime, targetTable, nestedSpec?.where, parentIds.length, "t");
|
|
270
|
+
let sql = `
|
|
271
|
+
SELECT ${selectCols}, j.${quoteIdentifier(parentFkCol)} AS _parent_id
|
|
246
272
|
FROM ${tableRef(throughTable)} j
|
|
247
273
|
JOIN ${tableRef(targetTable)} t ON t.${targetPkCol} = j.${quoteIdentifier(targetFkCol)}
|
|
248
|
-
WHERE j.${quoteIdentifier(parentFkCol)} IN (${placeholders})
|
|
274
|
+
WHERE j.${quoteIdentifier(parentFkCol)} IN (${placeholders})${extraWhere}
|
|
249
275
|
`.trim();
|
|
250
|
-
|
|
276
|
+
if (nestedSpec?.orderBy) {
|
|
277
|
+
sql += ` ${compileOrderBy(targetTable, nestedSpec.orderBy, "t", runtime.tableIndex)}`;
|
|
278
|
+
}
|
|
279
|
+
if (nestedSpec?.take !== undefined) {
|
|
280
|
+
sql += ` LIMIT ${normalizeLimitOffset(nestedSpec.take, "take")}`;
|
|
281
|
+
}
|
|
282
|
+
if (nestedSpec?.skip !== undefined) {
|
|
283
|
+
sql += ` OFFSET ${normalizeLimitOffset(nestedSpec.skip, "skip")}`;
|
|
284
|
+
}
|
|
285
|
+
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor: targetTable.accessor }, sql, [...parentIds, ...extraParams]);
|
|
251
286
|
const targetTableIndex = getTableIndex(runtime.tableIndex, targetTable.accessor);
|
|
252
287
|
const grouped = new Map();
|
|
253
288
|
for (const row of rows) {
|
|
@@ -285,7 +320,7 @@ export async function hydrateAndLoadRelations(executor, runtime, table, rawRows,
|
|
|
285
320
|
}
|
|
286
321
|
return resultRows;
|
|
287
322
|
}
|
|
288
|
-
async function executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, args, whereSql, params, planOptions) {
|
|
323
|
+
async function executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, args, whereSql, params, planOptions, projection) {
|
|
289
324
|
const dialect = runtime.dialect ?? postgresDialect;
|
|
290
325
|
const { manifest } = runtime;
|
|
291
326
|
const plan = getCachedRelationPlan(manifest, table, args.with, dialect, runtime.tableIndex, planOptions);
|
|
@@ -298,7 +333,8 @@ async function executeFindManyWithRelations(executor, runtime, tableAccessor, ta
|
|
|
298
333
|
whereSql = qualifiedWhere.sql;
|
|
299
334
|
params = qualifiedWhere.params;
|
|
300
335
|
}
|
|
301
|
-
const
|
|
336
|
+
const extraSelect = buildPlanExtraSelectCols(manifest, table, plan, dialect, runtime.tableIndex, params.length + 1);
|
|
337
|
+
const extraSelectCols = extraSelect.cols;
|
|
302
338
|
const countOrderSql = compileCountOrderBy(manifest, table, args.orderBy, plan, runtime.tableIndex);
|
|
303
339
|
const orderSqlForWith = countOrderSql ||
|
|
304
340
|
getCachedOrderByClause(table, args.orderBy, needsQualifiedRefs ? table.sqlName : undefined, runtime.tableIndex);
|
|
@@ -316,10 +352,12 @@ async function executeFindManyWithRelations(executor, runtime, tableAccessor, ta
|
|
|
316
352
|
}
|
|
317
353
|
const withSignature = withShapeSignature(args.with);
|
|
318
354
|
const planMode = planOptions?.useHasManyAggregate === false ? "corr" : "agg";
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
const
|
|
322
|
-
|
|
355
|
+
const projSig = projectionSignature(projection?.sqlColumns);
|
|
356
|
+
const signature = `${whereSql}|${orderSqlForWith}|${args.take ?? ""}|${args.skip ?? ""}|${distinctOn?.join(",") ?? ""}|${withSignature}|${planMode}|${groupBySql}|${projSig}`;
|
|
357
|
+
const query = getCachedFindManyQuery(tableIndex, signature, () => buildFindManyQuery(table, whereSql, orderSqlForWith, args.take, args.skip, distinctOn, extraSelectCols.length > 0 ? extraSelectCols : undefined, joinClauses, runtime.tableIndex, groupBySql || undefined, projection?.sqlColumns));
|
|
358
|
+
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor }, query, [...params, ...extraSelect.params]);
|
|
359
|
+
const hydrated = await hydrateAndLoadRelations(executor, runtime, table, rows, args.with, plan);
|
|
360
|
+
return projectFindRows(hydrated, projection, args.with);
|
|
323
361
|
}
|
|
324
362
|
export async function loadRelations(executor, runtime, table, rows, withSpec) {
|
|
325
363
|
if (!withSpec || rows.length === 0)
|
|
@@ -339,12 +377,14 @@ export async function findMany(executor, runtime, tableAccessor, args) {
|
|
|
339
377
|
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
340
378
|
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
341
379
|
const queryCtx = { operation: "select", tableAccessor };
|
|
380
|
+
const projection = resolveParentProjection(table, args, tableIndex);
|
|
342
381
|
const isSimpleFind = !args?.where &&
|
|
343
382
|
!args?.orderBy &&
|
|
344
383
|
!args?.with &&
|
|
345
384
|
!args?.distinct &&
|
|
346
|
-
|
|
347
|
-
args?.
|
|
385
|
+
!projection.hasProjection &&
|
|
386
|
+
args?.take === undefined &&
|
|
387
|
+
args?.skip === undefined;
|
|
348
388
|
if (isSimpleFind && tableIndex) {
|
|
349
389
|
const rows = await runQuery(executor, runtime, queryCtx, tableIndex.findAllSql, []);
|
|
350
390
|
return mapRowsToTs(tableIndex, table, rows);
|
|
@@ -358,53 +398,51 @@ export async function findMany(executor, runtime, tableAccessor, args) {
|
|
|
358
398
|
if (compiledWhere.impossible || isImpossibleWhere(compiledWhere.sql)) {
|
|
359
399
|
return [];
|
|
360
400
|
}
|
|
361
|
-
|
|
362
|
-
|
|
401
|
+
const whereSql = compiledWhere.sql;
|
|
402
|
+
const params = compiledWhere.params;
|
|
363
403
|
const hasWith = Boolean(args?.with && Object.keys(args.with).length > 0);
|
|
364
404
|
if (!hasWith) {
|
|
365
405
|
const orderSql = getCachedOrderByClause(table, args?.orderBy, undefined, runtime.tableIndex);
|
|
366
|
-
const
|
|
367
|
-
const
|
|
406
|
+
const projSig = projectionSignature(projection.sqlColumns);
|
|
407
|
+
const signature = `${whereSql}|${orderSql}|${args?.take ?? ""}|${args?.skip ?? ""}|${distinctOn?.join(",") ?? ""}|${projSig}`;
|
|
408
|
+
const query = getCachedFindManyQuery(tableIndex, signature, () => buildFindManyQuery(table, whereSql, orderSql, args?.take, args?.skip, distinctOn, undefined, undefined, runtime.tableIndex, undefined, projection.sqlColumns));
|
|
368
409
|
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor }, query, params);
|
|
369
|
-
return mapRowsToTs(tableIndex, table, rows);
|
|
410
|
+
return projectFindRows(mapRowsToTs(tableIndex, table, rows), projection);
|
|
370
411
|
}
|
|
371
|
-
return executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, { ...(args ?? {}), with: args.with }, whereSql, params, { useHasManyAggregate: true });
|
|
412
|
+
return executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, { ...(args ?? {}), with: args.with }, whereSql, params, { useHasManyAggregate: true }, projection);
|
|
372
413
|
}
|
|
373
414
|
export async function findFirst(executor, runtime, tableAccessor, args) {
|
|
374
415
|
const dialect = runtime.dialect ?? postgresDialect;
|
|
416
|
+
const { manifest } = runtime;
|
|
417
|
+
const table = manifest.tables[tableAccessor];
|
|
418
|
+
if (!table)
|
|
419
|
+
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
420
|
+
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
421
|
+
const projection = resolveParentProjection(table, args, tableIndex);
|
|
375
422
|
const hasWith = Boolean(args?.with && Object.keys(args.with).length > 0);
|
|
376
|
-
const canFastPath = !hasWith && !args?.distinct && args?.
|
|
423
|
+
const canFastPath = !hasWith && !args?.distinct && args?.skip === undefined;
|
|
377
424
|
if (canFastPath) {
|
|
378
|
-
const { manifest } = runtime;
|
|
379
|
-
const table = manifest.tables[tableAccessor];
|
|
380
|
-
if (!table)
|
|
381
|
-
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
382
|
-
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
383
425
|
const compiledWhere = getCachedWhereClause(manifest, table, args?.where, dialect, 1, runtime.tableIndex);
|
|
384
426
|
if (compiledWhere.impossible || isImpossibleWhere(compiledWhere.sql)) {
|
|
385
427
|
return null;
|
|
386
428
|
}
|
|
387
429
|
const { sql: whereSql, params } = compiledWhere;
|
|
388
430
|
const orderSql = getCachedOrderByClause(table, args?.orderBy, undefined, runtime.tableIndex);
|
|
389
|
-
const
|
|
390
|
-
const
|
|
431
|
+
const projSig = projectionSignature(projection.sqlColumns);
|
|
432
|
+
const signature = `${whereSql}|${orderSql}|1|||${projSig}`;
|
|
433
|
+
const query = getCachedFindManyQuery(tableIndex, signature, () => buildFindManyQuery(table, whereSql, orderSql, 1, undefined, undefined, undefined, undefined, runtime.tableIndex, undefined, projection.sqlColumns));
|
|
391
434
|
const rows = await runQuery(executor, runtime, { operation: "select", tableAccessor }, query, params);
|
|
392
435
|
if (rows.length === 0)
|
|
393
436
|
return null;
|
|
394
|
-
return mapRowToTs(tableIndex, table, rows[0]);
|
|
437
|
+
return projectFindRow(mapRowToTs(tableIndex, table, rows[0]), projection);
|
|
395
438
|
}
|
|
396
|
-
const { manifest } = runtime;
|
|
397
|
-
const table = manifest.tables[tableAccessor];
|
|
398
|
-
if (!table)
|
|
399
|
-
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
400
|
-
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
401
439
|
const compiledWhere = getCachedWhereClause(manifest, table, args?.where, dialect, 1, runtime.tableIndex);
|
|
402
440
|
if (compiledWhere.impossible || isImpossibleWhere(compiledWhere.sql)) {
|
|
403
441
|
return null;
|
|
404
442
|
}
|
|
405
443
|
const distinctOn = normalizeSelectColumns(args?.distinct);
|
|
406
444
|
validateDistinctOrderBy(distinctOn, args?.orderBy);
|
|
407
|
-
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, { ...args, with: args.with,
|
|
445
|
+
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, { ...args, with: args.with, take: 1 }, compiledWhere.sql, compiledWhere.params, { useHasManyAggregate: false }, projection);
|
|
408
446
|
return rows[0] ?? null;
|
|
409
447
|
}
|
|
410
448
|
function extractScalarPkValue(table, id) {
|
|
@@ -419,43 +457,70 @@ export async function findById(executor, runtime, tableAccessor, id, args) {
|
|
|
419
457
|
if (!table)
|
|
420
458
|
throw new Error(`Unknown table: ${tableAccessor}`);
|
|
421
459
|
const tableIndex = getTableIndex(runtime.tableIndex, tableAccessor);
|
|
460
|
+
const projection = resolveParentProjection(table, args, tableIndex);
|
|
422
461
|
if (table.primaryKey.length !== 1) {
|
|
423
462
|
const where = resolvePkWhere(table, id);
|
|
424
463
|
if (args?.with) {
|
|
425
464
|
const compiledWhere = getCachedWhereClause(manifest, table, where, dialect, 1, runtime.tableIndex);
|
|
426
|
-
if (compiledWhere.impossible ||
|
|
465
|
+
if (compiledWhere.impossible ||
|
|
466
|
+
isImpossibleWhere(compiledWhere.sql)) {
|
|
427
467
|
return null;
|
|
428
468
|
}
|
|
429
|
-
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, {
|
|
469
|
+
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, {
|
|
470
|
+
where,
|
|
471
|
+
take: 1,
|
|
472
|
+
with: args.with,
|
|
473
|
+
...(args.select !== undefined
|
|
474
|
+
? { select: args.select }
|
|
475
|
+
: {}),
|
|
476
|
+
...(args.omit !== undefined ? { omit: args.omit } : {}),
|
|
477
|
+
}, compiledWhere.sql, compiledWhere.params, { useHasManyAggregate: false }, projection);
|
|
430
478
|
return rows[0] ?? null;
|
|
431
479
|
}
|
|
432
480
|
const rows = await findMany(executor, runtime, tableAccessor, {
|
|
433
481
|
where,
|
|
434
|
-
|
|
482
|
+
take: 1,
|
|
483
|
+
...(args?.select !== undefined ? { select: args.select } : {}),
|
|
484
|
+
...(args?.omit !== undefined ? { omit: args.omit } : {}),
|
|
435
485
|
});
|
|
436
486
|
return rows[0] ?? null;
|
|
437
487
|
}
|
|
438
488
|
const pkValue = extractScalarPkValue(table, id);
|
|
439
489
|
const ctx = { operation: "select", tableAccessor };
|
|
440
490
|
if (!args?.with) {
|
|
441
|
-
const query =
|
|
491
|
+
const query = projection.hasProjection
|
|
492
|
+
? getCachedFindManyQuery(tableIndex, `byId|${projectionSignature(projection.sqlColumns)}`, () => buildFindByIdQuery(table, projection.sqlColumns, runtime.tableIndex))
|
|
493
|
+
: tableIndex?.findByIdSql || buildFindByIdQuery(table);
|
|
442
494
|
const row = await runQueryOne(executor, runtime, ctx, query, [pkValue]);
|
|
443
|
-
return row
|
|
495
|
+
return row
|
|
496
|
+
? projectFindRow(mapRowToTs(tableIndex, table, row), projection)
|
|
497
|
+
: null;
|
|
444
498
|
}
|
|
445
|
-
const cached = getCachedFindByIdWithQuery(manifest, table, args.with, dialect, runtime.tableIndex);
|
|
499
|
+
const cached = getCachedFindByIdWithQuery(manifest, table, args.with, dialect, runtime.tableIndex, projection.sqlColumns);
|
|
446
500
|
if (cached) {
|
|
447
|
-
const
|
|
501
|
+
const extra = buildPlanExtraSelectCols(manifest, table, cached.plan, dialect, runtime.tableIndex, 2);
|
|
502
|
+
const rows = await runQuery(executor, runtime, ctx, cached.sql, [
|
|
503
|
+
pkValue,
|
|
504
|
+
...extra.params,
|
|
505
|
+
]);
|
|
448
506
|
if (rows.length === 0)
|
|
449
507
|
return null;
|
|
450
508
|
const hydrated = hydrateRowsWithPlan(runtime, table, rows, cached.plan);
|
|
451
|
-
|
|
509
|
+
const projected = projectFindRows(hydrated, projection, args.with);
|
|
510
|
+
return projected[0] ?? null;
|
|
452
511
|
}
|
|
453
512
|
const where = resolvePkWhere(table, id);
|
|
454
513
|
const compiledWhere = getCachedWhereClause(manifest, table, where, dialect, 1, runtime.tableIndex);
|
|
455
514
|
if (compiledWhere.impossible || isImpossibleWhere(compiledWhere.sql)) {
|
|
456
515
|
return null;
|
|
457
516
|
}
|
|
458
|
-
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, {
|
|
517
|
+
const rows = await executeFindManyWithRelations(executor, runtime, tableAccessor, table, tableIndex, {
|
|
518
|
+
where,
|
|
519
|
+
take: 1,
|
|
520
|
+
with: args.with,
|
|
521
|
+
...(args.select !== undefined ? { select: args.select } : {}),
|
|
522
|
+
...(args.omit !== undefined ? { omit: args.omit } : {}),
|
|
523
|
+
}, compiledWhere.sql, compiledWhere.params, { useHasManyAggregate: false }, projection);
|
|
459
524
|
return rows[0] ?? null;
|
|
460
525
|
}
|
|
461
526
|
//# sourceMappingURL=find.js.map
|