drizzle-orm 0.33.0 → 0.34.0-680d055
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/aws-data-api/common/index.d.cts +1 -1
- package/aws-data-api/common/index.d.ts +1 -1
- package/aws-data-api/pg/driver.cjs +3 -1
- package/aws-data-api/pg/driver.cjs.map +1 -1
- package/aws-data-api/pg/driver.d.cts +4 -2
- package/aws-data-api/pg/driver.d.ts +4 -2
- package/aws-data-api/pg/driver.js +3 -1
- package/aws-data-api/pg/driver.js.map +1 -1
- package/aws-data-api/pg/migrator.cjs.map +1 -1
- package/aws-data-api/pg/migrator.d.cts +1 -1
- package/aws-data-api/pg/migrator.d.ts +1 -1
- package/aws-data-api/pg/migrator.js.map +1 -1
- package/better-sqlite3/driver.cjs +9 -1
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.cts +7 -2
- package/better-sqlite3/driver.d.ts +7 -2
- package/better-sqlite3/driver.js +8 -1
- package/better-sqlite3/driver.js.map +1 -1
- package/better-sqlite3/migrator.cjs.map +1 -1
- package/better-sqlite3/migrator.d.cts +1 -1
- package/better-sqlite3/migrator.d.ts +1 -1
- package/better-sqlite3/migrator.js.map +1 -1
- package/bun-sqlite/driver.cjs +9 -1
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.cts +7 -2
- package/bun-sqlite/driver.d.ts +7 -2
- package/bun-sqlite/driver.js +8 -1
- package/bun-sqlite/driver.js.map +1 -1
- package/bun-sqlite/migrator.cjs.map +1 -1
- package/bun-sqlite/migrator.d.cts +1 -1
- package/bun-sqlite/migrator.d.ts +1 -1
- package/bun-sqlite/migrator.js.map +1 -1
- package/d1/driver.cjs +3 -1
- package/d1/driver.cjs.map +1 -1
- package/d1/driver.d.cts +6 -2
- package/d1/driver.d.ts +6 -2
- package/d1/driver.js +3 -1
- package/d1/driver.js.map +1 -1
- package/d1/migrator.cjs +1 -1
- package/d1/migrator.cjs.map +1 -1
- package/d1/migrator.d.cts +1 -1
- package/d1/migrator.d.ts +1 -1
- package/d1/migrator.js +1 -1
- package/d1/migrator.js.map +1 -1
- package/expo-sqlite/driver.cjs +9 -1
- package/expo-sqlite/driver.cjs.map +1 -1
- package/expo-sqlite/driver.d.cts +7 -2
- package/expo-sqlite/driver.d.ts +7 -2
- package/expo-sqlite/driver.js +8 -1
- package/expo-sqlite/driver.js.map +1 -1
- package/index.cjs +4 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/libsql/driver.cjs +3 -1
- package/libsql/driver.cjs.map +1 -1
- package/libsql/driver.d.cts +3 -1
- package/libsql/driver.d.ts +3 -1
- package/libsql/driver.js +3 -1
- package/libsql/driver.js.map +1 -1
- package/libsql/migrator.cjs +2 -2
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.js +2 -2
- package/libsql/migrator.js.map +1 -1
- package/libsql/session.cjs +12 -0
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.d.cts +1 -0
- package/libsql/session.d.ts +1 -0
- package/libsql/session.js +12 -0
- package/libsql/session.js.map +1 -1
- package/migrator.cjs +1 -12
- package/migrator.cjs.map +1 -1
- package/migrator.d.cts +1 -1
- package/migrator.d.ts +1 -1
- package/migrator.js +1 -12
- package/migrator.js.map +1 -1
- package/monodriver.cjs +264 -0
- package/monodriver.cjs.map +1 -0
- package/monodriver.d.cts +184 -0
- package/monodriver.d.ts +184 -0
- package/monodriver.js +230 -0
- package/monodriver.js.map +1 -0
- package/monomigrator.cjs +95 -0
- package/monomigrator.cjs.map +1 -0
- package/monomigrator.d.cts +15 -0
- package/monomigrator.d.ts +15 -0
- package/monomigrator.js +61 -0
- package/monomigrator.js.map +1 -0
- package/mysql-core/db.cjs +6 -1
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +5 -2
- package/mysql-core/db.d.ts +5 -2
- package/mysql-core/db.js +6 -1
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/query-builders/count.cjs +73 -0
- package/mysql-core/query-builders/count.cjs.map +1 -0
- package/mysql-core/query-builders/count.d.cts +27 -0
- package/mysql-core/query-builders/count.d.ts +27 -0
- package/mysql-core/query-builders/count.js +49 -0
- package/mysql-core/query-builders/count.js.map +1 -0
- package/mysql-core/session.cjs +6 -0
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +1 -0
- package/mysql-core/session.d.ts +1 -0
- package/mysql-core/session.js +6 -0
- package/mysql-core/session.js.map +1 -1
- package/mysql-proxy/driver.cjs +7 -1
- package/mysql-proxy/driver.cjs.map +1 -1
- package/mysql-proxy/driver.d.cts +4 -1
- package/mysql-proxy/driver.d.ts +4 -1
- package/mysql-proxy/driver.js +6 -1
- package/mysql-proxy/driver.js.map +1 -1
- package/mysql2/driver.cjs +10 -5
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +6 -2
- package/mysql2/driver.d.ts +6 -2
- package/mysql2/driver.js +9 -5
- package/mysql2/driver.js.map +1 -1
- package/neon-http/driver.cjs +3 -1
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +3 -1
- package/neon-http/driver.d.ts +3 -1
- package/neon-http/driver.js +3 -1
- package/neon-http/driver.js.map +1 -1
- package/neon-http/migrator.cjs +2 -2
- package/neon-http/migrator.cjs.map +1 -1
- package/neon-http/migrator.d.cts +1 -1
- package/neon-http/migrator.d.ts +1 -1
- package/neon-http/migrator.js +2 -2
- package/neon-http/migrator.js.map +1 -1
- package/neon-http/session.cjs +6 -0
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +2 -1
- package/neon-http/session.d.ts +2 -1
- package/neon-http/session.js +6 -0
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +8 -1
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +6 -2
- package/neon-serverless/driver.d.ts +6 -2
- package/neon-serverless/driver.js +7 -1
- package/neon-serverless/driver.js.map +1 -1
- package/neon-serverless/migrator.cjs.map +1 -1
- package/neon-serverless/migrator.d.cts +1 -1
- package/neon-serverless/migrator.d.ts +1 -1
- package/neon-serverless/migrator.js.map +1 -1
- package/node-postgres/driver.cjs +8 -1
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +6 -2
- package/node-postgres/driver.d.ts +6 -2
- package/node-postgres/driver.js +7 -1
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/migrator.cjs.map +1 -1
- package/node-postgres/migrator.d.cts +1 -1
- package/node-postgres/migrator.d.ts +1 -1
- package/node-postgres/migrator.js.map +1 -1
- package/node-postgres/session.cjs +6 -0
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +2 -1
- package/node-postgres/session.d.ts +2 -1
- package/node-postgres/session.js +6 -0
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +9 -1
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.d.cts +7 -2
- package/op-sqlite/driver.d.ts +7 -2
- package/op-sqlite/driver.js +8 -1
- package/op-sqlite/driver.js.map +1 -1
- package/operations.cjs.map +1 -1
- package/package.json +112 -51
- package/pg-core/db.cjs +8 -3
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +6 -3
- package/pg-core/db.d.ts +6 -3
- package/pg-core/db.js +8 -3
- package/pg-core/db.js.map +1 -1
- package/pg-core/query-builders/count.cjs +73 -0
- package/pg-core/query-builders/count.cjs.map +1 -0
- package/pg-core/query-builders/count.d.cts +26 -0
- package/pg-core/query-builders/count.d.ts +26 -0
- package/pg-core/query-builders/count.js +49 -0
- package/pg-core/query-builders/count.js.map +1 -0
- package/pg-core/session.cjs +6 -0
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +1 -0
- package/pg-core/session.d.ts +1 -0
- package/pg-core/session.js +6 -0
- package/pg-core/session.js.map +1 -1
- package/pg-proxy/driver.cjs +7 -1
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.d.cts +4 -1
- package/pg-proxy/driver.d.ts +4 -1
- package/pg-proxy/driver.js +6 -1
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/migrator.cjs.map +1 -1
- package/pg-proxy/migrator.d.cts +1 -1
- package/pg-proxy/migrator.d.ts +1 -1
- package/pg-proxy/migrator.js.map +1 -1
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +8 -1
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +6 -2
- package/pglite/driver.d.ts +6 -2
- package/pglite/driver.js +7 -1
- package/pglite/driver.js.map +1 -1
- package/pglite/migrator.cjs.map +1 -1
- package/pglite/migrator.d.cts +1 -1
- package/pglite/migrator.d.ts +1 -1
- package/pglite/migrator.js.map +1 -1
- package/pglite/session.cjs +6 -0
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +2 -1
- package/pglite/session.d.ts +2 -1
- package/pglite/session.js +6 -0
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +9 -1
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +7 -2
- package/planetscale-serverless/driver.d.ts +7 -2
- package/planetscale-serverless/driver.js +8 -1
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/migrator.cjs.map +1 -1
- package/planetscale-serverless/migrator.js.map +1 -1
- package/planetscale-serverless/session.cjs +6 -0
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +1 -0
- package/planetscale-serverless/session.d.ts +1 -0
- package/planetscale-serverless/session.js +6 -0
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +9 -1
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +7 -2
- package/postgres-js/driver.d.ts +7 -2
- package/postgres-js/driver.js +8 -1
- package/postgres-js/driver.js.map +1 -1
- package/postgres-js/migrator.cjs.map +1 -1
- package/postgres-js/migrator.d.cts +1 -1
- package/postgres-js/migrator.d.ts +1 -1
- package/postgres-js/migrator.js.map +1 -1
- package/sql-js/migrator.cjs.map +1 -1
- package/sql-js/migrator.d.cts +1 -1
- package/sql-js/migrator.d.ts +1 -1
- package/sql-js/migrator.js.map +1 -1
- package/sqlite-core/db.cjs +21 -16
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +8 -5
- package/sqlite-core/db.d.ts +8 -5
- package/sqlite-core/db.js +21 -16
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/query-builders/count.cjs +72 -0
- package/sqlite-core/query-builders/count.cjs.map +1 -0
- package/sqlite-core/query-builders/count.d.cts +27 -0
- package/sqlite-core/query-builders/count.d.ts +27 -0
- package/sqlite-core/query-builders/count.js +48 -0
- package/sqlite-core/query-builders/count.js.map +1 -0
- package/sqlite-core/session.cjs +4 -0
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +1 -0
- package/sqlite-core/session.d.ts +1 -0
- package/sqlite-core/session.js +4 -0
- package/sqlite-core/session.js.map +1 -1
- package/sqlite-proxy/migrator.cjs.map +1 -1
- package/sqlite-proxy/migrator.d.cts +1 -1
- package/sqlite-proxy/migrator.d.ts +1 -1
- package/sqlite-proxy/migrator.js.map +1 -1
- package/tidb-serverless/driver.cjs +9 -1
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +7 -2
- package/tidb-serverless/driver.d.ts +7 -2
- package/tidb-serverless/driver.js +8 -1
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +6 -0
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +1 -0
- package/tidb-serverless/session.d.ts +1 -0
- package/tidb-serverless/session.js +6 -0
- package/tidb-serverless/session.js.map +1 -1
- package/utils.cjs.map +1 -1
- package/utils.d.cts +1 -0
- package/utils.d.ts +1 -0
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +8 -1
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +6 -2
- package/vercel-postgres/driver.d.ts +6 -2
- package/vercel-postgres/driver.js +7 -1
- package/vercel-postgres/driver.js.map +1 -1
- package/vercel-postgres/migrator.cjs.map +1 -1
- package/vercel-postgres/migrator.d.cts +1 -1
- package/vercel-postgres/migrator.d.ts +1 -1
- package/vercel-postgres/migrator.js.map +1 -1
- package/version.cjs +2 -2
- package/version.cjs.map +1 -1
- package/version.d.cts +2 -2
- package/version.d.ts +2 -2
- package/version.js +2 -2
- package/version.js.map +1 -1
- package/xata-http/driver.cjs +3 -1
- package/xata-http/driver.cjs.map +1 -1
- package/xata-http/driver.d.cts +3 -1
- package/xata-http/driver.d.ts +3 -1
- package/xata-http/driver.js +3 -1
- package/xata-http/driver.js.map +1 -1
- package/xata-http/migrator.cjs +1 -1
- package/xata-http/migrator.cjs.map +1 -1
- package/xata-http/migrator.d.cts +1 -1
- package/xata-http/migrator.d.ts +1 -1
- package/xata-http/migrator.js +1 -1
- package/xata-http/migrator.js.map +1 -1
package/monomigrator.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var monomigrator_exports = {};
|
|
30
|
+
__export(monomigrator_exports, {
|
|
31
|
+
migrate: () => migrate
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(monomigrator_exports);
|
|
34
|
+
var import_entity = require("./entity.cjs");
|
|
35
|
+
async function migrate(db, config) {
|
|
36
|
+
switch (db.constructor[import_entity.entityKind]) {
|
|
37
|
+
case "AwsDataApiPgDatabase": {
|
|
38
|
+
const { migrate: migrate2 } = await import("./aws-data-api/pg/migrator");
|
|
39
|
+
return migrate2(db, config);
|
|
40
|
+
}
|
|
41
|
+
case "BetterSQLite3Database": {
|
|
42
|
+
const { migrate: migrate2 } = await import("./better-sqlite3/migrator");
|
|
43
|
+
return migrate2(db, config);
|
|
44
|
+
}
|
|
45
|
+
case "BunSQLiteDatabase": {
|
|
46
|
+
const { migrate: migrate2 } = await import("./bun-sqlite/migrator");
|
|
47
|
+
return migrate2(db, config);
|
|
48
|
+
}
|
|
49
|
+
case "D1Database": {
|
|
50
|
+
const { migrate: migrate2 } = await import("./d1/migrator");
|
|
51
|
+
return migrate2(db, config);
|
|
52
|
+
}
|
|
53
|
+
case "LibSQLDatabase": {
|
|
54
|
+
const { migrate: migrate2 } = await import("./libsql/migrator");
|
|
55
|
+
return migrate2(db, config);
|
|
56
|
+
}
|
|
57
|
+
case "MySql2Database": {
|
|
58
|
+
const { migrate: migrate2 } = await import("./mysql2/migrator");
|
|
59
|
+
return migrate2(db, config);
|
|
60
|
+
}
|
|
61
|
+
case "NeonHttpDatabase": {
|
|
62
|
+
const { migrate: migrate2 } = await import("./neon-http/migrator");
|
|
63
|
+
return migrate2(db, config);
|
|
64
|
+
}
|
|
65
|
+
case "NeonServerlessDatabase": {
|
|
66
|
+
const { migrate: migrate2 } = await import("./neon-serverless/migrator");
|
|
67
|
+
return migrate2(db, config);
|
|
68
|
+
}
|
|
69
|
+
case "NodePgDatabase": {
|
|
70
|
+
const { migrate: migrate2 } = await import("./node-postgres/migrator");
|
|
71
|
+
return migrate2(db, config);
|
|
72
|
+
}
|
|
73
|
+
case "PlanetScaleDatabase": {
|
|
74
|
+
const { migrate: migrate2 } = await import("./planetscale-serverless/migrator");
|
|
75
|
+
return migrate2(db, config);
|
|
76
|
+
}
|
|
77
|
+
case "PostgresJsDatabase": {
|
|
78
|
+
const { migrate: migrate2 } = await import("./postgres-js/migrator");
|
|
79
|
+
return migrate2(db, config);
|
|
80
|
+
}
|
|
81
|
+
case "TiDBServerlessDatabase": {
|
|
82
|
+
const { migrate: migrate2 } = await import("./tidb-serverless/migrator");
|
|
83
|
+
return migrate2(db, config);
|
|
84
|
+
}
|
|
85
|
+
case "VercelPgDatabase": {
|
|
86
|
+
const { migrate: migrate2 } = await import("./vercel-postgres/migrator");
|
|
87
|
+
return migrate2(db, config);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
migrate
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=monomigrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monomigrator.ts"],"sourcesContent":["/* eslint-disable import/extensions */\nimport type { AwsDataApiPgDatabase } from './aws-data-api/pg/index.ts';\nimport type { BetterSQLite3Database } from './better-sqlite3/index.ts';\nimport type { BunSQLiteDatabase } from './bun-sqlite/index.ts';\nimport type { DrizzleD1Database } from './d1/index.ts';\nimport { entityKind } from './entity.ts';\nimport type { LibSQLDatabase } from './libsql/index.ts';\nimport type { MigrationConfig } from './migrator.ts';\nimport type { MySql2Database } from './mysql2/index.ts';\nimport type { NeonHttpDatabase } from './neon-http/index.ts';\nimport type { NeonDatabase } from './neon-serverless/index.ts';\nimport type { NodePgDatabase } from './node-postgres/index.ts';\nimport type { PlanetScaleDatabase } from './planetscale-serverless/index.ts';\nimport type { PostgresJsDatabase } from './postgres-js/index.ts';\nimport type { TiDBServerlessDatabase } from './tidb-serverless/index.ts';\nimport type { VercelPgDatabase } from './vercel-postgres/index.ts';\n\nexport async function migrate(\n\tdb:\n\t\t| AwsDataApiPgDatabase<any>\n\t\t| BetterSQLite3Database<any>\n\t\t| BunSQLiteDatabase<any>\n\t\t| DrizzleD1Database<any>\n\t\t| LibSQLDatabase<any>\n\t\t| MySql2Database<any>\n\t\t| NeonHttpDatabase<any>\n\t\t| NeonDatabase<any>\n\t\t| NodePgDatabase<any>\n\t\t| PlanetScaleDatabase<any>\n\t\t| PostgresJsDatabase<any>\n\t\t| VercelPgDatabase<any>\n\t\t| TiDBServerlessDatabase<any>,\n\tconfig: MigrationConfig,\n) {\n\tswitch ((<any> db).constructor[entityKind]) {\n\t\tcase 'AwsDataApiPgDatabase': {\n\t\t\tconst { migrate } = await import('./aws-data-api/pg/migrator');\n\n\t\t\treturn migrate(db as AwsDataApiPgDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'BetterSQLite3Database': {\n\t\t\tconst { migrate } = await import('./better-sqlite3/migrator');\n\n\t\t\treturn migrate(db as BetterSQLite3Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'BunSQLiteDatabase': {\n\t\t\tconst { migrate } = await import('./bun-sqlite/migrator');\n\n\t\t\treturn migrate(db as BunSQLiteDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'D1Database': {\n\t\t\tconst { migrate } = await import('./d1/migrator');\n\n\t\t\treturn migrate(db as DrizzleD1Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'LibSQLDatabase': {\n\t\t\tconst { migrate } = await import('./libsql/migrator');\n\n\t\t\treturn migrate(db as LibSQLDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'MySql2Database': {\n\t\t\tconst { migrate } = await import('./mysql2/migrator');\n\n\t\t\treturn migrate(db as MySql2Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'NeonHttpDatabase': {\n\t\t\tconst { migrate } = await import('./neon-http/migrator');\n\n\t\t\treturn migrate(db as NeonHttpDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'NeonServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./neon-serverless/migrator');\n\n\t\t\treturn migrate(db as NeonDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'NodePgDatabase': {\n\t\t\tconst { migrate } = await import('./node-postgres/migrator');\n\n\t\t\treturn migrate(db as NodePgDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'PlanetScaleDatabase': {\n\t\t\tconst { migrate } = await import('./planetscale-serverless/migrator');\n\n\t\t\treturn migrate(db as PlanetScaleDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'PostgresJsDatabase': {\n\t\t\tconst { migrate } = await import('./postgres-js/migrator');\n\n\t\t\treturn migrate(db as PostgresJsDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'TiDBServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./tidb-serverless/migrator');\n\n\t\t\treturn migrate(db as TiDBServerlessDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'VercelPgDatabase': {\n\t\t\tconst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,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAAoB,MAAyB;AAAA,IAC7D;AAAA,IACA,KAAK,kBAAkB;AACtB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,0BAA0B;AAE3D,aAAOA,SAAQ,IAAsB,MAAyB;AAAA,IAC/D;AAAA,IACA,KAAK,uBAAuB;AAC3B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mCAAmC;AAEpE,aAAOA,SAAQ,IAA2B,MAAyB;AAAA,IACpE;AAAA,IACA,KAAK,sBAAsB;AAC1B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,wBAAwB;AAEzD,aAAOA,SAAQ,IAA0B,MAAyB;AAAA,IACnE;AAAA,IACA,KAAK,0BAA0B;AAC9B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAA8B,MAAyB;AAAA,IACvE;AAAA,IACA,KAAK,oBAAoB;AACxB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAAwB,MAAyB;AAAA,IACjE;AAAA,EACD;AACD;","names":["migrate"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwsDataApiPgDatabase } from "./aws-data-api/pg/index.cjs";
|
|
2
|
+
import type { BetterSQLite3Database } from "./better-sqlite3/index.cjs";
|
|
3
|
+
import type { BunSQLiteDatabase } from "./bun-sqlite/index.cjs";
|
|
4
|
+
import type { DrizzleD1Database } from "./d1/index.cjs";
|
|
5
|
+
import type { LibSQLDatabase } from "./libsql/index.cjs";
|
|
6
|
+
import type { MigrationConfig } from "./migrator.cjs";
|
|
7
|
+
import type { MySql2Database } from "./mysql2/index.cjs";
|
|
8
|
+
import type { NeonHttpDatabase } from "./neon-http/index.cjs";
|
|
9
|
+
import type { NeonDatabase } from "./neon-serverless/index.cjs";
|
|
10
|
+
import type { NodePgDatabase } from "./node-postgres/index.cjs";
|
|
11
|
+
import type { PlanetScaleDatabase } from "./planetscale-serverless/index.cjs";
|
|
12
|
+
import type { PostgresJsDatabase } from "./postgres-js/index.cjs";
|
|
13
|
+
import type { TiDBServerlessDatabase } from "./tidb-serverless/index.cjs";
|
|
14
|
+
import type { VercelPgDatabase } from "./vercel-postgres/index.cjs";
|
|
15
|
+
export declare function migrate(db: AwsDataApiPgDatabase<any> | BetterSQLite3Database<any> | BunSQLiteDatabase<any> | DrizzleD1Database<any> | LibSQLDatabase<any> | MySql2Database<any> | NeonHttpDatabase<any> | NeonDatabase<any> | NodePgDatabase<any> | PlanetScaleDatabase<any> | PostgresJsDatabase<any> | VercelPgDatabase<any> | TiDBServerlessDatabase<any>, config: MigrationConfig): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwsDataApiPgDatabase } from "./aws-data-api/pg/index.js";
|
|
2
|
+
import type { BetterSQLite3Database } from "./better-sqlite3/index.js";
|
|
3
|
+
import type { BunSQLiteDatabase } from "./bun-sqlite/index.js";
|
|
4
|
+
import type { DrizzleD1Database } from "./d1/index.js";
|
|
5
|
+
import type { LibSQLDatabase } from "./libsql/index.js";
|
|
6
|
+
import type { MigrationConfig } from "./migrator.js";
|
|
7
|
+
import type { MySql2Database } from "./mysql2/index.js";
|
|
8
|
+
import type { NeonHttpDatabase } from "./neon-http/index.js";
|
|
9
|
+
import type { NeonDatabase } from "./neon-serverless/index.js";
|
|
10
|
+
import type { NodePgDatabase } from "./node-postgres/index.js";
|
|
11
|
+
import type { PlanetScaleDatabase } from "./planetscale-serverless/index.js";
|
|
12
|
+
import type { PostgresJsDatabase } from "./postgres-js/index.js";
|
|
13
|
+
import type { TiDBServerlessDatabase } from "./tidb-serverless/index.js";
|
|
14
|
+
import type { VercelPgDatabase } from "./vercel-postgres/index.js";
|
|
15
|
+
export declare function migrate(db: AwsDataApiPgDatabase<any> | BetterSQLite3Database<any> | BunSQLiteDatabase<any> | DrizzleD1Database<any> | LibSQLDatabase<any> | MySql2Database<any> | NeonHttpDatabase<any> | NeonDatabase<any> | NodePgDatabase<any> | PlanetScaleDatabase<any> | PostgresJsDatabase<any> | VercelPgDatabase<any> | TiDBServerlessDatabase<any>, config: MigrationConfig): Promise<void>;
|
package/monomigrator.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { entityKind } from "./entity.js";
|
|
2
|
+
async function migrate(db, config) {
|
|
3
|
+
switch (db.constructor[entityKind]) {
|
|
4
|
+
case "AwsDataApiPgDatabase": {
|
|
5
|
+
const { migrate: migrate2 } = await import("./aws-data-api/pg/migrator");
|
|
6
|
+
return migrate2(db, config);
|
|
7
|
+
}
|
|
8
|
+
case "BetterSQLite3Database": {
|
|
9
|
+
const { migrate: migrate2 } = await import("./better-sqlite3/migrator");
|
|
10
|
+
return migrate2(db, config);
|
|
11
|
+
}
|
|
12
|
+
case "BunSQLiteDatabase": {
|
|
13
|
+
const { migrate: migrate2 } = await import("./bun-sqlite/migrator");
|
|
14
|
+
return migrate2(db, config);
|
|
15
|
+
}
|
|
16
|
+
case "D1Database": {
|
|
17
|
+
const { migrate: migrate2 } = await import("./d1/migrator");
|
|
18
|
+
return migrate2(db, config);
|
|
19
|
+
}
|
|
20
|
+
case "LibSQLDatabase": {
|
|
21
|
+
const { migrate: migrate2 } = await import("./libsql/migrator");
|
|
22
|
+
return migrate2(db, config);
|
|
23
|
+
}
|
|
24
|
+
case "MySql2Database": {
|
|
25
|
+
const { migrate: migrate2 } = await import("./mysql2/migrator");
|
|
26
|
+
return migrate2(db, config);
|
|
27
|
+
}
|
|
28
|
+
case "NeonHttpDatabase": {
|
|
29
|
+
const { migrate: migrate2 } = await import("./neon-http/migrator");
|
|
30
|
+
return migrate2(db, config);
|
|
31
|
+
}
|
|
32
|
+
case "NeonServerlessDatabase": {
|
|
33
|
+
const { migrate: migrate2 } = await import("./neon-serverless/migrator");
|
|
34
|
+
return migrate2(db, config);
|
|
35
|
+
}
|
|
36
|
+
case "NodePgDatabase": {
|
|
37
|
+
const { migrate: migrate2 } = await import("./node-postgres/migrator");
|
|
38
|
+
return migrate2(db, config);
|
|
39
|
+
}
|
|
40
|
+
case "PlanetScaleDatabase": {
|
|
41
|
+
const { migrate: migrate2 } = await import("./planetscale-serverless/migrator");
|
|
42
|
+
return migrate2(db, config);
|
|
43
|
+
}
|
|
44
|
+
case "PostgresJsDatabase": {
|
|
45
|
+
const { migrate: migrate2 } = await import("./postgres-js/migrator");
|
|
46
|
+
return migrate2(db, config);
|
|
47
|
+
}
|
|
48
|
+
case "TiDBServerlessDatabase": {
|
|
49
|
+
const { migrate: migrate2 } = await import("./tidb-serverless/migrator");
|
|
50
|
+
return migrate2(db, config);
|
|
51
|
+
}
|
|
52
|
+
case "VercelPgDatabase": {
|
|
53
|
+
const { migrate: migrate2 } = await import("./vercel-postgres/migrator");
|
|
54
|
+
return migrate2(db, config);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
migrate
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=monomigrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monomigrator.ts"],"sourcesContent":["/* eslint-disable import/extensions */\nimport type { AwsDataApiPgDatabase } from './aws-data-api/pg/index.ts';\nimport type { BetterSQLite3Database } from './better-sqlite3/index.ts';\nimport type { BunSQLiteDatabase } from './bun-sqlite/index.ts';\nimport type { DrizzleD1Database } from './d1/index.ts';\nimport { entityKind } from './entity.ts';\nimport type { LibSQLDatabase } from './libsql/index.ts';\nimport type { MigrationConfig } from './migrator.ts';\nimport type { MySql2Database } from './mysql2/index.ts';\nimport type { NeonHttpDatabase } from './neon-http/index.ts';\nimport type { NeonDatabase } from './neon-serverless/index.ts';\nimport type { NodePgDatabase } from './node-postgres/index.ts';\nimport type { PlanetScaleDatabase } from './planetscale-serverless/index.ts';\nimport type { PostgresJsDatabase } from './postgres-js/index.ts';\nimport type { TiDBServerlessDatabase } from './tidb-serverless/index.ts';\nimport type { VercelPgDatabase } from './vercel-postgres/index.ts';\n\nexport async function migrate(\n\tdb:\n\t\t| AwsDataApiPgDatabase<any>\n\t\t| BetterSQLite3Database<any>\n\t\t| BunSQLiteDatabase<any>\n\t\t| DrizzleD1Database<any>\n\t\t| LibSQLDatabase<any>\n\t\t| MySql2Database<any>\n\t\t| NeonHttpDatabase<any>\n\t\t| NeonDatabase<any>\n\t\t| NodePgDatabase<any>\n\t\t| PlanetScaleDatabase<any>\n\t\t| PostgresJsDatabase<any>\n\t\t| VercelPgDatabase<any>\n\t\t| TiDBServerlessDatabase<any>,\n\tconfig: MigrationConfig,\n) {\n\tswitch ((<any> db).constructor[entityKind]) {\n\t\tcase 'AwsDataApiPgDatabase': {\n\t\t\tconst { migrate } = await import('./aws-data-api/pg/migrator');\n\n\t\t\treturn migrate(db as AwsDataApiPgDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'BetterSQLite3Database': {\n\t\t\tconst { migrate } = await import('./better-sqlite3/migrator');\n\n\t\t\treturn migrate(db as BetterSQLite3Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'BunSQLiteDatabase': {\n\t\t\tconst { migrate } = await import('./bun-sqlite/migrator');\n\n\t\t\treturn migrate(db as BunSQLiteDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'D1Database': {\n\t\t\tconst { migrate } = await import('./d1/migrator');\n\n\t\t\treturn migrate(db as DrizzleD1Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'LibSQLDatabase': {\n\t\t\tconst { migrate } = await import('./libsql/migrator');\n\n\t\t\treturn migrate(db as LibSQLDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'MySql2Database': {\n\t\t\tconst { migrate } = await import('./mysql2/migrator');\n\n\t\t\treturn migrate(db as MySql2Database, config as MigrationConfig);\n\t\t}\n\t\tcase 'NeonHttpDatabase': {\n\t\t\tconst { migrate } = await import('./neon-http/migrator');\n\n\t\t\treturn migrate(db as NeonHttpDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'NeonServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./neon-serverless/migrator');\n\n\t\t\treturn migrate(db as NeonDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'NodePgDatabase': {\n\t\t\tconst { migrate } = await import('./node-postgres/migrator');\n\n\t\t\treturn migrate(db as NodePgDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'PlanetScaleDatabase': {\n\t\t\tconst { migrate } = await import('./planetscale-serverless/migrator');\n\n\t\t\treturn migrate(db as PlanetScaleDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'PostgresJsDatabase': {\n\t\t\tconst { migrate } = await import('./postgres-js/migrator');\n\n\t\t\treturn migrate(db as PostgresJsDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'TiDBServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./tidb-serverless/migrator');\n\n\t\t\treturn migrate(db as TiDBServerlessDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'VercelPgDatabase': {\n\t\t\tconst { migrate } = await import('./vercel-postgres/migrator');\n\n\t\t\treturn migrate(db as VercelPgDatabase, config as MigrationConfig);\n\t\t}\n\t}\n}\n"],"mappings":"AAKA,SAAS,kBAAkB;AAY3B,eAAsB,QACrB,IAcA,QACC;AACD,UAAe,GAAI,YAAY,UAAU,GAAG;AAAA,IAC3C,KAAK,wBAAwB;AAC5B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAA4B,MAAyB;AAAA,IACrE;AAAA,IACA,KAAK,yBAAyB;AAC7B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,2BAA2B;AAE5D,aAAOA,SAAQ,IAA6B,MAAyB;AAAA,IACtE;AAAA,IACA,KAAK,qBAAqB;AACzB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,uBAA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B;AAAA,IACvE;AAAA,IACA,KAAK,oBAAoB;AACxB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAAwB,MAAyB;AAAA,IACjE;AAAA,EACD;AACD;","names":["migrate"]}
|
package/mysql-core/db.cjs
CHANGED
|
@@ -24,7 +24,9 @@ __export(db_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(db_exports);
|
|
25
25
|
var import_entity = require("../entity.cjs");
|
|
26
26
|
var import_selection_proxy = require("../selection-proxy.cjs");
|
|
27
|
+
var import_sql = require("../sql/sql.cjs");
|
|
27
28
|
var import_subquery = require("../subquery.cjs");
|
|
29
|
+
var import_count = require("./query-builders/count.cjs");
|
|
28
30
|
var import_query_builders = require("./query-builders/index.cjs");
|
|
29
31
|
var import_query = require("./query-builders/query.cjs");
|
|
30
32
|
class MySqlDatabase {
|
|
@@ -104,6 +106,9 @@ class MySqlDatabase {
|
|
|
104
106
|
}
|
|
105
107
|
};
|
|
106
108
|
}
|
|
109
|
+
$count(source, filters) {
|
|
110
|
+
return new import_count.MySqlCountBuilder({ source, filters, session: this.session });
|
|
111
|
+
}
|
|
107
112
|
/**
|
|
108
113
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
109
114
|
*
|
|
@@ -230,7 +235,7 @@ class MySqlDatabase {
|
|
|
230
235
|
return new import_query_builders.MySqlDeleteBase(table, this.session, this.dialect);
|
|
231
236
|
}
|
|
232
237
|
execute(query) {
|
|
233
|
-
return this.session.execute(query.getSQL());
|
|
238
|
+
return this.session.execute(typeof query === "string" ? import_sql.sql.raw(query) : query.getSQL());
|
|
234
239
|
}
|
|
235
240
|
transaction(transaction, config) {
|
|
236
241
|
return this.session.transaction(transaction, config);
|
package/mysql-core/db.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAG3B,6BAAsC;AAEtC,sBAA6B;AAG7B,4BAMO;AACP,mBAAuC;AAchC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB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AO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAG3B,6BAAsC;AACtC,iBAAsE;AACtE,sBAA6B;AAG7B,mBAAkC;AAClC,4BAMO;AACP,mBAAuC;AAehC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AACd,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,QAAC,KAAK,MAAuF,SAAS,IACrG,IAAI;AAAA,UACH,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA,UACP,KAAK,EAAE;AAAA,UACP,OAAQ,WAAW,SAAS;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK;AAAA,QACN;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAjDA,QAAiB,wBAAU,IAAY;AAAA,EAQvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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M,OAAO,CAAC;AAAA,EACxF;AAAA,EAEA,YACC,aAIA,QACa;AACb,WAAO,KAAK,QAAQ,YAAY,aAAa,MAAM;AAAA,EACpD;AACD;AAIO,MAAM,eAAe,CAY3B,SACA,UACA,aAAmC,MAAM,SAAS,KAAK,MAAM,KAAK,OAAO,IAAI,SAAS,MAAM,CAAC,MACnE;AAC1B,QAAM,SAAsB,IAAI,SAAa,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AAChF,QAAM,iBAAsC,IAAI,SAAa,WAAW,QAAQ,EAAE,eAAe,GAAG,IAAI;AACxG,QAAM,QAAmB,IAAI,SAAa,WAAW,QAAQ,EAAE,KAAK,GAAG,IAAI;AAE3E,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,UAAwB,IAAI,SAAgB,QAAQ,QAAQ,GAAG,IAAI;AACzE,QAAM,cAAgC,IAAI,SAAqB,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
package/mysql-core/db.d.cts
CHANGED
|
@@ -2,16 +2,18 @@ import type { ResultSetHeader } from 'mysql2/promise';
|
|
|
2
2
|
import { entityKind } from "../entity.cjs";
|
|
3
3
|
import type { TypedQueryBuilder } from "../query-builders/query-builder.cjs";
|
|
4
4
|
import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
5
|
-
import type
|
|
5
|
+
import { type ColumnsSelection, type SQL, type SQLWrapper } from "../sql/sql.cjs";
|
|
6
6
|
import { WithSubquery } from "../subquery.cjs";
|
|
7
7
|
import type { DrizzleTypeError } from "../utils.cjs";
|
|
8
8
|
import type { MySqlDialect } from "./dialect.cjs";
|
|
9
|
+
import { MySqlCountBuilder } from "./query-builders/count.cjs";
|
|
9
10
|
import { MySqlDeleteBase, MySqlInsertBuilder, MySqlSelectBuilder, MySqlUpdateBuilder, QueryBuilder } from "./query-builders/index.cjs";
|
|
10
11
|
import { RelationalQueryBuilder } from "./query-builders/query.cjs";
|
|
11
12
|
import type { SelectedFields } from "./query-builders/select.types.cjs";
|
|
12
13
|
import type { Mode, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, MySqlTransaction, MySqlTransactionConfig, PreparedQueryHKTBase } from "./session.cjs";
|
|
13
14
|
import type { WithSubqueryWithSelection } from "./subquery.cjs";
|
|
14
15
|
import type { MySqlTable } from "./table.cjs";
|
|
16
|
+
import type { MySqlViewBase } from "./view-base.cjs";
|
|
15
17
|
export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
16
18
|
protected readonly mode: Mode;
|
|
17
19
|
static readonly [entityKind]: string;
|
|
@@ -63,6 +65,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
63
65
|
$with<TAlias extends string>(alias: TAlias): {
|
|
64
66
|
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
65
67
|
};
|
|
68
|
+
$count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any>>;
|
|
66
69
|
/**
|
|
67
70
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
68
71
|
*
|
|
@@ -222,7 +225,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
222
225
|
delete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT>;
|
|
223
226
|
execute<T extends {
|
|
224
227
|
[column: string]: any;
|
|
225
|
-
} = ResultSetHeader>(query: SQLWrapper): Promise<MySqlQueryResultKind<TQueryResult, T>>;
|
|
228
|
+
} = ResultSetHeader>(query: SQLWrapper | string): Promise<MySqlQueryResultKind<TQueryResult, T>>;
|
|
226
229
|
transaction<T>(transaction: (tx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>, config?: MySqlTransactionConfig) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
|
227
230
|
}
|
|
228
231
|
export type MySQLWithReplicas<Q> = Q & {
|
package/mysql-core/db.d.ts
CHANGED
|
@@ -2,16 +2,18 @@ import type { ResultSetHeader } from 'mysql2/promise';
|
|
|
2
2
|
import { entityKind } from "../entity.js";
|
|
3
3
|
import type { TypedQueryBuilder } from "../query-builders/query-builder.js";
|
|
4
4
|
import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
5
|
-
import type
|
|
5
|
+
import { type ColumnsSelection, type SQL, type SQLWrapper } from "../sql/sql.js";
|
|
6
6
|
import { WithSubquery } from "../subquery.js";
|
|
7
7
|
import type { DrizzleTypeError } from "../utils.js";
|
|
8
8
|
import type { MySqlDialect } from "./dialect.js";
|
|
9
|
+
import { MySqlCountBuilder } from "./query-builders/count.js";
|
|
9
10
|
import { MySqlDeleteBase, MySqlInsertBuilder, MySqlSelectBuilder, MySqlUpdateBuilder, QueryBuilder } from "./query-builders/index.js";
|
|
10
11
|
import { RelationalQueryBuilder } from "./query-builders/query.js";
|
|
11
12
|
import type { SelectedFields } from "./query-builders/select.types.js";
|
|
12
13
|
import type { Mode, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, MySqlTransaction, MySqlTransactionConfig, PreparedQueryHKTBase } from "./session.js";
|
|
13
14
|
import type { WithSubqueryWithSelection } from "./subquery.js";
|
|
14
15
|
import type { MySqlTable } from "./table.js";
|
|
16
|
+
import type { MySqlViewBase } from "./view-base.js";
|
|
15
17
|
export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
16
18
|
protected readonly mode: Mode;
|
|
17
19
|
static readonly [entityKind]: string;
|
|
@@ -63,6 +65,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
63
65
|
$with<TAlias extends string>(alias: TAlias): {
|
|
64
66
|
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
65
67
|
};
|
|
68
|
+
$count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any>>;
|
|
66
69
|
/**
|
|
67
70
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
68
71
|
*
|
|
@@ -222,7 +225,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
222
225
|
delete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT>;
|
|
223
226
|
execute<T extends {
|
|
224
227
|
[column: string]: any;
|
|
225
|
-
} = ResultSetHeader>(query: SQLWrapper): Promise<MySqlQueryResultKind<TQueryResult, T>>;
|
|
228
|
+
} = ResultSetHeader>(query: SQLWrapper | string): Promise<MySqlQueryResultKind<TQueryResult, T>>;
|
|
226
229
|
transaction<T>(transaction: (tx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>, config?: MySqlTransactionConfig) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
|
227
230
|
}
|
|
228
231
|
export type MySQLWithReplicas<Q> = Q & {
|
package/mysql-core/db.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { entityKind } from "../entity.js";
|
|
2
2
|
import { SelectionProxyHandler } from "../selection-proxy.js";
|
|
3
|
+
import { sql } from "../sql/sql.js";
|
|
3
4
|
import { WithSubquery } from "../subquery.js";
|
|
5
|
+
import { MySqlCountBuilder } from "./query-builders/count.js";
|
|
4
6
|
import {
|
|
5
7
|
MySqlDeleteBase,
|
|
6
8
|
MySqlInsertBuilder,
|
|
@@ -86,6 +88,9 @@ class MySqlDatabase {
|
|
|
86
88
|
}
|
|
87
89
|
};
|
|
88
90
|
}
|
|
91
|
+
$count(source, filters) {
|
|
92
|
+
return new MySqlCountBuilder({ source, filters, session: this.session });
|
|
93
|
+
}
|
|
89
94
|
/**
|
|
90
95
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
91
96
|
*
|
|
@@ -212,7 +217,7 @@ class MySqlDatabase {
|
|
|
212
217
|
return new MySqlDeleteBase(table, this.session, this.dialect);
|
|
213
218
|
}
|
|
214
219
|
execute(query) {
|
|
215
|
-
return this.session.execute(query.getSQL());
|
|
220
|
+
return this.session.execute(typeof query === "string" ? sql.raw(query) : query.getSQL());
|
|
216
221
|
}
|
|
217
222
|
transaction(transaction, config) {
|
|
218
223
|
return this.session.transaction(transaction, config);
|
package/mysql-core/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAG7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAchC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MAC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A,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport { type ColumnsSelection, type SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper | string,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AACtC,SAA0C,WAA4B;AACtE,SAAS,oBAAoB;AAG7B,SAAS,yBAAyB;AAClC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAehC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AACd,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,QAAC,KAAK,MAAuF,SAAS,IACrG,IAAI;AAAA,UACH,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA,UACP,KAAK,EAAE;AAAA,UACP,OAAQ,WAAW,SAAS;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK;AAAA,QACN;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAjDA,QAAiB,UAAU,IAAY;AAAA,EAQvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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