drizzle-orm 0.26.1 → 0.26.2-83ca12d
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 +155 -0
- package/aws-data-api/pg/index.cjs +8 -7
- package/aws-data-api/pg/index.cjs.map +1 -1
- package/aws-data-api/pg/index.d.ts +65 -6
- package/aws-data-api/pg/index.mjs +18 -3
- package/aws-data-api/pg/index.mjs.map +1 -1
- package/aws-data-api/pg/migrator.d.ts +5 -5
- package/better-sqlite3/index.cjs +9 -8
- package/better-sqlite3/index.cjs.map +1 -1
- package/better-sqlite3/index.d.ts +5 -5
- package/better-sqlite3/index.mjs +13 -3
- package/better-sqlite3/index.mjs.map +1 -1
- package/better-sqlite3/migrator.d.ts +5 -5
- package/bun-sqlite/index.cjs +9 -8
- package/bun-sqlite/index.cjs.map +1 -1
- package/bun-sqlite/index.d.ts +5 -5
- package/bun-sqlite/index.mjs +13 -3
- package/bun-sqlite/index.mjs.map +1 -1
- package/bun-sqlite/migrator.d.ts +5 -5
- package/{column.d-c31e7ad3.d.ts → column.d-66a08b85.d.ts} +2 -1
- package/d1/index.cjs +9 -8
- package/d1/index.cjs.map +1 -1
- package/d1/index.d.ts +5 -5
- package/d1/index.mjs +14 -3
- package/d1/index.mjs.map +1 -1
- package/d1/migrator.d.ts +5 -5
- package/{db.d-132f4f67.d.ts → db.d-7539956f.d.ts} +4 -4
- package/{db.d-2eb7c122.d.ts → db.d-89e25221.d.ts} +4 -5
- package/{driver.d-5c39be67.d.ts → driver.d-1904bc39.d.ts} +2 -2
- package/{driver.d-86800af3.d.ts → driver.d-1d2954cc.d.ts} +2 -2
- package/{driver.d-c201cb6c.d.ts → driver.d-238b678e.d.ts} +2 -2
- package/{driver.d-0d0a6cb7.d.ts → driver.d-33a2c54d.d.ts} +2 -2
- package/{driver.d-323f603a.d.ts → driver.d-8de27d05.d.ts} +2 -2
- package/{driver.d-4469f445.d.ts → driver.d-d334afe8.d.ts} +2 -2
- package/index.cjs +37 -10
- package/index.cjs.map +1 -1
- package/index.d.ts +4 -4
- package/index.mjs +33 -2
- package/index.mjs.map +1 -1
- package/knex/index.d.ts +1 -1
- package/kysely/index.d.ts +1 -1
- package/libsql/index.cjs +9 -8
- package/libsql/index.cjs.map +1 -1
- package/libsql/index.d.ts +5 -5
- package/libsql/index.mjs +16 -3
- package/libsql/index.mjs.map +1 -1
- package/libsql/migrator.d.ts +5 -5
- package/mysql-core/index.cjs +3 -2
- package/mysql-core/index.cjs.map +1 -1
- package/mysql-core/index.d.ts +5 -5
- package/mysql-core/index.mjs +50 -67
- package/mysql-core/index.mjs.map +1 -1
- package/mysql2/index.cjs +9 -8
- package/mysql2/index.cjs.map +1 -1
- package/mysql2/index.d.ts +61 -7
- package/mysql2/index.mjs +18 -3
- package/mysql2/index.mjs.map +1 -1
- package/mysql2/migrator.d.ts +5 -5
- package/neon-serverless/index.cjs +9 -8
- package/neon-serverless/index.cjs.map +1 -1
- package/neon-serverless/index.d.ts +56 -6
- package/neon-serverless/index.mjs +18 -3
- package/neon-serverless/index.mjs.map +1 -1
- package/neon-serverless/migrator.d.ts +5 -5
- package/node-postgres/index.cjs +49 -38
- package/node-postgres/index.cjs.map +1 -1
- package/node-postgres/index.d.ts +53 -6
- package/node-postgres/index.mjs +58 -33
- package/node-postgres/index.mjs.map +1 -1
- package/node-postgres/migrator.d.ts +5 -5
- package/package-1b949c2d.mjs +4 -0
- package/package-1b949c2d.mjs.map +1 -0
- package/package-b95b1bef.cjs +6 -0
- package/package-b95b1bef.cjs.map +1 -0
- package/package.json +31 -230
- package/pg-core/index.cjs +3 -2
- package/pg-core/index.cjs.map +1 -1
- package/pg-core/index.d.ts +5 -5
- package/pg-core/index.mjs +38 -48
- package/pg-core/index.mjs.map +1 -1
- package/planetscale-serverless/index.cjs +9 -8
- package/planetscale-serverless/index.cjs.map +1 -1
- package/planetscale-serverless/index.d.ts +53 -6
- package/planetscale-serverless/index.mjs +17 -5
- package/planetscale-serverless/index.mjs.map +1 -1
- package/planetscale-serverless/migrator.d.ts +5 -5
- package/postgres-js/index.cjs +50 -26
- package/postgres-js/index.cjs.map +1 -1
- package/postgres-js/index.d.ts +46 -6
- package/postgres-js/index.mjs +56 -21
- package/postgres-js/index.mjs.map +1 -1
- package/postgres-js/migrator.d.ts +5 -5
- package/{query-promise.d-3b15626b.d.ts → query-promise.d-afecc38e.d.ts} +2 -2
- package/{relations-23963f0c.cjs → relations-01342313.cjs} +179 -122
- package/relations-01342313.cjs.map +1 -0
- package/{relations-c9e54a8f.mjs → relations-d3070559.mjs} +361 -213
- package/relations-d3070559.mjs.map +1 -0
- package/{select.types.d-34d7f74e.d.ts → select.types.d-1bd49d37.d.ts} +1 -1
- package/{select.types.d-75d13797.d.ts → select.types.d-2d1036d9.d.ts} +3 -3
- package/{session-5f4fc058.mjs → session-108d31ca.mjs} +94 -34
- package/session-108d31ca.mjs.map +1 -0
- package/{session-1beef0bc.mjs → session-3d76708c.mjs} +132 -73
- package/session-3d76708c.mjs.map +1 -0
- package/{session-9c287b9e.cjs → session-6af58e96.cjs} +43 -25
- package/session-6af58e96.cjs.map +1 -0
- package/{session-f1dcefd2.mjs → session-6d53d1de.mjs} +128 -73
- package/session-6d53d1de.mjs.map +1 -0
- package/{session-ce54b9a2.cjs → session-b33c29a1.cjs} +6 -4
- package/session-b33c29a1.cjs.map +1 -0
- package/{session-eb0100ab.cjs → session-f555a31e.cjs} +3 -2
- package/session-f555a31e.cjs.map +1 -0
- package/sql-js/index.cjs +9 -8
- package/sql-js/index.cjs.map +1 -1
- package/sql-js/index.d.ts +5 -5
- package/sql-js/index.mjs +14 -3
- package/sql-js/index.mjs.map +1 -1
- package/sql-js/migrator.d.ts +5 -5
- package/sqlite-core/index.cjs +6 -3
- package/sqlite-core/index.cjs.map +1 -1
- package/sqlite-core/index.d.ts +13 -7
- package/sqlite-core/index.mjs +44 -17
- package/sqlite-core/index.mjs.map +1 -1
- package/sqlite-proxy/index.cjs +13 -12
- package/sqlite-proxy/index.cjs.map +1 -1
- package/sqlite-proxy/index.d.ts +6 -6
- package/sqlite-proxy/index.mjs +16 -7
- package/sqlite-proxy/index.mjs.map +1 -1
- package/sqlite-proxy/migrator.cjs +2 -1
- package/sqlite-proxy/migrator.cjs.map +1 -1
- package/sqlite-proxy/migrator.d.ts +5 -5
- package/sqlite-proxy/migrator.mjs +2 -1
- package/sqlite-proxy/migrator.mjs.map +1 -1
- package/vercel-postgres/index.cjs +9 -8
- package/vercel-postgres/index.cjs.map +1 -1
- package/vercel-postgres/index.d.ts +56 -6
- package/vercel-postgres/index.mjs +18 -3
- package/vercel-postgres/index.mjs.map +1 -1
- package/vercel-postgres/migrator.d.ts +5 -5
- package/version.cjs +2 -2
- package/version.d.ts +1 -1
- package/version.mjs +2 -2
- package/driver.d-19470274.d.ts +0 -46
- package/driver.d-24f23dda.d.ts +0 -52
- package/driver.d-27ec30dc.d.ts +0 -64
- package/driver.d-2880f5a4.d.ts +0 -55
- package/driver.d-2c6c28d2.d.ts +0 -55
- package/driver.d-6fb29dde.d.ts +0 -55
- package/driver.d-f3926c10.d.ts +0 -60
- package/logger-caa1ca6e.cjs +0 -34
- package/logger-caa1ca6e.cjs.map +0 -1
- package/logger-caf75bde.mjs +0 -30
- package/logger-caf75bde.mjs.map +0 -1
- package/relations-23963f0c.cjs.map +0 -1
- package/relations-c9e54a8f.mjs.map +0 -1
- package/session-1beef0bc.mjs.map +0 -1
- package/session-5f4fc058.mjs.map +0 -1
- package/session-9c287b9e.cjs.map +0 -1
- package/session-ce54b9a2.cjs.map +0 -1
- package/session-eb0100ab.cjs.map +0 -1
- package/session-f1dcefd2.mjs.map +0 -1
package/postgres-js/index.d.ts
CHANGED
|
@@ -1,7 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
import '../
|
|
4
|
-
import '../
|
|
1
|
+
import { Sql, RowList, Row, TransactionSql } from 'postgres';
|
|
2
|
+
import { ah as PreparedQueryConfig, ai as PreparedQuery, a6 as SelectedFieldsOrdered, ak as PgSession, u as PgDialect, aj as PgTransactionConfig, al as PgTransaction, am as QueryResultHKT, t as PgDatabase } from '../db.d-89e25221.js';
|
|
3
|
+
import { L as Logger, Q as Query, ay as Assume, D as DrizzleConfig } from '../column.d-66a08b85.js';
|
|
4
|
+
import { T as TablesRelationalConfig, R as RelationalSchemaConfig } from '../query-promise.d-afecc38e.js';
|
|
5
5
|
import '../migrator.js';
|
|
6
|
-
import '../
|
|
7
|
-
|
|
6
|
+
import '../select.types.d-1bd49d37.js';
|
|
7
|
+
|
|
8
|
+
declare class PostgresJsPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {
|
|
9
|
+
private client;
|
|
10
|
+
private query;
|
|
11
|
+
private params;
|
|
12
|
+
private logger;
|
|
13
|
+
private fields;
|
|
14
|
+
private customResultMapper?;
|
|
15
|
+
constructor(client: Sql, query: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows: unknown[][]) => T['execute']) | undefined);
|
|
16
|
+
execute(placeholderValues?: Record<string, unknown> | undefined): Promise<T['execute']>;
|
|
17
|
+
all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']>;
|
|
18
|
+
}
|
|
19
|
+
interface PostgresJsSessionOptions {
|
|
20
|
+
logger?: Logger;
|
|
21
|
+
}
|
|
22
|
+
declare class PostgresJsSession<TSQL extends Sql, TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgSession<PostgresJsQueryResultHKT, TFullSchema, TSchema> {
|
|
23
|
+
client: TSQL;
|
|
24
|
+
private schema;
|
|
25
|
+
logger: Logger;
|
|
26
|
+
constructor(client: TSQL, dialect: PgDialect, schema: RelationalSchemaConfig<TSchema> | undefined,
|
|
27
|
+
/** @internal */
|
|
28
|
+
options?: PostgresJsSessionOptions);
|
|
29
|
+
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: unknown[][]) => T['execute']): PreparedQuery<T>;
|
|
30
|
+
query(query: string, params: unknown[]): Promise<RowList<Row[]>>;
|
|
31
|
+
queryObjects<T extends Row>(query: string, params: unknown[]): Promise<RowList<T[]>>;
|
|
32
|
+
transaction<T>(transaction: (tx: PostgresJsTransaction<TFullSchema, TSchema>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
33
|
+
}
|
|
34
|
+
declare class PostgresJsTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends PgTransaction<PostgresJsQueryResultHKT, TFullSchema, TSchema> {
|
|
35
|
+
constructor(dialect: PgDialect,
|
|
36
|
+
/** @internal */
|
|
37
|
+
session: PostgresJsSession<TransactionSql, TFullSchema, TSchema>, schema: RelationalSchemaConfig<TSchema> | undefined, nestedIndex?: number);
|
|
38
|
+
transaction<T>(transaction: (tx: PostgresJsTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
interface PostgresJsQueryResultHKT extends QueryResultHKT {
|
|
41
|
+
type: RowList<Assume<this['row'], Row>[]>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type PostgresJsDatabase<TSchema extends Record<string, unknown> = Record<string, never>> = PgDatabase<PostgresJsQueryResultHKT, TSchema>;
|
|
45
|
+
declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(client: Sql, config?: DrizzleConfig<TSchema>): PostgresJsDatabase<TSchema>;
|
|
46
|
+
|
|
47
|
+
export { PostgresJsDatabase, PostgresJsPreparedQuery, PostgresJsQueryResultHKT, PostgresJsSession, PostgresJsSessionOptions, PostgresJsTransaction, drizzle };
|
package/postgres-js/index.mjs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { P as PreparedQuery, a as PgSession, b as PgTransaction, c as PgDatabase } from '../session-
|
|
3
|
-
import {
|
|
1
|
+
import { NoopLogger, DefaultLogger } from '../index.mjs';
|
|
2
|
+
import { P as PreparedQuery, a as PgSession, b as PgTransaction, c as PgDatabase } from '../session-108d31ca.mjs';
|
|
3
|
+
import { t as tracer, f as fillPlaceholders, m as mapResultRow, e as extractTablesRelationalConfig, c as createTableRelationsHelpers, P as PgDialect } from '../relations-d3070559.mjs';
|
|
4
4
|
import '../errors-bb636d84.mjs';
|
|
5
|
+
import '../package-1b949c2d.mjs';
|
|
5
6
|
|
|
6
7
|
class PostgresJsPreparedQuery extends PreparedQuery {
|
|
8
|
+
client;
|
|
9
|
+
query;
|
|
10
|
+
params;
|
|
11
|
+
logger;
|
|
12
|
+
fields;
|
|
13
|
+
customResultMapper;
|
|
7
14
|
constructor(client, query, params, logger, fields, customResultMapper) {
|
|
8
15
|
super();
|
|
9
16
|
this.client = client;
|
|
@@ -14,29 +21,56 @@ class PostgresJsPreparedQuery extends PreparedQuery {
|
|
|
14
21
|
this.customResultMapper = customResultMapper;
|
|
15
22
|
}
|
|
16
23
|
async execute(placeholderValues = {}) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
return tracer.startActiveSpan('drizzle.execute', async (span) => {
|
|
25
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
26
|
+
span?.setAttributes({
|
|
27
|
+
'drizzle.query.text': this.query,
|
|
28
|
+
'drizzle.query.params': JSON.stringify(params),
|
|
29
|
+
});
|
|
30
|
+
this.logger.logQuery(this.query, params);
|
|
31
|
+
const { fields, query, client, joinsNotNullableMap, customResultMapper } = this;
|
|
32
|
+
if (!fields && !customResultMapper) {
|
|
33
|
+
return tracer.startActiveSpan('drizzle.driver.execute', () => {
|
|
34
|
+
return client.unsafe(query, params);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const rows = await tracer.startActiveSpan('drizzle.driver.execute', () => {
|
|
38
|
+
span?.setAttributes({
|
|
39
|
+
'drizzle.query.text': query,
|
|
40
|
+
'drizzle.query.params': JSON.stringify(params),
|
|
41
|
+
});
|
|
42
|
+
return client.unsafe(query, params).values();
|
|
43
|
+
});
|
|
44
|
+
return tracer.startActiveSpan('drizzle.mapResponse', () => {
|
|
45
|
+
return customResultMapper
|
|
46
|
+
? customResultMapper(rows)
|
|
47
|
+
: rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
27
50
|
}
|
|
28
51
|
all(placeholderValues = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
return tracer.startActiveSpan('drizzle.execute', async (span) => {
|
|
53
|
+
const params = fillPlaceholders(this.params, placeholderValues);
|
|
54
|
+
span?.setAttributes({
|
|
55
|
+
'drizzle.query.text': this.query,
|
|
56
|
+
'drizzle.query.params': JSON.stringify(params),
|
|
57
|
+
});
|
|
58
|
+
this.logger.logQuery(this.query, params);
|
|
59
|
+
return tracer.startActiveSpan('drizzle.driver.execute', () => {
|
|
60
|
+
span?.setAttributes({
|
|
61
|
+
'drizzle.query.text': this.query,
|
|
62
|
+
'drizzle.query.params': JSON.stringify(params),
|
|
63
|
+
});
|
|
64
|
+
return this.client.unsafe(this.query, params);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
37
67
|
}
|
|
38
68
|
}
|
|
39
69
|
class PostgresJsSession extends PgSession {
|
|
70
|
+
client;
|
|
71
|
+
schema;
|
|
72
|
+
options;
|
|
73
|
+
logger;
|
|
40
74
|
constructor(client, dialect, schema,
|
|
41
75
|
/** @internal */
|
|
42
76
|
options = {}) {
|
|
@@ -68,6 +102,7 @@ class PostgresJsSession extends PgSession {
|
|
|
68
102
|
}
|
|
69
103
|
}
|
|
70
104
|
class PostgresJsTransaction extends PgTransaction {
|
|
105
|
+
session;
|
|
71
106
|
constructor(dialect,
|
|
72
107
|
/** @internal */
|
|
73
108
|
session, schema, nestedIndex = 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/postgres-js/session.ts","../../src/postgres-js/driver.ts"],"sourcesContent":[null,null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/postgres-js/session.ts","../../src/postgres-js/driver.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;;;;AAaM,MAAO,uBAAuD,SAAQ,aAAgB,CAAA;AAElF,IAAA,MAAA,CAAA;AACA,IAAA,KAAA,CAAA;AACA,IAAA,MAAA,CAAA;AACA,IAAA,MAAA,CAAA;AACA,IAAA,MAAA,CAAA;AACA,IAAA,kBAAA,CAAA;IANT,WACS,CAAA,MAAW,EACX,KAAa,EACb,MAAiB,EACjB,MAAc,EACd,MAAyC,EACzC,kBAAwD,EAAA;AAEhE,QAAA,KAAK,EAAE,CAAC;QAPA,IAAM,CAAA,MAAA,GAAN,MAAM,CAAK;QACX,IAAK,CAAA,KAAA,GAAL,KAAK,CAAQ;QACb,IAAM,CAAA,MAAA,GAAN,MAAM,CAAW;QACjB,IAAM,CAAA,MAAA,GAAN,MAAM,CAAQ;QACd,IAAM,CAAA,MAAA,GAAN,MAAM,CAAmC;QACzC,IAAkB,CAAA,kBAAA,GAAlB,kBAAkB,CAAsC;KAGhE;AAED,IAAA,MAAM,OAAO,CAAC,iBAAA,GAAyD,EAAE,EAAA;QACxE,OAAO,MAAM,CAAC,eAAe,CAAC,iBAAiB,EAAE,OAAO,IAAI,KAAI;YAC/D,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;YAEhE,IAAI,EAAE,aAAa,CAAC;gBACnB,oBAAoB,EAAE,IAAI,CAAC,KAAK;AAChC,gBAAA,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;AAC9C,aAAA,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC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AG,IAAI,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAgC,CAAC;AAChF;;;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MigrationConfig } from '../migrator.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PostgresJsDatabase } from './index.js';
|
|
3
3
|
import 'postgres';
|
|
4
|
-
import '../db.d-
|
|
5
|
-
import '../column.d-
|
|
6
|
-
import '../query-promise.d-
|
|
7
|
-
import '../select.types.d-
|
|
4
|
+
import '../db.d-89e25221.js';
|
|
5
|
+
import '../column.d-66a08b85.js';
|
|
6
|
+
import '../query-promise.d-afecc38e.js';
|
|
7
|
+
import '../select.types.d-1bd49d37.js';
|
|
8
8
|
|
|
9
9
|
declare function migrate<TSchema extends Record<string, unknown>>(db: PostgresJsDatabase<TSchema>, config: string | MigrationConfig): Promise<void>;
|
|
10
10
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AnyColumn,
|
|
1
|
+
import { A as AnyColumn, a as SQL, ab as SQLChunk, ad as Placeholder, Y as SQLWrapper, G as GetColumnData, T as Table, an as AnyTable, ac as sql, ax as SimplifyShallow, aB as ValueOrArray, ay as Assume, az as Equal, as as InferModelFromColumns, aH as ColumnsWithTable, ak as TableConfig } from './column.d-66a08b85.js';
|
|
2
2
|
|
|
3
3
|
declare function bindIfParam(value: unknown, column: AnyColumn | SQL.Aliased): SQLChunk;
|
|
4
4
|
/**
|
|
@@ -614,4 +614,4 @@ declare abstract class QueryPromise<T> implements Promise<T> {
|
|
|
614
614
|
abstract execute(): Promise<T>;
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
-
export { normalizeRelation as $,
|
|
617
|
+
export { normalizeRelation as $, TableRelationsKeysOnly as A, ExtractObjectValues as B, ExtractRelationsFromTableExtraConfigSchema as C, operators as D, ExtractTableRelationsFromSchema as E, Operators as F, orderByOperators as G, OrderByOperators as H, FindTableByDBName as I, DBQueryConfig as J, TableRelationalConfig as K, ExtractTablesWithRelations as L, Many as M, ReturnTypeOrValue as N, One as O, BuildRelationResult as P, QueryPromise as Q, RelationalSchemaConfig as R, NonUndefinedKeysOnly as S, TablesRelationalConfig as T, BuildQueryResult as U, RelationConfig as V, extractTablesRelationalConfig as W, relations as X, createOne as Y, createMany as Z, NormalizedRelation as _, Relation as a, createTableRelationsHelpers as a0, TableRelationsHelpers as a1, BuildRelationalQueryResult as a2, mapRelationalRow as a3, bindIfParam as b, and as c, not as d, eq as e, gte as f, gt as g, lte as h, inArray as i, notInArray as j, isNull as k, lt as l, isNotNull as m, ne as n, or as o, exists as p, notExists as q, between as r, notBetween as s, like as t, notLike as u, ilike as v, notIlike as w, asc as x, desc as y, Relations as z };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _package = require('./package-b95b1bef.cjs');
|
|
4
|
+
|
|
3
5
|
/*
|
|
4
6
|
`Column` only accepts a full `ColumnConfig` as its generic.
|
|
5
7
|
To infer parts of the config, use `AnyColumn` that accepts a partial config.
|
|
@@ -151,6 +153,158 @@ function getTableName(table) {
|
|
|
151
153
|
return table[TableName];
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
/** @internal */
|
|
157
|
+
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
158
|
+
// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise
|
|
159
|
+
const nullifyMap = {};
|
|
160
|
+
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
161
|
+
let decoder;
|
|
162
|
+
if (field instanceof Column) {
|
|
163
|
+
decoder = field;
|
|
164
|
+
}
|
|
165
|
+
else if (field instanceof SQL) {
|
|
166
|
+
decoder = field.decoder;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
decoder = field.sql.decoder;
|
|
170
|
+
}
|
|
171
|
+
let node = result;
|
|
172
|
+
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
173
|
+
if (pathChunkIndex < path.length - 1) {
|
|
174
|
+
if (!(pathChunk in node)) {
|
|
175
|
+
node[pathChunk] = {};
|
|
176
|
+
}
|
|
177
|
+
node = node[pathChunk];
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const rawValue = row[columnIndex];
|
|
181
|
+
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
182
|
+
if (joinsNotNullableMap && field instanceof Column && path.length === 2) {
|
|
183
|
+
const objectName = path[0];
|
|
184
|
+
if (!(objectName in nullifyMap)) {
|
|
185
|
+
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
186
|
+
}
|
|
187
|
+
else if (typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
188
|
+
nullifyMap[objectName] = false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}, {});
|
|
195
|
+
// Nullify all nested objects from nullifyMap that are nullable
|
|
196
|
+
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
197
|
+
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
198
|
+
if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {
|
|
199
|
+
result[objectName] = null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
function orderSelectedFields(fields, pathPrefix) {
|
|
207
|
+
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
208
|
+
if (typeof name !== 'string') {
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
212
|
+
if (field instanceof Column
|
|
213
|
+
|| field instanceof SQL
|
|
214
|
+
|| field instanceof SQL.Aliased) {
|
|
215
|
+
result.push({ path: newPath, field });
|
|
216
|
+
}
|
|
217
|
+
else if (field instanceof Table) {
|
|
218
|
+
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
result.push(...orderSelectedFields(field, newPath));
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}, []);
|
|
225
|
+
}
|
|
226
|
+
/** @internal */
|
|
227
|
+
function mapUpdateSet(table, values) {
|
|
228
|
+
const entries = Object.entries(values)
|
|
229
|
+
.filter(([, value]) => value !== undefined)
|
|
230
|
+
.map(([key, value]) => {
|
|
231
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
232
|
+
if (value instanceof SQL) {
|
|
233
|
+
return [key, value];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
if (entries.length === 0) {
|
|
240
|
+
throw new Error('No values to set');
|
|
241
|
+
}
|
|
242
|
+
return Object.fromEntries(entries);
|
|
243
|
+
}
|
|
244
|
+
/** @internal */
|
|
245
|
+
function applyMixins(baseClass, extendedClasses) {
|
|
246
|
+
for (const extendedClass of extendedClasses) {
|
|
247
|
+
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
248
|
+
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function getTableColumns(table) {
|
|
253
|
+
return table[Table.Symbol.Columns];
|
|
254
|
+
}
|
|
255
|
+
/** @internal */
|
|
256
|
+
function getTableLikeName(table) {
|
|
257
|
+
return table instanceof Subquery
|
|
258
|
+
? table[SubqueryConfig].alias
|
|
259
|
+
: table instanceof View
|
|
260
|
+
? table[ViewBaseConfig].name
|
|
261
|
+
: table instanceof SQL
|
|
262
|
+
? undefined
|
|
263
|
+
: table[Table.Symbol.IsAlias]
|
|
264
|
+
? table[Table.Symbol.Name]
|
|
265
|
+
: table[Table.Symbol.BaseName];
|
|
266
|
+
}
|
|
267
|
+
function iife(fn, ...args) {
|
|
268
|
+
return fn(...args);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let otel;
|
|
272
|
+
let rawTracer;
|
|
273
|
+
try {
|
|
274
|
+
otel = require('@opentelemetry/api');
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/** @internal */
|
|
282
|
+
const tracer = {
|
|
283
|
+
startActiveSpan(name, fn) {
|
|
284
|
+
if (!otel) {
|
|
285
|
+
return fn();
|
|
286
|
+
}
|
|
287
|
+
if (!rawTracer) {
|
|
288
|
+
rawTracer = otel.trace.getTracer('drizzle-orm', _package.version);
|
|
289
|
+
}
|
|
290
|
+
return iife((otel, rawTracer) => rawTracer.startActiveSpan(name, ((span) => {
|
|
291
|
+
try {
|
|
292
|
+
return fn(span);
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
span.setStatus({
|
|
296
|
+
code: otel.SpanStatusCode.ERROR,
|
|
297
|
+
message: e instanceof Error ? e.message : 'Unknown error',
|
|
298
|
+
});
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
finally {
|
|
302
|
+
span.end();
|
|
303
|
+
}
|
|
304
|
+
})), otel, rawTracer);
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
154
308
|
function bindIfParam(value, column) {
|
|
155
309
|
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !(value instanceof Param) && !(value instanceof Placeholder)
|
|
156
310
|
&& !(value instanceof Column) && !(value instanceof Table) && !(value instanceof View)) {
|
|
@@ -334,7 +488,7 @@ function exists(subquery) {
|
|
|
334
488
|
* @see exists for the inverse of this test
|
|
335
489
|
*/
|
|
336
490
|
function notExists(subquery) {
|
|
337
|
-
return sql `exists (${subquery})`;
|
|
491
|
+
return sql `not exists (${subquery})`;
|
|
338
492
|
}
|
|
339
493
|
function between(column, min, max) {
|
|
340
494
|
return sql `${column} between ${bindIfParam(min, column)} and ${bindIfParam(max, column)}`;
|
|
@@ -483,7 +637,8 @@ function mergeQueries(queries) {
|
|
|
483
637
|
for (const query of queries) {
|
|
484
638
|
result.sql += query.sql;
|
|
485
639
|
result.params.push(...query.params);
|
|
486
|
-
if (
|
|
640
|
+
if (query.typings?.length) {
|
|
641
|
+
result.typings = result.typings || [];
|
|
487
642
|
result.typings.push(...query.typings);
|
|
488
643
|
}
|
|
489
644
|
}
|
|
@@ -506,7 +661,14 @@ class SQL {
|
|
|
506
661
|
return this;
|
|
507
662
|
}
|
|
508
663
|
toQuery(config) {
|
|
509
|
-
return
|
|
664
|
+
return tracer.startActiveSpan('drizzle.buildSQL', (span) => {
|
|
665
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
666
|
+
span?.setAttributes({
|
|
667
|
+
'drizzle.query.text': query.sql,
|
|
668
|
+
'drizzle.query.params': JSON.stringify(query.params),
|
|
669
|
+
});
|
|
670
|
+
return query;
|
|
671
|
+
});
|
|
510
672
|
}
|
|
511
673
|
buildQueryFromSourceParams(chunks, _config) {
|
|
512
674
|
const config = Object.assign({}, _config, {
|
|
@@ -1137,118 +1299,6 @@ class PrimaryKey {
|
|
|
1137
1299
|
}
|
|
1138
1300
|
}
|
|
1139
1301
|
|
|
1140
|
-
/** @internal */
|
|
1141
|
-
function mapResultRow(columns, row, joinsNotNullableMap) {
|
|
1142
|
-
// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise
|
|
1143
|
-
const nullifyMap = {};
|
|
1144
|
-
const result = columns.reduce((result, { path, field }, columnIndex) => {
|
|
1145
|
-
let decoder;
|
|
1146
|
-
if (field instanceof Column) {
|
|
1147
|
-
decoder = field;
|
|
1148
|
-
}
|
|
1149
|
-
else if (field instanceof SQL) {
|
|
1150
|
-
decoder = field.decoder;
|
|
1151
|
-
}
|
|
1152
|
-
else {
|
|
1153
|
-
decoder = field.sql.decoder;
|
|
1154
|
-
}
|
|
1155
|
-
let node = result;
|
|
1156
|
-
for (const [pathChunkIndex, pathChunk] of path.entries()) {
|
|
1157
|
-
if (pathChunkIndex < path.length - 1) {
|
|
1158
|
-
if (!(pathChunk in node)) {
|
|
1159
|
-
node[pathChunk] = {};
|
|
1160
|
-
}
|
|
1161
|
-
node = node[pathChunk];
|
|
1162
|
-
}
|
|
1163
|
-
else {
|
|
1164
|
-
const rawValue = row[columnIndex];
|
|
1165
|
-
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
|
|
1166
|
-
if (joinsNotNullableMap && field instanceof Column && path.length === 2) {
|
|
1167
|
-
const objectName = path[0];
|
|
1168
|
-
if (!(objectName in nullifyMap)) {
|
|
1169
|
-
nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
|
|
1170
|
-
}
|
|
1171
|
-
else if (typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)) {
|
|
1172
|
-
nullifyMap[objectName] = false;
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
return result;
|
|
1178
|
-
}, {});
|
|
1179
|
-
// Nullify all nested objects from nullifyMap that are nullable
|
|
1180
|
-
if (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {
|
|
1181
|
-
for (const [objectName, tableName] of Object.entries(nullifyMap)) {
|
|
1182
|
-
if (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {
|
|
1183
|
-
result[objectName] = null;
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
return result;
|
|
1188
|
-
}
|
|
1189
|
-
/** @internal */
|
|
1190
|
-
function orderSelectedFields(fields, pathPrefix) {
|
|
1191
|
-
return Object.entries(fields).reduce((result, [name, field]) => {
|
|
1192
|
-
if (typeof name !== 'string') {
|
|
1193
|
-
return result;
|
|
1194
|
-
}
|
|
1195
|
-
const newPath = pathPrefix ? [...pathPrefix, name] : [name];
|
|
1196
|
-
if (field instanceof Column
|
|
1197
|
-
|| field instanceof SQL
|
|
1198
|
-
|| field instanceof SQL.Aliased) {
|
|
1199
|
-
result.push({ path: newPath, field });
|
|
1200
|
-
}
|
|
1201
|
-
else if (field instanceof Table) {
|
|
1202
|
-
result.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));
|
|
1203
|
-
}
|
|
1204
|
-
else {
|
|
1205
|
-
result.push(...orderSelectedFields(field, newPath));
|
|
1206
|
-
}
|
|
1207
|
-
return result;
|
|
1208
|
-
}, []);
|
|
1209
|
-
}
|
|
1210
|
-
/** @internal */
|
|
1211
|
-
function mapUpdateSet(table, values) {
|
|
1212
|
-
const entries = Object.entries(values)
|
|
1213
|
-
.filter(([, value]) => value !== undefined)
|
|
1214
|
-
.map(([key, value]) => {
|
|
1215
|
-
// eslint-disable-next-line unicorn/prefer-ternary
|
|
1216
|
-
if (value instanceof SQL) {
|
|
1217
|
-
return [key, value];
|
|
1218
|
-
}
|
|
1219
|
-
else {
|
|
1220
|
-
return [key, new Param(value, table[Table.Symbol.Columns][key])];
|
|
1221
|
-
}
|
|
1222
|
-
});
|
|
1223
|
-
if (entries.length === 0) {
|
|
1224
|
-
throw new Error('No values to set');
|
|
1225
|
-
}
|
|
1226
|
-
return Object.fromEntries(entries);
|
|
1227
|
-
}
|
|
1228
|
-
/** @internal */
|
|
1229
|
-
function applyMixins(baseClass, extendedClasses) {
|
|
1230
|
-
for (const extendedClass of extendedClasses) {
|
|
1231
|
-
for (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {
|
|
1232
|
-
Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null));
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
function getTableColumns(table) {
|
|
1237
|
-
return table[Table.Symbol.Columns];
|
|
1238
|
-
}
|
|
1239
|
-
/** @internal */
|
|
1240
|
-
function getTableLikeName(table) {
|
|
1241
|
-
return table instanceof Subquery
|
|
1242
|
-
? table[SubqueryConfig].alias
|
|
1243
|
-
: table instanceof View
|
|
1244
|
-
? table[ViewBaseConfig].name
|
|
1245
|
-
: table instanceof SQL
|
|
1246
|
-
? undefined
|
|
1247
|
-
: table[Table.Symbol.IsAlias]
|
|
1248
|
-
? table[Table.Symbol.Name]
|
|
1249
|
-
: table[Table.Symbol.BaseName];
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
1302
|
class PgDialect {
|
|
1253
1303
|
async migrate(migrations, session) {
|
|
1254
1304
|
const migrationTableCreate = sql `
|
|
@@ -2049,17 +2099,22 @@ class PgSelect extends PgSelectQueryBuilder {
|
|
|
2049
2099
|
constructor() {
|
|
2050
2100
|
super(...arguments);
|
|
2051
2101
|
this.execute = (placeholderValues) => {
|
|
2052
|
-
return
|
|
2102
|
+
return tracer.startActiveSpan('drizzle.operation', () => {
|
|
2103
|
+
return this._prepare().execute(placeholderValues);
|
|
2104
|
+
});
|
|
2053
2105
|
};
|
|
2054
2106
|
}
|
|
2055
2107
|
_prepare(name) {
|
|
2056
|
-
|
|
2108
|
+
const { session, config, dialect, joinsNotNullableMap } = this;
|
|
2109
|
+
if (!session) {
|
|
2057
2110
|
throw new Error('Cannot execute a query on a query builder. Please use a database instance instead.');
|
|
2058
2111
|
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2112
|
+
return tracer.startActiveSpan('drizzle.prepareQuery', () => {
|
|
2113
|
+
const fieldsList = orderSelectedFields(config.fields);
|
|
2114
|
+
const query = session.prepareQuery(dialect.sqlToQuery(this.getSQL()), fieldsList, name);
|
|
2115
|
+
query.joinsNotNullableMap = joinsNotNullableMap;
|
|
2116
|
+
return query;
|
|
2117
|
+
});
|
|
2063
2118
|
}
|
|
2064
2119
|
/**
|
|
2065
2120
|
* Create a prepared statement for this query. This allows
|
|
@@ -3069,6 +3124,7 @@ exports.getTableName = getTableName;
|
|
|
3069
3124
|
exports.getViewConfig = getViewConfig;
|
|
3070
3125
|
exports.gt = gt;
|
|
3071
3126
|
exports.gte = gte;
|
|
3127
|
+
exports.iife = iife;
|
|
3072
3128
|
exports.ilike = ilike;
|
|
3073
3129
|
exports.inArray = inArray;
|
|
3074
3130
|
exports.index = index;
|
|
@@ -3121,6 +3177,7 @@ exports.relations = relations;
|
|
|
3121
3177
|
exports.sql = sql;
|
|
3122
3178
|
exports.time = time;
|
|
3123
3179
|
exports.timestamp = timestamp;
|
|
3180
|
+
exports.tracer = tracer;
|
|
3124
3181
|
exports.uniqueIndex = uniqueIndex;
|
|
3125
3182
|
exports.uuid = uuid;
|
|
3126
|
-
//# sourceMappingURL=relations-
|
|
3183
|
+
//# sourceMappingURL=relations-01342313.cjs.map
|