Initial commit
This commit is contained in:
120
node_modules/drizzle-orm/mysql2/driver.cjs
generated
vendored
Normal file
120
node_modules/drizzle-orm/mysql2/driver.cjs
generated
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var driver_exports = {};
|
||||
__export(driver_exports, {
|
||||
MySql2Database: () => MySql2Database,
|
||||
MySql2Driver: () => MySql2Driver,
|
||||
MySqlDatabase: () => import_db2.MySqlDatabase,
|
||||
drizzle: () => drizzle
|
||||
});
|
||||
module.exports = __toCommonJS(driver_exports);
|
||||
var import_mysql2 = require("mysql2");
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_db = require("../mysql-core/db.cjs");
|
||||
var import_dialect = require("../mysql-core/dialect.cjs");
|
||||
var import_relations = require("../relations.cjs");
|
||||
var import_utils = require("../utils.cjs");
|
||||
var import_errors = require("../errors.cjs");
|
||||
var import_session = require("./session.cjs");
|
||||
var import_db2 = require("../mysql-core/db.cjs");
|
||||
class MySql2Driver {
|
||||
constructor(client, dialect, options = {}) {
|
||||
this.client = client;
|
||||
this.dialect = dialect;
|
||||
this.options = options;
|
||||
}
|
||||
static [import_entity.entityKind] = "MySql2Driver";
|
||||
createSession(schema, mode) {
|
||||
return new import_session.MySql2Session(this.client, this.dialect, schema, { logger: this.options.logger, mode });
|
||||
}
|
||||
}
|
||||
class MySql2Database extends import_db.MySqlDatabase {
|
||||
static [import_entity.entityKind] = "MySql2Database";
|
||||
}
|
||||
function construct(client, config = {}) {
|
||||
const dialect = new import_dialect.MySqlDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new import_logger.DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
const clientForInstance = isCallbackClient(client) ? client.promise() : client;
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
if (config.mode === void 0) {
|
||||
throw new import_errors.DrizzleError({
|
||||
message: 'You need to specify "mode": "planetscale" or "default" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes'
|
||||
});
|
||||
}
|
||||
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
|
||||
config.schema,
|
||||
import_relations.createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const mode = config.mode ?? "default";
|
||||
const driver = new MySql2Driver(clientForInstance, dialect, { logger });
|
||||
const session = driver.createSession(schema, mode);
|
||||
const db = new MySql2Database(dialect, session, schema, mode);
|
||||
db.$client = client;
|
||||
return db;
|
||||
}
|
||||
function isCallbackClient(client) {
|
||||
return typeof client.promise === "function";
|
||||
}
|
||||
function drizzle(...params) {
|
||||
if (typeof params[0] === "string") {
|
||||
const connectionString = params[0];
|
||||
const instance = (0, import_mysql2.createPool)({
|
||||
uri: connectionString
|
||||
});
|
||||
return construct(instance, params[1]);
|
||||
}
|
||||
if ((0, import_utils.isConfig)(params[0])) {
|
||||
const { connection, client, ...drizzleConfig } = params[0];
|
||||
if (client)
|
||||
return construct(client, drizzleConfig);
|
||||
const instance = typeof connection === "string" ? (0, import_mysql2.createPool)({
|
||||
uri: connection
|
||||
}) : (0, import_mysql2.createPool)(connection);
|
||||
const db = construct(instance, drizzleConfig);
|
||||
return db;
|
||||
}
|
||||
return construct(params[0], params[1]);
|
||||
}
|
||||
((drizzle2) => {
|
||||
function mock(config) {
|
||||
return construct({}, config);
|
||||
}
|
||||
drizzle2.mock = mock;
|
||||
})(drizzle || (drizzle = {}));
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
MySql2Database,
|
||||
MySql2Driver,
|
||||
MySqlDatabase,
|
||||
drizzle
|
||||
});
|
||||
//# sourceMappingURL=driver.cjs.map
|
||||
1
node_modules/drizzle-orm/mysql2/driver.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/driver.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
53
node_modules/drizzle-orm/mysql2/driver.d.cts
generated
vendored
Normal file
53
node_modules/drizzle-orm/mysql2/driver.d.cts
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
import { type Connection as CallbackConnection, type Pool as CallbackPool, type PoolOptions } from 'mysql2';
|
||||
import type { Connection, Pool } from 'mysql2/promise';
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import type { Logger } from "../logger.cjs";
|
||||
import { MySqlDatabase } from "../mysql-core/db.cjs";
|
||||
import { MySqlDialect } from "../mysql-core/dialect.cjs";
|
||||
import type { Mode } from "../mysql-core/session.cjs";
|
||||
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.cjs";
|
||||
import { type DrizzleConfig } from "../utils.cjs";
|
||||
import type { MySql2Client, MySql2PreparedQueryHKT, MySql2QueryResultHKT } from "./session.cjs";
|
||||
import { MySql2Session } from "./session.cjs";
|
||||
export interface MySqlDriverOptions {
|
||||
logger?: Logger;
|
||||
}
|
||||
export declare class MySql2Driver {
|
||||
private client;
|
||||
private dialect;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(client: MySql2Client, dialect: MySqlDialect, options?: MySqlDriverOptions);
|
||||
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined, mode: Mode): MySql2Session<Record<string, unknown>, TablesRelationalConfig>;
|
||||
}
|
||||
export { MySqlDatabase } from "../mysql-core/db.cjs";
|
||||
export declare class MySql2Database<TSchema extends Record<string, unknown> = Record<string, never>> extends MySqlDatabase<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
}
|
||||
export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> = Omit<DrizzleConfig<TSchema>, 'schema'> & ({
|
||||
schema: TSchema;
|
||||
mode: Mode;
|
||||
} | {
|
||||
schema?: undefined;
|
||||
mode?: Mode;
|
||||
});
|
||||
export type AnyMySql2Connection = Pool | Connection | CallbackPool | CallbackConnection;
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends AnyMySql2Connection = CallbackPool>(...params: [
|
||||
TClient | string
|
||||
] | [
|
||||
TClient | string,
|
||||
MySql2DrizzleConfig<TSchema>
|
||||
] | [
|
||||
(MySql2DrizzleConfig<TSchema> & ({
|
||||
connection: string | PoolOptions;
|
||||
} | {
|
||||
client: TClient;
|
||||
}))
|
||||
]): MySql2Database<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
export declare namespace drizzle {
|
||||
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: MySql2DrizzleConfig<TSchema>): MySql2Database<TSchema> & {
|
||||
$client: '$client is not available on drizzle.mock()';
|
||||
};
|
||||
}
|
||||
53
node_modules/drizzle-orm/mysql2/driver.d.ts
generated
vendored
Normal file
53
node_modules/drizzle-orm/mysql2/driver.d.ts
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
import { type Connection as CallbackConnection, type Pool as CallbackPool, type PoolOptions } from 'mysql2';
|
||||
import type { Connection, Pool } from 'mysql2/promise';
|
||||
import { entityKind } from "../entity.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { MySqlDatabase } from "../mysql-core/db.js";
|
||||
import { MySqlDialect } from "../mysql-core/dialect.js";
|
||||
import type { Mode } from "../mysql-core/session.js";
|
||||
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.js";
|
||||
import { type DrizzleConfig } from "../utils.js";
|
||||
import type { MySql2Client, MySql2PreparedQueryHKT, MySql2QueryResultHKT } from "./session.js";
|
||||
import { MySql2Session } from "./session.js";
|
||||
export interface MySqlDriverOptions {
|
||||
logger?: Logger;
|
||||
}
|
||||
export declare class MySql2Driver {
|
||||
private client;
|
||||
private dialect;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(client: MySql2Client, dialect: MySqlDialect, options?: MySqlDriverOptions);
|
||||
createSession(schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined, mode: Mode): MySql2Session<Record<string, unknown>, TablesRelationalConfig>;
|
||||
}
|
||||
export { MySqlDatabase } from "../mysql-core/db.js";
|
||||
export declare class MySql2Database<TSchema extends Record<string, unknown> = Record<string, never>> extends MySqlDatabase<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
}
|
||||
export type MySql2DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> = Omit<DrizzleConfig<TSchema>, 'schema'> & ({
|
||||
schema: TSchema;
|
||||
mode: Mode;
|
||||
} | {
|
||||
schema?: undefined;
|
||||
mode?: Mode;
|
||||
});
|
||||
export type AnyMySql2Connection = Pool | Connection | CallbackPool | CallbackConnection;
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends AnyMySql2Connection = CallbackPool>(...params: [
|
||||
TClient | string
|
||||
] | [
|
||||
TClient | string,
|
||||
MySql2DrizzleConfig<TSchema>
|
||||
] | [
|
||||
(MySql2DrizzleConfig<TSchema> & ({
|
||||
connection: string | PoolOptions;
|
||||
} | {
|
||||
client: TClient;
|
||||
}))
|
||||
]): MySql2Database<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
export declare namespace drizzle {
|
||||
function mock<TSchema extends Record<string, unknown> = Record<string, never>>(config?: MySql2DrizzleConfig<TSchema>): MySql2Database<TSchema> & {
|
||||
$client: '$client is not available on drizzle.mock()';
|
||||
};
|
||||
}
|
||||
96
node_modules/drizzle-orm/mysql2/driver.js
generated
vendored
Normal file
96
node_modules/drizzle-orm/mysql2/driver.js
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
import { createPool } from "mysql2";
|
||||
import { entityKind } from "../entity.js";
|
||||
import { DefaultLogger } from "../logger.js";
|
||||
import { MySqlDatabase } from "../mysql-core/db.js";
|
||||
import { MySqlDialect } from "../mysql-core/dialect.js";
|
||||
import {
|
||||
createTableRelationsHelpers,
|
||||
extractTablesRelationalConfig
|
||||
} from "../relations.js";
|
||||
import { isConfig } from "../utils.js";
|
||||
import { DrizzleError } from "../errors.js";
|
||||
import { MySql2Session } from "./session.js";
|
||||
class MySql2Driver {
|
||||
constructor(client, dialect, options = {}) {
|
||||
this.client = client;
|
||||
this.dialect = dialect;
|
||||
this.options = options;
|
||||
}
|
||||
static [entityKind] = "MySql2Driver";
|
||||
createSession(schema, mode) {
|
||||
return new MySql2Session(this.client, this.dialect, schema, { logger: this.options.logger, mode });
|
||||
}
|
||||
}
|
||||
import { MySqlDatabase as MySqlDatabase2 } from "../mysql-core/db.js";
|
||||
class MySql2Database extends MySqlDatabase {
|
||||
static [entityKind] = "MySql2Database";
|
||||
}
|
||||
function construct(client, config = {}) {
|
||||
const dialect = new MySqlDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
const clientForInstance = isCallbackClient(client) ? client.promise() : client;
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
if (config.mode === void 0) {
|
||||
throw new DrizzleError({
|
||||
message: 'You need to specify "mode": "planetscale" or "default" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes'
|
||||
});
|
||||
}
|
||||
const tablesConfig = extractTablesRelationalConfig(
|
||||
config.schema,
|
||||
createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const mode = config.mode ?? "default";
|
||||
const driver = new MySql2Driver(clientForInstance, dialect, { logger });
|
||||
const session = driver.createSession(schema, mode);
|
||||
const db = new MySql2Database(dialect, session, schema, mode);
|
||||
db.$client = client;
|
||||
return db;
|
||||
}
|
||||
function isCallbackClient(client) {
|
||||
return typeof client.promise === "function";
|
||||
}
|
||||
function drizzle(...params) {
|
||||
if (typeof params[0] === "string") {
|
||||
const connectionString = params[0];
|
||||
const instance = createPool({
|
||||
uri: connectionString
|
||||
});
|
||||
return construct(instance, params[1]);
|
||||
}
|
||||
if (isConfig(params[0])) {
|
||||
const { connection, client, ...drizzleConfig } = params[0];
|
||||
if (client)
|
||||
return construct(client, drizzleConfig);
|
||||
const instance = typeof connection === "string" ? createPool({
|
||||
uri: connection
|
||||
}) : createPool(connection);
|
||||
const db = construct(instance, drizzleConfig);
|
||||
return db;
|
||||
}
|
||||
return construct(params[0], params[1]);
|
||||
}
|
||||
((drizzle2) => {
|
||||
function mock(config) {
|
||||
return construct({}, config);
|
||||
}
|
||||
drizzle2.mock = mock;
|
||||
})(drizzle || (drizzle = {}));
|
||||
export {
|
||||
MySql2Database,
|
||||
MySql2Driver,
|
||||
MySqlDatabase2 as MySqlDatabase,
|
||||
drizzle
|
||||
};
|
||||
//# sourceMappingURL=driver.js.map
|
||||
1
node_modules/drizzle-orm/mysql2/driver.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/driver.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
25
node_modules/drizzle-orm/mysql2/index.cjs
generated
vendored
Normal file
25
node_modules/drizzle-orm/mysql2/index.cjs
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var mysql2_exports = {};
|
||||
module.exports = __toCommonJS(mysql2_exports);
|
||||
__reExport(mysql2_exports, require("./driver.cjs"), module.exports);
|
||||
__reExport(mysql2_exports, require("./session.cjs"), module.exports);
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
...require("./driver.cjs"),
|
||||
...require("./session.cjs")
|
||||
});
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
1
node_modules/drizzle-orm/mysql2/index.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/index.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/mysql2/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,wBAAd;AACA,2BAAc,yBADd;","names":[]}
|
||||
2
node_modules/drizzle-orm/mysql2/index.d.cts
generated
vendored
Normal file
2
node_modules/drizzle-orm/mysql2/index.d.cts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./driver.cjs";
|
||||
export * from "./session.cjs";
|
||||
2
node_modules/drizzle-orm/mysql2/index.d.ts
generated
vendored
Normal file
2
node_modules/drizzle-orm/mysql2/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./driver.js";
|
||||
export * from "./session.js";
|
||||
3
node_modules/drizzle-orm/mysql2/index.js
generated
vendored
Normal file
3
node_modules/drizzle-orm/mysql2/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export * from "./driver.js";
|
||||
export * from "./session.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/drizzle-orm/mysql2/index.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/mysql2/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
||||
33
node_modules/drizzle-orm/mysql2/migrator.cjs
generated
vendored
Normal file
33
node_modules/drizzle-orm/mysql2/migrator.cjs
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var migrator_exports = {};
|
||||
__export(migrator_exports, {
|
||||
migrate: () => migrate
|
||||
});
|
||||
module.exports = __toCommonJS(migrator_exports);
|
||||
var import_migrator = require("../migrator.cjs");
|
||||
async function migrate(db, config) {
|
||||
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
||||
await db.dialect.migrate(migrations, db.session, config);
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
migrate
|
||||
});
|
||||
//# sourceMappingURL=migrator.cjs.map
|
||||
1
node_modules/drizzle-orm/mysql2/migrator.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/migrator.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { MySql2Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: MySql2Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
||||
3
node_modules/drizzle-orm/mysql2/migrator.d.cts
generated
vendored
Normal file
3
node_modules/drizzle-orm/mysql2/migrator.d.cts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.cjs";
|
||||
import type { MySql2Database } from "./driver.cjs";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: MySql2Database<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
3
node_modules/drizzle-orm/mysql2/migrator.d.ts
generated
vendored
Normal file
3
node_modules/drizzle-orm/mysql2/migrator.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.js";
|
||||
import type { MySql2Database } from "./driver.js";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: MySql2Database<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
9
node_modules/drizzle-orm/mysql2/migrator.js
generated
vendored
Normal file
9
node_modules/drizzle-orm/mysql2/migrator.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { readMigrationFiles } from "../migrator.js";
|
||||
async function migrate(db, config) {
|
||||
const migrations = readMigrationFiles(config);
|
||||
await db.dialect.migrate(migrations, db.session, config);
|
||||
}
|
||||
export {
|
||||
migrate
|
||||
};
|
||||
//# sourceMappingURL=migrator.js.map
|
||||
1
node_modules/drizzle-orm/mysql2/migrator.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/migrator.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/mysql2/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport type { MySql2Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: MySql2Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tawait db.dialect.migrate(migrations, db.session, config);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AAGnC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,GAAG,QAAQ,QAAQ,YAAY,GAAG,SAAS,MAAM;AACxD;","names":[]}
|
||||
262
node_modules/drizzle-orm/mysql2/session.cjs
generated
vendored
Normal file
262
node_modules/drizzle-orm/mysql2/session.cjs
generated
vendored
Normal file
@ -0,0 +1,262 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
var session_exports = {};
|
||||
__export(session_exports, {
|
||||
MySql2PreparedQuery: () => MySql2PreparedQuery,
|
||||
MySql2Session: () => MySql2Session,
|
||||
MySql2Transaction: () => MySql2Transaction
|
||||
});
|
||||
module.exports = __toCommonJS(session_exports);
|
||||
var import_node_events = require("node:events");
|
||||
var import_column = require("../column.cjs");
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_session = require("../mysql-core/session.cjs");
|
||||
var import_sql = require("../sql/sql.cjs");
|
||||
var import_utils = require("../utils.cjs");
|
||||
class MySql2PreparedQuery extends import_session.MySqlPreparedQuery {
|
||||
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {
|
||||
super();
|
||||
this.client = client;
|
||||
this.params = params;
|
||||
this.logger = logger;
|
||||
this.fields = fields;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.generatedIds = generatedIds;
|
||||
this.returningIds = returningIds;
|
||||
this.rawQuery = {
|
||||
sql: queryString,
|
||||
// rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
||||
this.query = {
|
||||
sql: queryString,
|
||||
rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
||||
}
|
||||
static [import_entity.entityKind] = "MySql2PreparedQuery";
|
||||
rawQuery;
|
||||
query;
|
||||
async execute(placeholderValues = {}) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.rawQuery.sql, params);
|
||||
const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const res = await client.query(rawQuery, params);
|
||||
const insertId = res[0].insertId;
|
||||
const affectedRows = res[0].affectedRows;
|
||||
if (returningIds) {
|
||||
const returningResponse = [];
|
||||
let j = 0;
|
||||
for (let i = insertId; i < insertId + affectedRows; i++) {
|
||||
for (const column of returningIds) {
|
||||
const key = returningIds[0].path[0];
|
||||
if ((0, import_entity.is)(column.field, import_column.Column)) {
|
||||
if (column.field.primary && column.field.autoIncrement) {
|
||||
returningResponse.push({ [key]: i });
|
||||
}
|
||||
if (column.field.defaultFn && generatedIds) {
|
||||
returningResponse.push({ [key]: generatedIds[j][key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return returningResponse;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
const result = await client.query(query, params);
|
||||
const rows = result[0];
|
||||
if (customResultMapper) {
|
||||
return customResultMapper(rows);
|
||||
}
|
||||
return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
||||
}
|
||||
async *iterator(placeholderValues = {}) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.params, placeholderValues);
|
||||
const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
|
||||
const { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;
|
||||
const hasRowsMapper = Boolean(fields || customResultMapper);
|
||||
const driverQuery = hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params);
|
||||
const stream = driverQuery.stream();
|
||||
function dataListener() {
|
||||
stream.pause();
|
||||
}
|
||||
stream.on("data", dataListener);
|
||||
try {
|
||||
const onEnd = (0, import_node_events.once)(stream, "end");
|
||||
const onError = (0, import_node_events.once)(stream, "error");
|
||||
while (true) {
|
||||
stream.resume();
|
||||
const row = await Promise.race([onEnd, onError, new Promise((resolve) => stream.once("data", resolve))]);
|
||||
if (row === void 0 || Array.isArray(row) && row.length === 0) {
|
||||
break;
|
||||
} else if (row instanceof Error) {
|
||||
throw row;
|
||||
} else {
|
||||
if (hasRowsMapper) {
|
||||
if (customResultMapper) {
|
||||
const mappedRow = customResultMapper([row]);
|
||||
yield Array.isArray(mappedRow) ? mappedRow[0] : mappedRow;
|
||||
} else {
|
||||
yield (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap);
|
||||
}
|
||||
} else {
|
||||
yield row;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
stream.off("data", dataListener);
|
||||
if (isPool(client)) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class MySql2Session extends import_session.MySqlSession {
|
||||
constructor(client, dialect, schema, options) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new import_logger.NoopLogger();
|
||||
this.mode = options.mode;
|
||||
}
|
||||
static [import_entity.entityKind] = "MySql2Session";
|
||||
logger;
|
||||
mode;
|
||||
prepareQuery(query, fields, customResultMapper, generatedIds, returningIds) {
|
||||
return new MySql2PreparedQuery(
|
||||
this.client,
|
||||
query.sql,
|
||||
query.params,
|
||||
this.logger,
|
||||
fields,
|
||||
customResultMapper,
|
||||
generatedIds,
|
||||
returningIds
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* What is its purpose?
|
||||
*/
|
||||
async query(query, params) {
|
||||
this.logger.logQuery(query, params);
|
||||
const result = await this.client.query({
|
||||
sql: query,
|
||||
values: params,
|
||||
rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
all(query) {
|
||||
const querySql = this.dialect.sqlToQuery(query);
|
||||
this.logger.logQuery(querySql.sql, querySql.params);
|
||||
return this.client.execute(querySql.sql, querySql.params).then((result) => result[0]);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
const session = isPool(this.client) ? new MySql2Session(
|
||||
await this.client.getConnection(),
|
||||
this.dialect,
|
||||
this.schema,
|
||||
this.options
|
||||
) : this;
|
||||
const tx = new MySql2Transaction(
|
||||
this.dialect,
|
||||
session,
|
||||
this.schema,
|
||||
0,
|
||||
this.mode
|
||||
);
|
||||
if (config) {
|
||||
const setTransactionConfigSql = this.getSetTransactionSQL(config);
|
||||
if (setTransactionConfigSql) {
|
||||
await tx.execute(setTransactionConfigSql);
|
||||
}
|
||||
const startTransactionSql = this.getStartTransactionSQL(config);
|
||||
await (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute(import_sql.sql`begin`));
|
||||
} else {
|
||||
await tx.execute(import_sql.sql`begin`);
|
||||
}
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(import_sql.sql`commit`);
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(import_sql.sql`rollback`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (isPool(this.client)) {
|
||||
session.client.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class MySql2Transaction extends import_session.MySqlTransaction {
|
||||
static [import_entity.entityKind] = "MySql2Transaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex + 1}`;
|
||||
const tx = new MySql2Transaction(
|
||||
this.dialect,
|
||||
this.session,
|
||||
this.schema,
|
||||
this.nestedIndex + 1,
|
||||
this.mode
|
||||
);
|
||||
await tx.execute(import_sql.sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(import_sql.sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
function isPool(client) {
|
||||
return "getConnection" in client;
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
MySql2PreparedQuery,
|
||||
MySql2Session,
|
||||
MySql2Transaction
|
||||
});
|
||||
//# sourceMappingURL=session.cjs.map
|
||||
1
node_modules/drizzle-orm/mysql2/session.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/session.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
54
node_modules/drizzle-orm/mysql2/session.d.cts
generated
vendored
Normal file
54
node_modules/drizzle-orm/mysql2/session.d.cts
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
import type { Connection, FieldPacket, OkPacket, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise';
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import type { Logger } from "../logger.cjs";
|
||||
import type { MySqlDialect } from "../mysql-core/dialect.cjs";
|
||||
import type { SelectedFieldsOrdered } from "../mysql-core/query-builders/select.types.cjs";
|
||||
import { type Mode, MySqlPreparedQuery, type MySqlPreparedQueryConfig, type MySqlPreparedQueryHKT, type MySqlQueryResultHKT, MySqlSession, MySqlTransaction, type MySqlTransactionConfig, type PreparedQueryKind } from "../mysql-core/session.cjs";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
||||
import type { Query, SQL } from "../sql/sql.cjs";
|
||||
import { type Assume } from "../utils.cjs";
|
||||
export type MySql2Client = Pool | Connection;
|
||||
export type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];
|
||||
export type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;
|
||||
export type MySqlQueryResult<T = any> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];
|
||||
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig> extends MySqlPreparedQuery<T> {
|
||||
private client;
|
||||
private params;
|
||||
private logger;
|
||||
private fields;
|
||||
private customResultMapper?;
|
||||
private generatedIds?;
|
||||
private returningIds?;
|
||||
static readonly [entityKind]: string;
|
||||
private rawQuery;
|
||||
private query;
|
||||
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined, generatedIds?: Record<string, unknown>[] | undefined, returningIds?: SelectedFieldsOrdered | undefined);
|
||||
execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
|
||||
iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']>;
|
||||
}
|
||||
export interface MySql2SessionOptions {
|
||||
logger?: Logger;
|
||||
mode: Mode;
|
||||
}
|
||||
export declare class MySql2Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
private mode;
|
||||
constructor(client: MySql2Client, dialect: MySqlDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options: MySql2SessionOptions);
|
||||
prepareQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper?: (rows: unknown[][]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
||||
all<T = unknown>(query: SQL): Promise<T[]>;
|
||||
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
||||
}
|
||||
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlTransaction<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export interface MySql2QueryResultHKT extends MySqlQueryResultHKT {
|
||||
type: MySqlRawQueryResult;
|
||||
}
|
||||
export interface MySql2PreparedQueryHKT extends MySqlPreparedQueryHKT {
|
||||
type: MySql2PreparedQuery<Assume<this['config'], MySqlPreparedQueryConfig>>;
|
||||
}
|
||||
54
node_modules/drizzle-orm/mysql2/session.d.ts
generated
vendored
Normal file
54
node_modules/drizzle-orm/mysql2/session.d.ts
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
import type { Connection, FieldPacket, OkPacket, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise';
|
||||
import { entityKind } from "../entity.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import type { MySqlDialect } from "../mysql-core/dialect.js";
|
||||
import type { SelectedFieldsOrdered } from "../mysql-core/query-builders/select.types.js";
|
||||
import { type Mode, MySqlPreparedQuery, type MySqlPreparedQueryConfig, type MySqlPreparedQueryHKT, type MySqlQueryResultHKT, MySqlSession, MySqlTransaction, type MySqlTransactionConfig, type PreparedQueryKind } from "../mysql-core/session.js";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
||||
import type { Query, SQL } from "../sql/sql.js";
|
||||
import { type Assume } from "../utils.js";
|
||||
export type MySql2Client = Pool | Connection;
|
||||
export type MySqlRawQueryResult = [ResultSetHeader, FieldPacket[]];
|
||||
export type MySqlQueryResultType = RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader;
|
||||
export type MySqlQueryResult<T = any> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];
|
||||
export declare class MySql2PreparedQuery<T extends MySqlPreparedQueryConfig> extends MySqlPreparedQuery<T> {
|
||||
private client;
|
||||
private params;
|
||||
private logger;
|
||||
private fields;
|
||||
private customResultMapper?;
|
||||
private generatedIds?;
|
||||
private returningIds?;
|
||||
static readonly [entityKind]: string;
|
||||
private rawQuery;
|
||||
private query;
|
||||
constructor(client: MySql2Client, queryString: string, params: unknown[], logger: Logger, fields: SelectedFieldsOrdered | undefined, customResultMapper?: ((rows: unknown[][]) => T["execute"]) | undefined, generatedIds?: Record<string, unknown>[] | undefined, returningIds?: SelectedFieldsOrdered | undefined);
|
||||
execute(placeholderValues?: Record<string, unknown>): Promise<T['execute']>;
|
||||
iterator(placeholderValues?: Record<string, unknown>): AsyncGenerator<T['execute'] extends any[] ? T['execute'][number] : T['execute']>;
|
||||
}
|
||||
export interface MySql2SessionOptions {
|
||||
logger?: Logger;
|
||||
mode: Mode;
|
||||
}
|
||||
export declare class MySql2Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlSession<MySqlQueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
private mode;
|
||||
constructor(client: MySql2Client, dialect: MySqlDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options: MySql2SessionOptions);
|
||||
prepareQuery<T extends MySqlPreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, customResultMapper?: (rows: unknown[][]) => T['execute'], generatedIds?: Record<string, unknown>[], returningIds?: SelectedFieldsOrdered): PreparedQueryKind<MySql2PreparedQueryHKT, T>;
|
||||
all<T = unknown>(query: SQL): Promise<T[]>;
|
||||
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>, config?: MySqlTransactionConfig): Promise<T>;
|
||||
}
|
||||
export declare class MySql2Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends MySqlTransaction<MySql2QueryResultHKT, MySql2PreparedQueryHKT, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: MySql2Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export interface MySql2QueryResultHKT extends MySqlQueryResultHKT {
|
||||
type: MySqlRawQueryResult;
|
||||
}
|
||||
export interface MySql2PreparedQueryHKT extends MySqlPreparedQueryHKT {
|
||||
type: MySql2PreparedQuery<Assume<this['config'], MySqlPreparedQueryConfig>>;
|
||||
}
|
||||
240
node_modules/drizzle-orm/mysql2/session.js
generated
vendored
Normal file
240
node_modules/drizzle-orm/mysql2/session.js
generated
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
import { once } from "node:events";
|
||||
import { Column } from "../column.js";
|
||||
import { entityKind, is } from "../entity.js";
|
||||
import { NoopLogger } from "../logger.js";
|
||||
import {
|
||||
MySqlPreparedQuery,
|
||||
MySqlSession,
|
||||
MySqlTransaction
|
||||
} from "../mysql-core/session.js";
|
||||
import { fillPlaceholders, sql } from "../sql/sql.js";
|
||||
import { mapResultRow } from "../utils.js";
|
||||
class MySql2PreparedQuery extends MySqlPreparedQuery {
|
||||
constructor(client, queryString, params, logger, fields, customResultMapper, generatedIds, returningIds) {
|
||||
super();
|
||||
this.client = client;
|
||||
this.params = params;
|
||||
this.logger = logger;
|
||||
this.fields = fields;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.generatedIds = generatedIds;
|
||||
this.returningIds = returningIds;
|
||||
this.rawQuery = {
|
||||
sql: queryString,
|
||||
// rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
||||
this.query = {
|
||||
sql: queryString,
|
||||
rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
};
|
||||
}
|
||||
static [entityKind] = "MySql2PreparedQuery";
|
||||
rawQuery;
|
||||
query;
|
||||
async execute(placeholderValues = {}) {
|
||||
const params = fillPlaceholders(this.params, placeholderValues);
|
||||
this.logger.logQuery(this.rawQuery.sql, params);
|
||||
const { fields, client, rawQuery, query, joinsNotNullableMap, customResultMapper, returningIds, generatedIds } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const res = await client.query(rawQuery, params);
|
||||
const insertId = res[0].insertId;
|
||||
const affectedRows = res[0].affectedRows;
|
||||
if (returningIds) {
|
||||
const returningResponse = [];
|
||||
let j = 0;
|
||||
for (let i = insertId; i < insertId + affectedRows; i++) {
|
||||
for (const column of returningIds) {
|
||||
const key = returningIds[0].path[0];
|
||||
if (is(column.field, Column)) {
|
||||
if (column.field.primary && column.field.autoIncrement) {
|
||||
returningResponse.push({ [key]: i });
|
||||
}
|
||||
if (column.field.defaultFn && generatedIds) {
|
||||
returningResponse.push({ [key]: generatedIds[j][key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return returningResponse;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
const result = await client.query(query, params);
|
||||
const rows = result[0];
|
||||
if (customResultMapper) {
|
||||
return customResultMapper(rows);
|
||||
}
|
||||
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
||||
}
|
||||
async *iterator(placeholderValues = {}) {
|
||||
const params = fillPlaceholders(this.params, placeholderValues);
|
||||
const conn = (isPool(this.client) ? await this.client.getConnection() : this.client).connection;
|
||||
const { fields, query, rawQuery, joinsNotNullableMap, client, customResultMapper } = this;
|
||||
const hasRowsMapper = Boolean(fields || customResultMapper);
|
||||
const driverQuery = hasRowsMapper ? conn.query(query, params) : conn.query(rawQuery, params);
|
||||
const stream = driverQuery.stream();
|
||||
function dataListener() {
|
||||
stream.pause();
|
||||
}
|
||||
stream.on("data", dataListener);
|
||||
try {
|
||||
const onEnd = once(stream, "end");
|
||||
const onError = once(stream, "error");
|
||||
while (true) {
|
||||
stream.resume();
|
||||
const row = await Promise.race([onEnd, onError, new Promise((resolve) => stream.once("data", resolve))]);
|
||||
if (row === void 0 || Array.isArray(row) && row.length === 0) {
|
||||
break;
|
||||
} else if (row instanceof Error) {
|
||||
throw row;
|
||||
} else {
|
||||
if (hasRowsMapper) {
|
||||
if (customResultMapper) {
|
||||
const mappedRow = customResultMapper([row]);
|
||||
yield Array.isArray(mappedRow) ? mappedRow[0] : mappedRow;
|
||||
} else {
|
||||
yield mapResultRow(fields, row, joinsNotNullableMap);
|
||||
}
|
||||
} else {
|
||||
yield row;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
stream.off("data", dataListener);
|
||||
if (isPool(client)) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class MySql2Session extends MySqlSession {
|
||||
constructor(client, dialect, schema, options) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new NoopLogger();
|
||||
this.mode = options.mode;
|
||||
}
|
||||
static [entityKind] = "MySql2Session";
|
||||
logger;
|
||||
mode;
|
||||
prepareQuery(query, fields, customResultMapper, generatedIds, returningIds) {
|
||||
return new MySql2PreparedQuery(
|
||||
this.client,
|
||||
query.sql,
|
||||
query.params,
|
||||
this.logger,
|
||||
fields,
|
||||
customResultMapper,
|
||||
generatedIds,
|
||||
returningIds
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* What is its purpose?
|
||||
*/
|
||||
async query(query, params) {
|
||||
this.logger.logQuery(query, params);
|
||||
const result = await this.client.query({
|
||||
sql: query,
|
||||
values: params,
|
||||
rowsAsArray: true,
|
||||
typeCast: function(field, next) {
|
||||
if (field.type === "TIMESTAMP" || field.type === "DATETIME" || field.type === "DATE") {
|
||||
return field.string();
|
||||
}
|
||||
return next();
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
all(query) {
|
||||
const querySql = this.dialect.sqlToQuery(query);
|
||||
this.logger.logQuery(querySql.sql, querySql.params);
|
||||
return this.client.execute(querySql.sql, querySql.params).then((result) => result[0]);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
const session = isPool(this.client) ? new MySql2Session(
|
||||
await this.client.getConnection(),
|
||||
this.dialect,
|
||||
this.schema,
|
||||
this.options
|
||||
) : this;
|
||||
const tx = new MySql2Transaction(
|
||||
this.dialect,
|
||||
session,
|
||||
this.schema,
|
||||
0,
|
||||
this.mode
|
||||
);
|
||||
if (config) {
|
||||
const setTransactionConfigSql = this.getSetTransactionSQL(config);
|
||||
if (setTransactionConfigSql) {
|
||||
await tx.execute(setTransactionConfigSql);
|
||||
}
|
||||
const startTransactionSql = this.getStartTransactionSQL(config);
|
||||
await (startTransactionSql ? tx.execute(startTransactionSql) : tx.execute(sql`begin`));
|
||||
} else {
|
||||
await tx.execute(sql`begin`);
|
||||
}
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(sql`commit`);
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(sql`rollback`);
|
||||
throw err;
|
||||
} finally {
|
||||
if (isPool(this.client)) {
|
||||
session.client.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class MySql2Transaction extends MySqlTransaction {
|
||||
static [entityKind] = "MySql2Transaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex + 1}`;
|
||||
const tx = new MySql2Transaction(
|
||||
this.dialect,
|
||||
this.session,
|
||||
this.schema,
|
||||
this.nestedIndex + 1,
|
||||
this.mode
|
||||
);
|
||||
await tx.execute(sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await tx.execute(sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
function isPool(client) {
|
||||
return "getConnection" in client;
|
||||
}
|
||||
export {
|
||||
MySql2PreparedQuery,
|
||||
MySql2Session,
|
||||
MySql2Transaction
|
||||
};
|
||||
//# sourceMappingURL=session.js.map
|
||||
1
node_modules/drizzle-orm/mysql2/session.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/mysql2/session.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user