Initial commit
This commit is contained in:
67
node_modules/drizzle-orm/d1/driver.cjs
generated
vendored
Normal file
67
node_modules/drizzle-orm/d1/driver.cjs
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
"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, {
|
||||
DrizzleD1Database: () => DrizzleD1Database,
|
||||
drizzle: () => drizzle
|
||||
});
|
||||
module.exports = __toCommonJS(driver_exports);
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_relations = require("../relations.cjs");
|
||||
var import_db = require("../sqlite-core/db.cjs");
|
||||
var import_dialect = require("../sqlite-core/dialect.cjs");
|
||||
var import_session = require("./session.cjs");
|
||||
class DrizzleD1Database extends import_db.BaseSQLiteDatabase {
|
||||
static [import_entity.entityKind] = "D1Database";
|
||||
async batch(batch) {
|
||||
return this.session.batch(batch);
|
||||
}
|
||||
}
|
||||
function drizzle(client, config = {}) {
|
||||
const dialect = new import_dialect.SQLiteAsyncDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new import_logger.DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
const tablesConfig = (0, import_relations.extractTablesRelationalConfig)(
|
||||
config.schema,
|
||||
import_relations.createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const session = new import_session.SQLiteD1Session(client, dialect, schema, { logger });
|
||||
const db = new DrizzleD1Database("async", dialect, session, schema);
|
||||
db.$client = client;
|
||||
return db;
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
DrizzleD1Database,
|
||||
drizzle
|
||||
});
|
||||
//# sourceMappingURL=driver.cjs.map
|
||||
1
node_modules/drizzle-orm/d1/driver.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/driver.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/driver.ts"],"sourcesContent":["/// <reference types=\"@cloudflare/workers-types\" />\nimport type { D1Database as MiniflareD1Database } from '@miniflare/d1';\nimport type { BatchItem, BatchResponse } from '~/batch.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype ExtractTablesWithRelations,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig, IfNotImported } from '~/utils.ts';\nimport { SQLiteD1Session } from './session.ts';\n\nexport type AnyD1Database = IfNotImported<\n\tD1Database,\n\tMiniflareD1Database,\n\tD1Database | IfNotImported<MiniflareD1Database, never, MiniflareD1Database>\n>;\n\nexport class DrizzleD1Database<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends BaseSQLiteDatabase<'async', D1Result, TSchema> {\n\tstatic override readonly [entityKind]: string = 'D1Database';\n\n\t/** @internal */\n\tdeclare readonly session: SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>;\n\n\tasync batch<U extends BatchItem<'sqlite'>, T extends Readonly<[U, ...U[]]>>(\n\t\tbatch: T,\n\t): Promise<BatchResponse<T>> {\n\t\treturn this.session.batch(batch) as Promise<BatchResponse<T>>;\n\t}\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnyD1Database = AnyD1Database,\n>(\n\tclient: TClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): DrizzleD1Database<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SQLiteAsyncDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst session = new SQLiteD1Session(client as D1Database, dialect, schema, { logger });\n\tconst db = new DrizzleD1Database('async', dialect, session, schema) as DrizzleD1Database<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA2B;AAC3B,oBAA8B;AAC9B,uBAMO;AACP,gBAAmC;AACnC,qBAAmC;AAEnC,qBAAgC;AAQzB,MAAM,0BAEH,6BAA+C;AAAA,EACxD,QAA0B,wBAAU,IAAY;AAAA,EAKhD,MAAM,MACL,OAC4B;AAC5B,WAAO,KAAK,QAAQ,MAAM,KAAK;AAAA,EAChC;AACD;AAEO,SAAS,QAIf,QACA,SAAiC,CAAC,GAGjC;AACD,QAAM,UAAU,IAAI,kCAAmB,EAAE,QAAQ,OAAO,OAAO,CAAC;AAChE,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,4BAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,mBAAe;AAAA,MACpB,OAAO;AAAA,MACP;AAAA,IACD;AACA,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,UAAU,IAAI,+BAAgB,QAAsB,SAAS,QAAQ,EAAE,OAAO,CAAC;AACrF,QAAM,KAAK,IAAI,kBAAkB,SAAS,SAAS,SAAS,MAAM;AAClE,EAAO,GAAI,UAAU;AAErB,SAAO;AACR;","names":[]}
|
||||
13
node_modules/drizzle-orm/d1/driver.d.cts
generated
vendored
Normal file
13
node_modules/drizzle-orm/d1/driver.d.cts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import type { D1Database as MiniflareD1Database } from '@miniflare/d1';
|
||||
import type { BatchItem, BatchResponse } from "../batch.cjs";
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import { BaseSQLiteDatabase } from "../sqlite-core/db.cjs";
|
||||
import type { DrizzleConfig, IfNotImported } from "../utils.cjs";
|
||||
export type AnyD1Database = IfNotImported<D1Database, MiniflareD1Database, D1Database | IfNotImported<MiniflareD1Database, never, MiniflareD1Database>>;
|
||||
export declare class DrizzleD1Database<TSchema extends Record<string, unknown> = Record<string, never>> extends BaseSQLiteDatabase<'async', D1Result, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
batch<U extends BatchItem<'sqlite'>, T extends Readonly<[U, ...U[]]>>(batch: T): Promise<BatchResponse<T>>;
|
||||
}
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends AnyD1Database = AnyD1Database>(client: TClient, config?: DrizzleConfig<TSchema>): DrizzleD1Database<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
13
node_modules/drizzle-orm/d1/driver.d.ts
generated
vendored
Normal file
13
node_modules/drizzle-orm/d1/driver.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import type { D1Database as MiniflareD1Database } from '@miniflare/d1';
|
||||
import type { BatchItem, BatchResponse } from "../batch.js";
|
||||
import { entityKind } from "../entity.js";
|
||||
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
||||
import type { DrizzleConfig, IfNotImported } from "../utils.js";
|
||||
export type AnyD1Database = IfNotImported<D1Database, MiniflareD1Database, D1Database | IfNotImported<MiniflareD1Database, never, MiniflareD1Database>>;
|
||||
export declare class DrizzleD1Database<TSchema extends Record<string, unknown> = Record<string, never>> extends BaseSQLiteDatabase<'async', D1Result, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
batch<U extends BatchItem<'sqlite'>, T extends Readonly<[U, ...U[]]>>(batch: T): Promise<BatchResponse<T>>;
|
||||
}
|
||||
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends AnyD1Database = AnyD1Database>(client: TClient, config?: DrizzleConfig<TSchema>): DrizzleD1Database<TSchema> & {
|
||||
$client: TClient;
|
||||
};
|
||||
45
node_modules/drizzle-orm/d1/driver.js
generated
vendored
Normal file
45
node_modules/drizzle-orm/d1/driver.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
import { entityKind } from "../entity.js";
|
||||
import { DefaultLogger } from "../logger.js";
|
||||
import {
|
||||
createTableRelationsHelpers,
|
||||
extractTablesRelationalConfig
|
||||
} from "../relations.js";
|
||||
import { BaseSQLiteDatabase } from "../sqlite-core/db.js";
|
||||
import { SQLiteAsyncDialect } from "../sqlite-core/dialect.js";
|
||||
import { SQLiteD1Session } from "./session.js";
|
||||
class DrizzleD1Database extends BaseSQLiteDatabase {
|
||||
static [entityKind] = "D1Database";
|
||||
async batch(batch) {
|
||||
return this.session.batch(batch);
|
||||
}
|
||||
}
|
||||
function drizzle(client, config = {}) {
|
||||
const dialect = new SQLiteAsyncDialect({ casing: config.casing });
|
||||
let logger;
|
||||
if (config.logger === true) {
|
||||
logger = new DefaultLogger();
|
||||
} else if (config.logger !== false) {
|
||||
logger = config.logger;
|
||||
}
|
||||
let schema;
|
||||
if (config.schema) {
|
||||
const tablesConfig = extractTablesRelationalConfig(
|
||||
config.schema,
|
||||
createTableRelationsHelpers
|
||||
);
|
||||
schema = {
|
||||
fullSchema: config.schema,
|
||||
schema: tablesConfig.tables,
|
||||
tableNamesMap: tablesConfig.tableNamesMap
|
||||
};
|
||||
}
|
||||
const session = new SQLiteD1Session(client, dialect, schema, { logger });
|
||||
const db = new DrizzleD1Database("async", dialect, session, schema);
|
||||
db.$client = client;
|
||||
return db;
|
||||
}
|
||||
export {
|
||||
DrizzleD1Database,
|
||||
drizzle
|
||||
};
|
||||
//# sourceMappingURL=driver.js.map
|
||||
1
node_modules/drizzle-orm/d1/driver.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/driver.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/driver.ts"],"sourcesContent":["/// <reference types=\"@cloudflare/workers-types\" />\nimport type { D1Database as MiniflareD1Database } from '@miniflare/d1';\nimport type { BatchItem, BatchResponse } from '~/batch.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype ExtractTablesWithRelations,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';\nimport { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleConfig, IfNotImported } from '~/utils.ts';\nimport { SQLiteD1Session } from './session.ts';\n\nexport type AnyD1Database = IfNotImported<\n\tD1Database,\n\tMiniflareD1Database,\n\tD1Database | IfNotImported<MiniflareD1Database, never, MiniflareD1Database>\n>;\n\nexport class DrizzleD1Database<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends BaseSQLiteDatabase<'async', D1Result, TSchema> {\n\tstatic override readonly [entityKind]: string = 'D1Database';\n\n\t/** @internal */\n\tdeclare readonly session: SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>;\n\n\tasync batch<U extends BatchItem<'sqlite'>, T extends Readonly<[U, ...U[]]>>(\n\t\tbatch: T,\n\t): Promise<BatchResponse<T>> {\n\t\treturn this.session.batch(batch) as Promise<BatchResponse<T>>;\n\t}\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends AnyD1Database = AnyD1Database,\n>(\n\tclient: TClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): DrizzleD1Database<TSchema> & {\n\t$client: TClient;\n} {\n\tconst dialect = new SQLiteAsyncDialect({ casing: config.casing });\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tlet schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;\n\tif (config.schema) {\n\t\tconst tablesConfig = extractTablesRelationalConfig(\n\t\t\tconfig.schema,\n\t\t\tcreateTableRelationsHelpers,\n\t\t);\n\t\tschema = {\n\t\t\tfullSchema: config.schema,\n\t\t\tschema: tablesConfig.tables,\n\t\t\ttableNamesMap: tablesConfig.tableNamesMap,\n\t\t};\n\t}\n\n\tconst session = new SQLiteD1Session(client as D1Database, dialect, schema, { logger });\n\tconst db = new DrizzleD1Database('async', dialect, session, schema) as DrizzleD1Database<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n"],"mappings":"AAGA,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B;AAAA,EACC;AAAA,EACA;AAAA,OAIM;AACP,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB;AAQzB,MAAM,0BAEH,mBAA+C;AAAA,EACxD,QAA0B,UAAU,IAAY;AAAA,EAKhD,MAAM,MACL,OAC4B;AAC5B,WAAO,KAAK,QAAQ,MAAM,KAAK;AAAA,EAChC;AACD;AAEO,SAAS,QAIf,QACA,SAAiC,CAAC,GAGjC;AACD,QAAM,UAAU,IAAI,mBAAmB,EAAE,QAAQ,OAAO,OAAO,CAAC;AAChE,MAAI;AACJ,MAAI,OAAO,WAAW,MAAM;AAC3B,aAAS,IAAI,cAAc;AAAA,EAC5B,WAAW,OAAO,WAAW,OAAO;AACnC,aAAS,OAAO;AAAA,EACjB;AAEA,MAAI;AACJ,MAAI,OAAO,QAAQ;AAClB,UAAM,eAAe;AAAA,MACpB,OAAO;AAAA,MACP;AAAA,IACD;AACA,aAAS;AAAA,MACR,YAAY,OAAO;AAAA,MACnB,QAAQ,aAAa;AAAA,MACrB,eAAe,aAAa;AAAA,IAC7B;AAAA,EACD;AAEA,QAAM,UAAU,IAAI,gBAAgB,QAAsB,SAAS,QAAQ,EAAE,OAAO,CAAC;AACrF,QAAM,KAAK,IAAI,kBAAkB,SAAS,SAAS,SAAS,MAAM;AAClE,EAAO,GAAI,UAAU;AAErB,SAAO;AACR;","names":[]}
|
||||
25
node_modules/drizzle-orm/d1/index.cjs
generated
vendored
Normal file
25
node_modules/drizzle-orm/d1/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 d1_exports = {};
|
||||
module.exports = __toCommonJS(d1_exports);
|
||||
__reExport(d1_exports, require("./driver.cjs"), module.exports);
|
||||
__reExport(d1_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/d1/index.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/index.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAc,wBAAd;AACA,uBAAc,yBADd;","names":[]}
|
||||
2
node_modules/drizzle-orm/d1/index.d.cts
generated
vendored
Normal file
2
node_modules/drizzle-orm/d1/index.d.cts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./driver.cjs";
|
||||
export * from "./session.cjs";
|
||||
2
node_modules/drizzle-orm/d1/index.d.ts
generated
vendored
Normal file
2
node_modules/drizzle-orm/d1/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./driver.js";
|
||||
export * from "./session.js";
|
||||
3
node_modules/drizzle-orm/d1/index.js
generated
vendored
Normal file
3
node_modules/drizzle-orm/d1/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/d1/index.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/index.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/index.ts"],"sourcesContent":["export * from './driver.ts';\nexport * from './session.ts';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
||||
62
node_modules/drizzle-orm/d1/migrator.cjs
generated
vendored
Normal file
62
node_modules/drizzle-orm/d1/migrator.cjs
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
"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");
|
||||
var import_sql = require("../sql/sql.cjs");
|
||||
async function migrate(db, config) {
|
||||
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
||||
const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";
|
||||
const migrationTableCreate = import_sql.sql`
|
||||
CREATE TABLE IF NOT EXISTS ${import_sql.sql.identifier(migrationsTable)} (
|
||||
id SERIAL PRIMARY KEY,
|
||||
hash text NOT NULL,
|
||||
created_at numeric
|
||||
)
|
||||
`;
|
||||
await db.session.run(migrationTableCreate);
|
||||
const dbMigrations = await db.values(
|
||||
import_sql.sql`SELECT id, hash, created_at FROM ${import_sql.sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
||||
);
|
||||
const lastDbMigration = dbMigrations[0] ?? void 0;
|
||||
const statementToBatch = [];
|
||||
for (const migration of migrations) {
|
||||
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
||||
for (const stmt of migration.sql) {
|
||||
statementToBatch.push(db.run(import_sql.sql.raw(stmt)));
|
||||
}
|
||||
statementToBatch.push(
|
||||
db.run(
|
||||
import_sql.sql`INSERT INTO ${import_sql.sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${import_sql.sql.raw(`'${migration.hash}'`)}, ${import_sql.sql.raw(`${migration.folderMillis}`)})`
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (statementToBatch.length > 0) {
|
||||
await db.session.batch(statementToBatch);
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
migrate
|
||||
});
|
||||
//# sourceMappingURL=migrator.cjs.map
|
||||
1
node_modules/drizzle-orm/d1/migrator.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/migrator.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { DrizzleD1Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: DrizzleD1Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at numeric\n\t\t)\n\t`;\n\tawait db.session.run(migrationTableCreate);\n\n\tconst dbMigrations = await db.values<[number, string, string]>(\n\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\tconst statementToBatch = [];\n\n\tfor (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tstatementToBatch.push(db.run(sql.raw(stmt)));\n\t\t\t}\n\n\t\t\tstatementToBatch.push(\n\t\t\t\tdb.run(\n\t\t\t\t\tsql`INSERT INTO ${sql.identifier(migrationsTable)} (\"hash\", \"created_at\") VALUES(${\n\t\t\t\t\t\tsql.raw(`'${migration.hash}'`)\n\t\t\t\t\t}, ${sql.raw(`${migration.folderMillis}`)})`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tif (statementToBatch.length > 0) {\n\t\tawait db.session.batch(statementToBatch);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AACnC,iBAAoB;AAGpB,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,QAAM,kBAAkB,OAAO,mBAAmB;AAElD,QAAM,uBAAuB;AAAA,+BACC,eAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,IAAI,oBAAoB;AAEzC,QAAM,eAAe,MAAM,GAAG;AAAA,IAC7B,kDAAuC,eAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC,KAAK;AAE3C,QAAM,mBAAmB,CAAC;AAE1B,aAAW,aAAa,YAAY;AACnC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,IAAK,UAAU,cAAc;AAC7E,iBAAW,QAAQ,UAAU,KAAK;AACjC,yBAAiB,KAAK,GAAG,IAAI,eAAI,IAAI,IAAI,CAAC,CAAC;AAAA,MAC5C;AAEA,uBAAiB;AAAA,QAChB,GAAG;AAAA,UACF,6BAAkB,eAAI,WAAW,eAAe,CAAC,kCAChD,eAAI,IAAI,IAAI,UAAU,IAAI,GAAG,CAC9B,KAAK,eAAI,IAAI,GAAG,UAAU,YAAY,EAAE,CAAC;AAAA,QAC1C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI,iBAAiB,SAAS,GAAG;AAChC,UAAM,GAAG,QAAQ,MAAM,gBAAgB;AAAA,EACxC;AACD;","names":[]}
|
||||
3
node_modules/drizzle-orm/d1/migrator.d.cts
generated
vendored
Normal file
3
node_modules/drizzle-orm/d1/migrator.d.cts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.cjs";
|
||||
import type { DrizzleD1Database } from "./driver.cjs";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: DrizzleD1Database<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
3
node_modules/drizzle-orm/d1/migrator.d.ts
generated
vendored
Normal file
3
node_modules/drizzle-orm/d1/migrator.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import type { MigrationConfig } from "../migrator.js";
|
||||
import type { DrizzleD1Database } from "./driver.js";
|
||||
export declare function migrate<TSchema extends Record<string, unknown>>(db: DrizzleD1Database<TSchema>, config: MigrationConfig): Promise<void>;
|
||||
38
node_modules/drizzle-orm/d1/migrator.js
generated
vendored
Normal file
38
node_modules/drizzle-orm/d1/migrator.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import { readMigrationFiles } from "../migrator.js";
|
||||
import { sql } from "../sql/sql.js";
|
||||
async function migrate(db, config) {
|
||||
const migrations = readMigrationFiles(config);
|
||||
const migrationsTable = config.migrationsTable ?? "__drizzle_migrations";
|
||||
const migrationTableCreate = sql`
|
||||
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
||||
id SERIAL PRIMARY KEY,
|
||||
hash text NOT NULL,
|
||||
created_at numeric
|
||||
)
|
||||
`;
|
||||
await db.session.run(migrationTableCreate);
|
||||
const dbMigrations = await db.values(
|
||||
sql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`
|
||||
);
|
||||
const lastDbMigration = dbMigrations[0] ?? void 0;
|
||||
const statementToBatch = [];
|
||||
for (const migration of migrations) {
|
||||
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
||||
for (const stmt of migration.sql) {
|
||||
statementToBatch.push(db.run(sql.raw(stmt)));
|
||||
}
|
||||
statementToBatch.push(
|
||||
db.run(
|
||||
sql`INSERT INTO ${sql.identifier(migrationsTable)} ("hash", "created_at") VALUES(${sql.raw(`'${migration.hash}'`)}, ${sql.raw(`${migration.folderMillis}`)})`
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (statementToBatch.length > 0) {
|
||||
await db.session.batch(statementToBatch);
|
||||
}
|
||||
}
|
||||
export {
|
||||
migrate
|
||||
};
|
||||
//# sourceMappingURL=migrator.js.map
|
||||
1
node_modules/drizzle-orm/d1/migrator.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/migrator.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/d1/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { sql } from '~/sql/sql.ts';\nimport type { DrizzleD1Database } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>>(\n\tdb: DrizzleD1Database<TSchema>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\n\tconst migrationTableCreate = sql`\n\t\tCREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\thash text NOT NULL,\n\t\t\tcreated_at numeric\n\t\t)\n\t`;\n\tawait db.session.run(migrationTableCreate);\n\n\tconst dbMigrations = await db.values<[number, string, string]>(\n\t\tsql`SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`,\n\t);\n\n\tconst lastDbMigration = dbMigrations[0] ?? undefined;\n\n\tconst statementToBatch = [];\n\n\tfor (const migration of migrations) {\n\t\tif (!lastDbMigration || Number(lastDbMigration[2])! < migration.folderMillis) {\n\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\tstatementToBatch.push(db.run(sql.raw(stmt)));\n\t\t\t}\n\n\t\t\tstatementToBatch.push(\n\t\t\t\tdb.run(\n\t\t\t\t\tsql`INSERT INTO ${sql.identifier(migrationsTable)} (\"hash\", \"created_at\") VALUES(${\n\t\t\t\t\t\tsql.raw(`'${migration.hash}'`)\n\t\t\t\t\t}, ${sql.raw(`${migration.folderMillis}`)})`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tif (statementToBatch.length > 0) {\n\t\tawait db.session.batch(statementToBatch);\n\t}\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AACnC,SAAS,WAAW;AAGpB,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,QAAM,kBAAkB,OAAO,mBAAmB;AAElD,QAAM,uBAAuB;AAAA,+BACC,IAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,QAAM,GAAG,QAAQ,IAAI,oBAAoB;AAEzC,QAAM,eAAe,MAAM,GAAG;AAAA,IAC7B,uCAAuC,IAAI,WAAW,eAAe,CAAC;AAAA,EACvE;AAEA,QAAM,kBAAkB,aAAa,CAAC,KAAK;AAE3C,QAAM,mBAAmB,CAAC;AAE1B,aAAW,aAAa,YAAY;AACnC,QAAI,CAAC,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,IAAK,UAAU,cAAc;AAC7E,iBAAW,QAAQ,UAAU,KAAK;AACjC,yBAAiB,KAAK,GAAG,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;AAAA,MAC5C;AAEA,uBAAiB;AAAA,QAChB,GAAG;AAAA,UACF,kBAAkB,IAAI,WAAW,eAAe,CAAC,kCAChD,IAAI,IAAI,IAAI,UAAU,IAAI,GAAG,CAC9B,KAAK,IAAI,IAAI,GAAG,UAAU,YAAY,EAAE,CAAC;AAAA,QAC1C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,MAAI,iBAAiB,SAAS,GAAG;AAChC,UAAM,GAAG,QAAQ,MAAM,gBAAgB;AAAA,EACxC;AACD;","names":[]}
|
||||
206
node_modules/drizzle-orm/d1/session.cjs
generated
vendored
Normal file
206
node_modules/drizzle-orm/d1/session.cjs
generated
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
"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, {
|
||||
D1PreparedQuery: () => D1PreparedQuery,
|
||||
D1Transaction: () => D1Transaction,
|
||||
SQLiteD1Session: () => SQLiteD1Session
|
||||
});
|
||||
module.exports = __toCommonJS(session_exports);
|
||||
var import_entity = require("../entity.cjs");
|
||||
var import_logger = require("../logger.cjs");
|
||||
var import_sql = require("../sql/sql.cjs");
|
||||
var import_sqlite_core = require("../sqlite-core/index.cjs");
|
||||
var import_session = require("../sqlite-core/session.cjs");
|
||||
var import_utils = require("../utils.cjs");
|
||||
class SQLiteD1Session extends import_session.SQLiteSession {
|
||||
constructor(client, dialect, schema, options = {}) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new import_logger.NoopLogger();
|
||||
}
|
||||
static [import_entity.entityKind] = "SQLiteD1Session";
|
||||
logger;
|
||||
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper) {
|
||||
const stmt = this.client.prepare(query.sql);
|
||||
return new D1PreparedQuery(
|
||||
stmt,
|
||||
query,
|
||||
this.logger,
|
||||
fields,
|
||||
executeMethod,
|
||||
isResponseInArrayMode,
|
||||
customResultMapper
|
||||
);
|
||||
}
|
||||
async batch(queries) {
|
||||
const preparedQueries = [];
|
||||
const builtQueries = [];
|
||||
for (const query of queries) {
|
||||
const preparedQuery = query._prepare();
|
||||
const builtQuery = preparedQuery.getQuery();
|
||||
preparedQueries.push(preparedQuery);
|
||||
if (builtQuery.params.length > 0) {
|
||||
builtQueries.push(preparedQuery.stmt.bind(...builtQuery.params));
|
||||
} else {
|
||||
const builtQuery2 = preparedQuery.getQuery();
|
||||
builtQueries.push(
|
||||
this.client.prepare(builtQuery2.sql).bind(...builtQuery2.params)
|
||||
);
|
||||
}
|
||||
}
|
||||
const batchResults = await this.client.batch(builtQueries);
|
||||
return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
|
||||
}
|
||||
extractRawAllValueFromBatchResult(result) {
|
||||
return result.results;
|
||||
}
|
||||
extractRawGetValueFromBatchResult(result) {
|
||||
return result.results[0];
|
||||
}
|
||||
extractRawValuesValueFromBatchResult(result) {
|
||||
return d1ToRawMapping(result.results);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
const tx = new D1Transaction("async", this.dialect, this, this.schema);
|
||||
await this.run(import_sql.sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await this.run(import_sql.sql`commit`);
|
||||
return result;
|
||||
} catch (err) {
|
||||
await this.run(import_sql.sql`rollback`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
class D1Transaction extends import_sqlite_core.SQLiteTransaction {
|
||||
static [import_entity.entityKind] = "D1Transaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex}`;
|
||||
const tx = new D1Transaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
||||
await this.session.run(import_sql.sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await this.session.run(import_sql.sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await this.session.run(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
function d1ToRawMapping(results) {
|
||||
const rows = [];
|
||||
for (const row of results) {
|
||||
const entry = Object.keys(row).map((k) => row[k]);
|
||||
rows.push(entry);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
class D1PreparedQuery extends import_session.SQLitePreparedQuery {
|
||||
constructor(stmt, query, logger, fields, executeMethod, _isResponseInArrayMode, customResultMapper) {
|
||||
super("async", executeMethod, query);
|
||||
this.logger = logger;
|
||||
this._isResponseInArrayMode = _isResponseInArrayMode;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.fields = fields;
|
||||
this.stmt = stmt;
|
||||
}
|
||||
static [import_entity.entityKind] = "D1PreparedQuery";
|
||||
/** @internal */
|
||||
customResultMapper;
|
||||
/** @internal */
|
||||
fields;
|
||||
/** @internal */
|
||||
stmt;
|
||||
run(placeholderValues) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
|
||||
this.logger.logQuery(this.query.sql, params);
|
||||
return this.stmt.bind(...params).run();
|
||||
}
|
||||
async all(placeholderValues) {
|
||||
const { fields, query, logger, stmt, customResultMapper } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
||||
logger.logQuery(query.sql, params);
|
||||
return stmt.bind(...params).all().then(({ results }) => this.mapAllResult(results));
|
||||
}
|
||||
const rows = await this.values(placeholderValues);
|
||||
return this.mapAllResult(rows);
|
||||
}
|
||||
mapAllResult(rows, isFromBatch) {
|
||||
if (isFromBatch) {
|
||||
rows = d1ToRawMapping(rows.results);
|
||||
}
|
||||
if (!this.fields && !this.customResultMapper) {
|
||||
return rows;
|
||||
}
|
||||
if (this.customResultMapper) {
|
||||
return this.customResultMapper(rows);
|
||||
}
|
||||
return rows.map((row) => (0, import_utils.mapResultRow)(this.fields, row, this.joinsNotNullableMap));
|
||||
}
|
||||
async get(placeholderValues) {
|
||||
const { fields, joinsNotNullableMap, query, logger, stmt, customResultMapper } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
||||
logger.logQuery(query.sql, params);
|
||||
return stmt.bind(...params).all().then(({ results }) => results[0]);
|
||||
}
|
||||
const rows = await this.values(placeholderValues);
|
||||
if (!rows[0]) {
|
||||
return void 0;
|
||||
}
|
||||
if (customResultMapper) {
|
||||
return customResultMapper(rows);
|
||||
}
|
||||
return (0, import_utils.mapResultRow)(fields, rows[0], joinsNotNullableMap);
|
||||
}
|
||||
mapGetResult(result, isFromBatch) {
|
||||
if (isFromBatch) {
|
||||
result = d1ToRawMapping(result.results)[0];
|
||||
}
|
||||
if (!this.fields && !this.customResultMapper) {
|
||||
return result;
|
||||
}
|
||||
if (this.customResultMapper) {
|
||||
return this.customResultMapper([result]);
|
||||
}
|
||||
return (0, import_utils.mapResultRow)(this.fields, result, this.joinsNotNullableMap);
|
||||
}
|
||||
values(placeholderValues) {
|
||||
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
|
||||
this.logger.logQuery(this.query.sql, params);
|
||||
return this.stmt.bind(...params).raw();
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return this._isResponseInArrayMode;
|
||||
}
|
||||
}
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
D1PreparedQuery,
|
||||
D1Transaction,
|
||||
SQLiteD1Session
|
||||
});
|
||||
//# sourceMappingURL=session.cjs.map
|
||||
1
node_modules/drizzle-orm/d1/session.cjs.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/session.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
52
node_modules/drizzle-orm/d1/session.d.cts
generated
vendored
Normal file
52
node_modules/drizzle-orm/d1/session.d.cts
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
import type { BatchItem } from "../batch.cjs";
|
||||
import { entityKind } from "../entity.cjs";
|
||||
import type { Logger } from "../logger.cjs";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
||||
import { type Query } from "../sql/sql.cjs";
|
||||
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.cjs";
|
||||
import { SQLiteTransaction } from "../sqlite-core/index.cjs";
|
||||
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.cjs";
|
||||
import type { PreparedQueryConfig as PreparedQueryConfigBase, SQLiteExecuteMethod, SQLiteTransactionConfig } from "../sqlite-core/session.cjs";
|
||||
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.cjs";
|
||||
export interface SQLiteD1SessionOptions {
|
||||
logger?: Logger;
|
||||
}
|
||||
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
||||
export declare class SQLiteD1Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<'async', D1Result, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
constructor(client: D1Database, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: SQLiteD1SessionOptions);
|
||||
prepareQuery(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown): D1PreparedQuery;
|
||||
batch<T extends BatchItem<'sqlite'>[] | readonly BatchItem<'sqlite'>[]>(queries: T): Promise<unknown[]>;
|
||||
extractRawAllValueFromBatchResult(result: unknown): unknown;
|
||||
extractRawGetValueFromBatchResult(result: unknown): unknown;
|
||||
extractRawValuesValueFromBatchResult(result: unknown): unknown;
|
||||
transaction<T>(transaction: (tx: D1Transaction<TFullSchema, TSchema>) => T | Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
|
||||
}
|
||||
export declare class D1Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteTransaction<'async', D1Result, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: D1Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export declare class D1PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
|
||||
type: 'async';
|
||||
run: D1Response;
|
||||
all: T['all'];
|
||||
get: T['get'];
|
||||
values: T['values'];
|
||||
execute: T['execute'];
|
||||
}> {
|
||||
private logger;
|
||||
private _isResponseInArrayMode;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(stmt: D1PreparedStatement, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, _isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown);
|
||||
run(placeholderValues?: Record<string, unknown>): Promise<D1Response>;
|
||||
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
||||
mapAllResult(rows: unknown, isFromBatch?: boolean): unknown;
|
||||
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
||||
mapGetResult(result: unknown, isFromBatch?: boolean): unknown;
|
||||
values<T extends any[] = unknown[]>(placeholderValues?: Record<string, unknown>): Promise<T[]>;
|
||||
}
|
||||
export {};
|
||||
52
node_modules/drizzle-orm/d1/session.d.ts
generated
vendored
Normal file
52
node_modules/drizzle-orm/d1/session.d.ts
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
import type { BatchItem } from "../batch.js";
|
||||
import { entityKind } from "../entity.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
||||
import { type Query } from "../sql/sql.js";
|
||||
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.js";
|
||||
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
||||
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.js";
|
||||
import type { PreparedQueryConfig as PreparedQueryConfigBase, SQLiteExecuteMethod, SQLiteTransactionConfig } from "../sqlite-core/session.js";
|
||||
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
|
||||
export interface SQLiteD1SessionOptions {
|
||||
logger?: Logger;
|
||||
}
|
||||
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
||||
export declare class SQLiteD1Session<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<'async', D1Result, TFullSchema, TSchema> {
|
||||
private client;
|
||||
private schema;
|
||||
private options;
|
||||
static readonly [entityKind]: string;
|
||||
private logger;
|
||||
constructor(client: D1Database, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: SQLiteD1SessionOptions);
|
||||
prepareQuery(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown): D1PreparedQuery;
|
||||
batch<T extends BatchItem<'sqlite'>[] | readonly BatchItem<'sqlite'>[]>(queries: T): Promise<unknown[]>;
|
||||
extractRawAllValueFromBatchResult(result: unknown): unknown;
|
||||
extractRawGetValueFromBatchResult(result: unknown): unknown;
|
||||
extractRawValuesValueFromBatchResult(result: unknown): unknown;
|
||||
transaction<T>(transaction: (tx: D1Transaction<TFullSchema, TSchema>) => T | Promise<T>, config?: SQLiteTransactionConfig): Promise<T>;
|
||||
}
|
||||
export declare class D1Transaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteTransaction<'async', D1Result, TFullSchema, TSchema> {
|
||||
static readonly [entityKind]: string;
|
||||
transaction<T>(transaction: (tx: D1Transaction<TFullSchema, TSchema>) => Promise<T>): Promise<T>;
|
||||
}
|
||||
export declare class D1PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
|
||||
type: 'async';
|
||||
run: D1Response;
|
||||
all: T['all'];
|
||||
get: T['get'];
|
||||
values: T['values'];
|
||||
execute: T['execute'];
|
||||
}> {
|
||||
private logger;
|
||||
private _isResponseInArrayMode;
|
||||
static readonly [entityKind]: string;
|
||||
constructor(stmt: D1PreparedStatement, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, _isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => unknown);
|
||||
run(placeholderValues?: Record<string, unknown>): Promise<D1Response>;
|
||||
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
||||
mapAllResult(rows: unknown, isFromBatch?: boolean): unknown;
|
||||
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
||||
mapGetResult(result: unknown, isFromBatch?: boolean): unknown;
|
||||
values<T extends any[] = unknown[]>(placeholderValues?: Record<string, unknown>): Promise<T[]>;
|
||||
}
|
||||
export {};
|
||||
180
node_modules/drizzle-orm/d1/session.js
generated
vendored
Normal file
180
node_modules/drizzle-orm/d1/session.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
import { entityKind } from "../entity.js";
|
||||
import { NoopLogger } from "../logger.js";
|
||||
import { fillPlaceholders, sql } from "../sql/sql.js";
|
||||
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
||||
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
|
||||
import { mapResultRow } from "../utils.js";
|
||||
class SQLiteD1Session extends SQLiteSession {
|
||||
constructor(client, dialect, schema, options = {}) {
|
||||
super(dialect);
|
||||
this.client = client;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.logger = options.logger ?? new NoopLogger();
|
||||
}
|
||||
static [entityKind] = "SQLiteD1Session";
|
||||
logger;
|
||||
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper) {
|
||||
const stmt = this.client.prepare(query.sql);
|
||||
return new D1PreparedQuery(
|
||||
stmt,
|
||||
query,
|
||||
this.logger,
|
||||
fields,
|
||||
executeMethod,
|
||||
isResponseInArrayMode,
|
||||
customResultMapper
|
||||
);
|
||||
}
|
||||
async batch(queries) {
|
||||
const preparedQueries = [];
|
||||
const builtQueries = [];
|
||||
for (const query of queries) {
|
||||
const preparedQuery = query._prepare();
|
||||
const builtQuery = preparedQuery.getQuery();
|
||||
preparedQueries.push(preparedQuery);
|
||||
if (builtQuery.params.length > 0) {
|
||||
builtQueries.push(preparedQuery.stmt.bind(...builtQuery.params));
|
||||
} else {
|
||||
const builtQuery2 = preparedQuery.getQuery();
|
||||
builtQueries.push(
|
||||
this.client.prepare(builtQuery2.sql).bind(...builtQuery2.params)
|
||||
);
|
||||
}
|
||||
}
|
||||
const batchResults = await this.client.batch(builtQueries);
|
||||
return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
|
||||
}
|
||||
extractRawAllValueFromBatchResult(result) {
|
||||
return result.results;
|
||||
}
|
||||
extractRawGetValueFromBatchResult(result) {
|
||||
return result.results[0];
|
||||
}
|
||||
extractRawValuesValueFromBatchResult(result) {
|
||||
return d1ToRawMapping(result.results);
|
||||
}
|
||||
async transaction(transaction, config) {
|
||||
const tx = new D1Transaction("async", this.dialect, this, this.schema);
|
||||
await this.run(sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await this.run(sql`commit`);
|
||||
return result;
|
||||
} catch (err) {
|
||||
await this.run(sql`rollback`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
class D1Transaction extends SQLiteTransaction {
|
||||
static [entityKind] = "D1Transaction";
|
||||
async transaction(transaction) {
|
||||
const savepointName = `sp${this.nestedIndex}`;
|
||||
const tx = new D1Transaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
||||
await this.session.run(sql.raw(`savepoint ${savepointName}`));
|
||||
try {
|
||||
const result = await transaction(tx);
|
||||
await this.session.run(sql.raw(`release savepoint ${savepointName}`));
|
||||
return result;
|
||||
} catch (err) {
|
||||
await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
function d1ToRawMapping(results) {
|
||||
const rows = [];
|
||||
for (const row of results) {
|
||||
const entry = Object.keys(row).map((k) => row[k]);
|
||||
rows.push(entry);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
class D1PreparedQuery extends SQLitePreparedQuery {
|
||||
constructor(stmt, query, logger, fields, executeMethod, _isResponseInArrayMode, customResultMapper) {
|
||||
super("async", executeMethod, query);
|
||||
this.logger = logger;
|
||||
this._isResponseInArrayMode = _isResponseInArrayMode;
|
||||
this.customResultMapper = customResultMapper;
|
||||
this.fields = fields;
|
||||
this.stmt = stmt;
|
||||
}
|
||||
static [entityKind] = "D1PreparedQuery";
|
||||
/** @internal */
|
||||
customResultMapper;
|
||||
/** @internal */
|
||||
fields;
|
||||
/** @internal */
|
||||
stmt;
|
||||
run(placeholderValues) {
|
||||
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
||||
this.logger.logQuery(this.query.sql, params);
|
||||
return this.stmt.bind(...params).run();
|
||||
}
|
||||
async all(placeholderValues) {
|
||||
const { fields, query, logger, stmt, customResultMapper } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
||||
logger.logQuery(query.sql, params);
|
||||
return stmt.bind(...params).all().then(({ results }) => this.mapAllResult(results));
|
||||
}
|
||||
const rows = await this.values(placeholderValues);
|
||||
return this.mapAllResult(rows);
|
||||
}
|
||||
mapAllResult(rows, isFromBatch) {
|
||||
if (isFromBatch) {
|
||||
rows = d1ToRawMapping(rows.results);
|
||||
}
|
||||
if (!this.fields && !this.customResultMapper) {
|
||||
return rows;
|
||||
}
|
||||
if (this.customResultMapper) {
|
||||
return this.customResultMapper(rows);
|
||||
}
|
||||
return rows.map((row) => mapResultRow(this.fields, row, this.joinsNotNullableMap));
|
||||
}
|
||||
async get(placeholderValues) {
|
||||
const { fields, joinsNotNullableMap, query, logger, stmt, customResultMapper } = this;
|
||||
if (!fields && !customResultMapper) {
|
||||
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
||||
logger.logQuery(query.sql, params);
|
||||
return stmt.bind(...params).all().then(({ results }) => results[0]);
|
||||
}
|
||||
const rows = await this.values(placeholderValues);
|
||||
if (!rows[0]) {
|
||||
return void 0;
|
||||
}
|
||||
if (customResultMapper) {
|
||||
return customResultMapper(rows);
|
||||
}
|
||||
return mapResultRow(fields, rows[0], joinsNotNullableMap);
|
||||
}
|
||||
mapGetResult(result, isFromBatch) {
|
||||
if (isFromBatch) {
|
||||
result = d1ToRawMapping(result.results)[0];
|
||||
}
|
||||
if (!this.fields && !this.customResultMapper) {
|
||||
return result;
|
||||
}
|
||||
if (this.customResultMapper) {
|
||||
return this.customResultMapper([result]);
|
||||
}
|
||||
return mapResultRow(this.fields, result, this.joinsNotNullableMap);
|
||||
}
|
||||
values(placeholderValues) {
|
||||
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
||||
this.logger.logQuery(this.query.sql, params);
|
||||
return this.stmt.bind(...params).raw();
|
||||
}
|
||||
/** @internal */
|
||||
isResponseInArrayMode() {
|
||||
return this._isResponseInArrayMode;
|
||||
}
|
||||
}
|
||||
export {
|
||||
D1PreparedQuery,
|
||||
D1Transaction,
|
||||
SQLiteD1Session
|
||||
};
|
||||
//# sourceMappingURL=session.js.map
|
||||
1
node_modules/drizzle-orm/d1/session.js.map
generated
vendored
Normal file
1
node_modules/drizzle-orm/d1/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