drizzle-orm 0.30.0 → 0.30.1-e01313e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/expo-sqlite/migrator.cjs +4 -6
- package/expo-sqlite/migrator.cjs.map +1 -1
- package/expo-sqlite/migrator.js +4 -6
- package/expo-sqlite/migrator.js.map +1 -1
- package/libsql/migrator.cjs +29 -2
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.js +29 -2
- package/libsql/migrator.js.map +1 -1
- package/op-sqlite/driver.cjs +56 -0
- package/op-sqlite/driver.cjs.map +1 -0
- package/op-sqlite/driver.d.cts +5 -0
- package/op-sqlite/driver.d.ts +5 -0
- package/op-sqlite/driver.js +35 -0
- package/op-sqlite/driver.js.map +1 -0
- package/op-sqlite/index.cjs +25 -0
- package/op-sqlite/index.cjs.map +1 -0
- package/op-sqlite/index.d.cts +2 -0
- package/op-sqlite/index.d.ts +2 -0
- package/op-sqlite/index.js +3 -0
- package/op-sqlite/index.js.map +1 -0
- package/op-sqlite/migrator.cjs +90 -0
- package/op-sqlite/migrator.cjs.map +1 -0
- package/op-sqlite/migrator.d.cts +29 -0
- package/op-sqlite/migrator.d.ts +29 -0
- package/op-sqlite/migrator.js +65 -0
- package/op-sqlite/migrator.js.map +1 -0
- package/op-sqlite/session.cjs +130 -0
- package/op-sqlite/session.cjs.map +1 -0
- package/op-sqlite/session.d.cts +46 -0
- package/op-sqlite/session.d.ts +46 -0
- package/op-sqlite/session.js +107 -0
- package/op-sqlite/session.js.map +1 -0
- package/package.json +103 -50
- package/sqlite-core/dialect.cjs +1 -1
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.d.cts +1 -1
- package/sqlite-core/dialect.d.ts +1 -1
- package/sqlite-core/dialect.js +1 -1
- package/sqlite-core/dialect.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var session_exports = {};
|
|
20
|
+
__export(session_exports, {
|
|
21
|
+
OPSQLitePreparedQuery: () => OPSQLitePreparedQuery,
|
|
22
|
+
OPSQLiteSession: () => OPSQLiteSession,
|
|
23
|
+
OPSQLiteTransaction: () => OPSQLiteTransaction
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(session_exports);
|
|
26
|
+
var import_entity = require("../entity.cjs");
|
|
27
|
+
var import_logger = require("../logger.cjs");
|
|
28
|
+
var import_sql = require("../sql/sql.cjs");
|
|
29
|
+
var import_sqlite_core = require("../sqlite-core/index.cjs");
|
|
30
|
+
var import_session = require("../sqlite-core/session.cjs");
|
|
31
|
+
var import_utils = require("../utils.cjs");
|
|
32
|
+
class OPSQLiteSession extends import_session.SQLiteSession {
|
|
33
|
+
constructor(client, dialect, schema, options = {}) {
|
|
34
|
+
super(dialect);
|
|
35
|
+
this.client = client;
|
|
36
|
+
this.schema = schema;
|
|
37
|
+
this.logger = options.logger ?? new import_logger.NoopLogger();
|
|
38
|
+
}
|
|
39
|
+
static [import_entity.entityKind] = "OPSQLiteSession";
|
|
40
|
+
logger;
|
|
41
|
+
prepareQuery(query, fields, executeMethod, customResultMapper) {
|
|
42
|
+
return new OPSQLitePreparedQuery(this.client, query, this.logger, fields, executeMethod, customResultMapper);
|
|
43
|
+
}
|
|
44
|
+
transaction(transaction, config = {}) {
|
|
45
|
+
const tx = new OPSQLiteTransaction("async", this.dialect, this, this.schema);
|
|
46
|
+
this.run(import_sql.sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
|
|
47
|
+
try {
|
|
48
|
+
const result = transaction(tx);
|
|
49
|
+
this.run(import_sql.sql`commit`);
|
|
50
|
+
return result;
|
|
51
|
+
} catch (err) {
|
|
52
|
+
this.run(import_sql.sql`rollback`);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class OPSQLiteTransaction extends import_sqlite_core.SQLiteTransaction {
|
|
58
|
+
static [import_entity.entityKind] = "OPSQLiteTransaction";
|
|
59
|
+
transaction(transaction) {
|
|
60
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
61
|
+
const tx = new OPSQLiteTransaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
62
|
+
this.session.run(import_sql.sql.raw(`savepoint ${savepointName}`));
|
|
63
|
+
try {
|
|
64
|
+
const result = transaction(tx);
|
|
65
|
+
this.session.run(import_sql.sql.raw(`release savepoint ${savepointName}`));
|
|
66
|
+
return result;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
this.session.run(import_sql.sql.raw(`rollback to savepoint ${savepointName}`));
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class OPSQLitePreparedQuery extends import_session.SQLitePreparedQuery {
|
|
74
|
+
constructor(client, query, logger, fields, executeMethod, customResultMapper) {
|
|
75
|
+
super("sync", executeMethod, query);
|
|
76
|
+
this.client = client;
|
|
77
|
+
this.logger = logger;
|
|
78
|
+
this.fields = fields;
|
|
79
|
+
this.customResultMapper = customResultMapper;
|
|
80
|
+
}
|
|
81
|
+
static [import_entity.entityKind] = "OPSQLitePreparedQuery";
|
|
82
|
+
run(placeholderValues) {
|
|
83
|
+
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
|
|
84
|
+
this.logger.logQuery(this.query.sql, params);
|
|
85
|
+
return this.client.executeAsync(this.query.sql, params);
|
|
86
|
+
}
|
|
87
|
+
async all(placeholderValues) {
|
|
88
|
+
const { fields, joinsNotNullableMap, query, logger, customResultMapper, client } = this;
|
|
89
|
+
if (!fields && !customResultMapper) {
|
|
90
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
91
|
+
logger.logQuery(query.sql, params);
|
|
92
|
+
return client.execute(query.sql, params).rows?._array || [];
|
|
93
|
+
}
|
|
94
|
+
const rows = await this.values(placeholderValues);
|
|
95
|
+
if (customResultMapper) {
|
|
96
|
+
return customResultMapper(rows);
|
|
97
|
+
}
|
|
98
|
+
return rows.map((row) => (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap));
|
|
99
|
+
}
|
|
100
|
+
async get(placeholderValues) {
|
|
101
|
+
const { fields, joinsNotNullableMap, customResultMapper, query, logger, client } = this;
|
|
102
|
+
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
103
|
+
logger.logQuery(query.sql, params);
|
|
104
|
+
if (!fields && !customResultMapper) {
|
|
105
|
+
const rows2 = client.execute(query.sql, params).rows?._array || [];
|
|
106
|
+
return rows2[0];
|
|
107
|
+
}
|
|
108
|
+
const rows = await this.values(placeholderValues);
|
|
109
|
+
const row = rows[0];
|
|
110
|
+
if (!row) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
if (customResultMapper) {
|
|
114
|
+
return customResultMapper(rows);
|
|
115
|
+
}
|
|
116
|
+
return (0, import_utils.mapResultRow)(fields, row, joinsNotNullableMap);
|
|
117
|
+
}
|
|
118
|
+
values(placeholderValues) {
|
|
119
|
+
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
|
|
120
|
+
this.logger.logQuery(this.query.sql, params);
|
|
121
|
+
return this.client.executeRawAsync(this.query.sql, params);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
OPSQLitePreparedQuery,
|
|
127
|
+
OPSQLiteSession,
|
|
128
|
+
OPSQLiteTransaction
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/session.ts"],"sourcesContent":["import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, sql } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport { SQLiteTransaction } from '~/sqlite-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types.ts';\nimport {\n type PreparedQueryConfig as PreparedQueryConfigBase,\n SQLitePreparedQuery,\n type SQLiteExecuteMethod,\n SQLiteSession,\n type SQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport { mapResultRow } from '~/utils.ts';\n\nexport interface OPSQLiteSessionOptions {\n logger?: Logger;\n}\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class OPSQLiteSession<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig,\n> extends SQLiteSession<'async', QueryResult, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'OPSQLiteSession';\n\n private logger: Logger;\n\n constructor(\n private client: OPSQLiteConnection,\n dialect: SQLiteAsyncDialect,\n private schema: RelationalSchemaConfig<TSchema> | undefined,\n options: OPSQLiteSessionOptions = {},\n\n ) {\n super(dialect);\n this.logger = options.logger ?? new NoopLogger();\n }\n\n prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n query: Query,\n fields: SelectedFieldsOrdered | undefined,\n executeMethod: SQLiteExecuteMethod,\n customResultMapper?: (rows: unknown[][]) => unknown,\n ): OPSQLitePreparedQuery<T> {\n return new OPSQLitePreparedQuery(this.client, query, this.logger, fields, executeMethod, customResultMapper);\n }\n\n override transaction<T>(\n transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T,\n config: SQLiteTransactionConfig = {},\n ): T {\n const tx = new OPSQLiteTransaction('async', this.dialect, this, this.schema);\n this.run(sql.raw(`begin${config?.behavior ? ' ' + config.behavior : ''}`));\n try {\n const result = transaction(tx);\n this.run(sql`commit`);\n return result;\n } catch (err) {\n this.run(sql`rollback`);\n throw err;\n }\n }\n}\n\nexport class OPSQLiteTransaction<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig,\n> extends SQLiteTransaction<'async', QueryResult, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'OPSQLiteTransaction';\n\n override transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T): T {\n const savepointName = `sp${this.nestedIndex}`;\n const tx = new OPSQLiteTransaction('async', this.dialect, this.session, this.schema, this.nestedIndex + 1);\n this.session.run(sql.raw(`savepoint ${savepointName}`));\n try {\n const result = transaction(tx);\n this.session.run(sql.raw(`release savepoint ${savepointName}`));\n return result;\n } catch (err) {\n this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n throw err;\n }\n }\n}\n\nexport class OPSQLitePreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<\n { type: 'async'; run: QueryResult; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }\n> {\n static readonly [entityKind]: string = 'OPSQLitePreparedQuery';\n\n constructor(\n\t\tprivate client: OPSQLiteConnection,\n query: Query,\n private logger: Logger,\n private fields: SelectedFieldsOrdered | undefined,\n executeMethod: SQLiteExecuteMethod,\n private customResultMapper?: (rows: unknown[][]) => unknown,\n ) {\n super('sync', executeMethod, query);\n }\n\n run(placeholderValues?: Record<string, unknown>): Promise<QueryResult> {\n const params = fillPlaceholders(this.query.params, placeholderValues ?? {});\n this.logger.logQuery(this.query.sql, params);\n\n return this.client.executeAsync(this.query.sql, params);\n }\n\n async all(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n const { fields, joinsNotNullableMap, query, logger, customResultMapper, client } = this;\n if (!fields && !customResultMapper) {\n const params = fillPlaceholders(query.params, placeholderValues ?? {});\n logger.logQuery(query.sql, params);\n\n return client.execute(query.sql, params).rows?._array || [];\n }\n\n const rows = await this.values(placeholderValues) as unknown[][];\n if (customResultMapper) {\n return customResultMapper(rows) as T['all'];\n }\n return rows.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));\n }\n\n async get(placeholderValues?: Record<string, unknown>): Promise<T['get']> {\n const { fields, joinsNotNullableMap, customResultMapper, query, logger, client } = this;\n const params = fillPlaceholders(query.params, placeholderValues ?? {});\n logger.logQuery(query.sql, params);\n if (!fields && !customResultMapper) {\n const rows = client.execute(query.sql, params).rows?._array || [];\n return rows[0];\n }\n\n const rows = await this.values(placeholderValues) as unknown[][];\n const row = rows[0];\n\n if (!row) {\n return undefined;\n }\n\n if (customResultMapper) {\n return customResultMapper(rows) as T['get'];\n }\n\n return mapResultRow(fields!, row, joinsNotNullableMap);\n }\n\n values(placeholderValues?: Record<string, unknown>): Promise<T['values']> {\n const params = fillPlaceholders(this.query.params, placeholderValues ?? {});\n this.logger.logQuery(this.query.sql, params);\n return this.client.executeRawAsync(this.query.sql, params);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;A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C,oBAAoB;AAChC,YAAMA,QAAO,OAAO,QAAQ,MAAM,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAChE,aAAOA,MAAK,CAAC;AAAA,IACjB;AAEA,UAAM,OAAO,MAAM,KAAK,OAAO,iBAAiB;AAChD,UAAM,MAAM,KAAK,CAAC;AAElB,QAAI,CAAC,KAAK;AACN,aAAO;AAAA,IACX;AAEA,QAAI,oBAAoB;AACpB,aAAO,mBAAmB,IAAI;AAAA,IAClC;AAEA,eAAO,2BAAa,QAAS,KAAK,mBAAmB;AAAA,EACzD;AAAA,EAEA,OAAO,mBAAmE;AACtE,UAAM,aAAS,6BAAiB,KAAK,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AAC1E,SAAK,OAAO,SAAS,KAAK,MAAM,KAAK,MAAM;AAC3C,WAAO,KAAK,OAAO,gBAAgB,KAAK,MAAM,KAAK,MAAM;AAAA,EAC7D;AACJ;","names":["rows"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { entityKind } from "../entity.cjs";
|
|
3
|
+
import type { Logger } from "../logger.cjs";
|
|
4
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
5
|
+
import { type Query } from "../sql/sql.cjs";
|
|
6
|
+
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.cjs";
|
|
7
|
+
import { SQLiteTransaction } from "../sqlite-core/index.cjs";
|
|
8
|
+
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.cjs";
|
|
9
|
+
import { type PreparedQueryConfig as PreparedQueryConfigBase, SQLitePreparedQuery, type SQLiteExecuteMethod, SQLiteSession, type SQLiteTransactionConfig } from "../sqlite-core/session.cjs";
|
|
10
|
+
export interface OPSQLiteSessionOptions {
|
|
11
|
+
logger?: Logger;
|
|
12
|
+
}
|
|
13
|
+
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
|
14
|
+
export declare class OPSQLiteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<'async', QueryResult, TFullSchema, TSchema> {
|
|
15
|
+
private client;
|
|
16
|
+
private schema;
|
|
17
|
+
static readonly [entityKind]: string;
|
|
18
|
+
private logger;
|
|
19
|
+
constructor(client: OPSQLiteConnection, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: OPSQLiteSessionOptions);
|
|
20
|
+
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: (rows: unknown[][]) => unknown): OPSQLitePreparedQuery<T>;
|
|
21
|
+
transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T, config?: SQLiteTransactionConfig): T;
|
|
22
|
+
}
|
|
23
|
+
export declare class OPSQLiteTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteTransaction<'async', QueryResult, TFullSchema, TSchema> {
|
|
24
|
+
static readonly [entityKind]: string;
|
|
25
|
+
transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T): T;
|
|
26
|
+
}
|
|
27
|
+
export declare class OPSQLitePreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
|
|
28
|
+
type: 'async';
|
|
29
|
+
run: QueryResult;
|
|
30
|
+
all: T['all'];
|
|
31
|
+
get: T['get'];
|
|
32
|
+
values: T['values'];
|
|
33
|
+
execute: T['execute'];
|
|
34
|
+
}> {
|
|
35
|
+
private client;
|
|
36
|
+
private logger;
|
|
37
|
+
private fields;
|
|
38
|
+
private customResultMapper?;
|
|
39
|
+
static readonly [entityKind]: string;
|
|
40
|
+
constructor(client: OPSQLiteConnection, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: ((rows: unknown[][]) => unknown) | undefined);
|
|
41
|
+
run(placeholderValues?: Record<string, unknown>): Promise<QueryResult>;
|
|
42
|
+
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
|
43
|
+
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
|
44
|
+
values(placeholderValues?: Record<string, unknown>): Promise<T['values']>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { entityKind } from "../entity.js";
|
|
3
|
+
import type { Logger } from "../logger.js";
|
|
4
|
+
import type { RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
5
|
+
import { type Query } from "../sql/sql.js";
|
|
6
|
+
import type { SQLiteAsyncDialect } from "../sqlite-core/dialect.js";
|
|
7
|
+
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
|
8
|
+
import type { SelectedFieldsOrdered } from "../sqlite-core/query-builders/select.types.js";
|
|
9
|
+
import { type PreparedQueryConfig as PreparedQueryConfigBase, SQLitePreparedQuery, type SQLiteExecuteMethod, SQLiteSession, type SQLiteTransactionConfig } from "../sqlite-core/session.js";
|
|
10
|
+
export interface OPSQLiteSessionOptions {
|
|
11
|
+
logger?: Logger;
|
|
12
|
+
}
|
|
13
|
+
type PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;
|
|
14
|
+
export declare class OPSQLiteSession<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteSession<'async', QueryResult, TFullSchema, TSchema> {
|
|
15
|
+
private client;
|
|
16
|
+
private schema;
|
|
17
|
+
static readonly [entityKind]: string;
|
|
18
|
+
private logger;
|
|
19
|
+
constructor(client: OPSQLiteConnection, dialect: SQLiteAsyncDialect, schema: RelationalSchemaConfig<TSchema> | undefined, options?: OPSQLiteSessionOptions);
|
|
20
|
+
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(query: Query, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: (rows: unknown[][]) => unknown): OPSQLitePreparedQuery<T>;
|
|
21
|
+
transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T, config?: SQLiteTransactionConfig): T;
|
|
22
|
+
}
|
|
23
|
+
export declare class OPSQLiteTransaction<TFullSchema extends Record<string, unknown>, TSchema extends TablesRelationalConfig> extends SQLiteTransaction<'async', QueryResult, TFullSchema, TSchema> {
|
|
24
|
+
static readonly [entityKind]: string;
|
|
25
|
+
transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T): T;
|
|
26
|
+
}
|
|
27
|
+
export declare class OPSQLitePreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<{
|
|
28
|
+
type: 'async';
|
|
29
|
+
run: QueryResult;
|
|
30
|
+
all: T['all'];
|
|
31
|
+
get: T['get'];
|
|
32
|
+
values: T['values'];
|
|
33
|
+
execute: T['execute'];
|
|
34
|
+
}> {
|
|
35
|
+
private client;
|
|
36
|
+
private logger;
|
|
37
|
+
private fields;
|
|
38
|
+
private customResultMapper?;
|
|
39
|
+
static readonly [entityKind]: string;
|
|
40
|
+
constructor(client: OPSQLiteConnection, query: Query, logger: Logger, fields: SelectedFieldsOrdered | undefined, executeMethod: SQLiteExecuteMethod, customResultMapper?: ((rows: unknown[][]) => unknown) | undefined);
|
|
41
|
+
run(placeholderValues?: Record<string, unknown>): Promise<QueryResult>;
|
|
42
|
+
all(placeholderValues?: Record<string, unknown>): Promise<T['all']>;
|
|
43
|
+
get(placeholderValues?: Record<string, unknown>): Promise<T['get']>;
|
|
44
|
+
values(placeholderValues?: Record<string, unknown>): Promise<T['values']>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { entityKind } from "../entity.js";
|
|
2
|
+
import { NoopLogger } from "../logger.js";
|
|
3
|
+
import { fillPlaceholders, sql } from "../sql/sql.js";
|
|
4
|
+
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
|
5
|
+
import {
|
|
6
|
+
SQLitePreparedQuery,
|
|
7
|
+
SQLiteSession
|
|
8
|
+
} from "../sqlite-core/session.js";
|
|
9
|
+
import { mapResultRow } from "../utils.js";
|
|
10
|
+
class OPSQLiteSession extends SQLiteSession {
|
|
11
|
+
constructor(client, dialect, schema, options = {}) {
|
|
12
|
+
super(dialect);
|
|
13
|
+
this.client = client;
|
|
14
|
+
this.schema = schema;
|
|
15
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
16
|
+
}
|
|
17
|
+
static [entityKind] = "OPSQLiteSession";
|
|
18
|
+
logger;
|
|
19
|
+
prepareQuery(query, fields, executeMethod, customResultMapper) {
|
|
20
|
+
return new OPSQLitePreparedQuery(this.client, query, this.logger, fields, executeMethod, customResultMapper);
|
|
21
|
+
}
|
|
22
|
+
transaction(transaction, config = {}) {
|
|
23
|
+
const tx = new OPSQLiteTransaction("async", this.dialect, this, this.schema);
|
|
24
|
+
this.run(sql.raw(`begin${config?.behavior ? " " + config.behavior : ""}`));
|
|
25
|
+
try {
|
|
26
|
+
const result = transaction(tx);
|
|
27
|
+
this.run(sql`commit`);
|
|
28
|
+
return result;
|
|
29
|
+
} catch (err) {
|
|
30
|
+
this.run(sql`rollback`);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class OPSQLiteTransaction extends SQLiteTransaction {
|
|
36
|
+
static [entityKind] = "OPSQLiteTransaction";
|
|
37
|
+
transaction(transaction) {
|
|
38
|
+
const savepointName = `sp${this.nestedIndex}`;
|
|
39
|
+
const tx = new OPSQLiteTransaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
|
|
40
|
+
this.session.run(sql.raw(`savepoint ${savepointName}`));
|
|
41
|
+
try {
|
|
42
|
+
const result = transaction(tx);
|
|
43
|
+
this.session.run(sql.raw(`release savepoint ${savepointName}`));
|
|
44
|
+
return result;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class OPSQLitePreparedQuery extends SQLitePreparedQuery {
|
|
52
|
+
constructor(client, query, logger, fields, executeMethod, customResultMapper) {
|
|
53
|
+
super("sync", executeMethod, query);
|
|
54
|
+
this.client = client;
|
|
55
|
+
this.logger = logger;
|
|
56
|
+
this.fields = fields;
|
|
57
|
+
this.customResultMapper = customResultMapper;
|
|
58
|
+
}
|
|
59
|
+
static [entityKind] = "OPSQLitePreparedQuery";
|
|
60
|
+
run(placeholderValues) {
|
|
61
|
+
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
62
|
+
this.logger.logQuery(this.query.sql, params);
|
|
63
|
+
return this.client.executeAsync(this.query.sql, params);
|
|
64
|
+
}
|
|
65
|
+
async all(placeholderValues) {
|
|
66
|
+
const { fields, joinsNotNullableMap, query, logger, customResultMapper, client } = this;
|
|
67
|
+
if (!fields && !customResultMapper) {
|
|
68
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
69
|
+
logger.logQuery(query.sql, params);
|
|
70
|
+
return client.execute(query.sql, params).rows?._array || [];
|
|
71
|
+
}
|
|
72
|
+
const rows = await this.values(placeholderValues);
|
|
73
|
+
if (customResultMapper) {
|
|
74
|
+
return customResultMapper(rows);
|
|
75
|
+
}
|
|
76
|
+
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
77
|
+
}
|
|
78
|
+
async get(placeholderValues) {
|
|
79
|
+
const { fields, joinsNotNullableMap, customResultMapper, query, logger, client } = this;
|
|
80
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
81
|
+
logger.logQuery(query.sql, params);
|
|
82
|
+
if (!fields && !customResultMapper) {
|
|
83
|
+
const rows2 = client.execute(query.sql, params).rows?._array || [];
|
|
84
|
+
return rows2[0];
|
|
85
|
+
}
|
|
86
|
+
const rows = await this.values(placeholderValues);
|
|
87
|
+
const row = rows[0];
|
|
88
|
+
if (!row) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
if (customResultMapper) {
|
|
92
|
+
return customResultMapper(rows);
|
|
93
|
+
}
|
|
94
|
+
return mapResultRow(fields, row, joinsNotNullableMap);
|
|
95
|
+
}
|
|
96
|
+
values(placeholderValues) {
|
|
97
|
+
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
|
|
98
|
+
this.logger.logQuery(this.query.sql, params);
|
|
99
|
+
return this.client.executeRawAsync(this.query.sql, params);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
OPSQLitePreparedQuery,
|
|
104
|
+
OPSQLiteSession,
|
|
105
|
+
OPSQLiteTransaction
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/op-sqlite/session.ts"],"sourcesContent":["import type { OPSQLiteConnection, QueryResult } from '@op-engineering/op-sqlite';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { fillPlaceholders, type Query, sql } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect } from '~/sqlite-core/dialect.ts';\nimport { SQLiteTransaction } from '~/sqlite-core/index.ts';\nimport type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types.ts';\nimport {\n type PreparedQueryConfig as PreparedQueryConfigBase,\n SQLitePreparedQuery,\n type SQLiteExecuteMethod,\n SQLiteSession,\n type SQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport { mapResultRow } from '~/utils.ts';\n\nexport interface OPSQLiteSessionOptions {\n logger?: Logger;\n}\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class OPSQLiteSession<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig,\n> extends SQLiteSession<'async', QueryResult, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'OPSQLiteSession';\n\n private logger: Logger;\n\n constructor(\n private client: OPSQLiteConnection,\n dialect: SQLiteAsyncDialect,\n private schema: RelationalSchemaConfig<TSchema> | undefined,\n options: OPSQLiteSessionOptions = {},\n\n ) {\n super(dialect);\n this.logger = options.logger ?? new NoopLogger();\n }\n\n prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n query: Query,\n fields: SelectedFieldsOrdered | undefined,\n executeMethod: SQLiteExecuteMethod,\n customResultMapper?: (rows: unknown[][]) => unknown,\n ): OPSQLitePreparedQuery<T> {\n return new OPSQLitePreparedQuery(this.client, query, this.logger, fields, executeMethod, customResultMapper);\n }\n\n override transaction<T>(\n transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T,\n config: SQLiteTransactionConfig = {},\n ): T {\n const tx = new OPSQLiteTransaction('async', this.dialect, this, this.schema);\n this.run(sql.raw(`begin${config?.behavior ? ' ' + config.behavior : ''}`));\n try {\n const result = transaction(tx);\n this.run(sql`commit`);\n return result;\n } catch (err) {\n this.run(sql`rollback`);\n throw err;\n }\n }\n}\n\nexport class OPSQLiteTransaction<\n TFullSchema extends Record<string, unknown>,\n TSchema extends TablesRelationalConfig,\n> extends SQLiteTransaction<'async', QueryResult, TFullSchema, TSchema> {\n static readonly [entityKind]: string = 'OPSQLiteTransaction';\n\n override transaction<T>(transaction: (tx: OPSQLiteTransaction<TFullSchema, TSchema>) => T): T {\n const savepointName = `sp${this.nestedIndex}`;\n const tx = new OPSQLiteTransaction('async', this.dialect, this.session, this.schema, this.nestedIndex + 1);\n this.session.run(sql.raw(`savepoint ${savepointName}`));\n try {\n const result = transaction(tx);\n this.session.run(sql.raw(`release savepoint ${savepointName}`));\n return result;\n } catch (err) {\n this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n throw err;\n }\n }\n}\n\nexport class OPSQLitePreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<\n { type: 'async'; run: QueryResult; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }\n> {\n static readonly [entityKind]: string = 'OPSQLitePreparedQuery';\n\n constructor(\n\t\tprivate client: OPSQLiteConnection,\n query: Query,\n private logger: Logger,\n private fields: SelectedFieldsOrdered | undefined,\n executeMethod: SQLiteExecuteMethod,\n private customResultMapper?: (rows: unknown[][]) => unknown,\n ) {\n super('sync', executeMethod, query);\n }\n\n run(placeholderValues?: Record<string, unknown>): Promise<QueryResult> {\n const params = fillPlaceholders(this.query.params, placeholderValues ?? {});\n this.logger.logQuery(this.query.sql, params);\n\n return this.client.executeAsync(this.query.sql, params);\n }\n\n async all(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n const { fields, joinsNotNullableMap, query, logger, customResultMapper, client } = this;\n if (!fields && !customResultMapper) {\n const params = fillPlaceholders(query.params, placeholderValues ?? {});\n logger.logQuery(query.sql, params);\n\n return client.execute(query.sql, params).rows?._array || [];\n }\n\n const rows = await this.values(placeholderValues) as unknown[][];\n if (customResultMapper) {\n return customResultMapper(rows) as T['all'];\n }\n return rows.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));\n }\n\n async get(placeholderValues?: Record<string, unknown>): Promise<T['get']> {\n const { fields, joinsNotNullableMap, customResultMapper, query, logger, client } = this;\n const params = fillPlaceholders(query.params, placeholderValues ?? {});\n logger.logQuery(query.sql, params);\n if (!fields && !customResultMapper) {\n const rows = client.execute(query.sql, params).rows?._array || [];\n return rows[0];\n }\n\n const rows = await this.values(placeholderValues) as unknown[][];\n const row = rows[0];\n\n if (!row) {\n return undefined;\n }\n\n if (customResultMapper) {\n return customResultMapper(rows) as T['get'];\n }\n\n return mapResultRow(fields!, row, joinsNotNullableMap);\n }\n\n values(placeholderValues?: Record<string, unknown>): Promise<T['values']> {\n const params = fillPlaceholders(this.query.params, placeholderValues ?? {});\n this.logger.logQuery(this.query.sql, params);\n return this.client.executeRawAsync(this.query.sql, params);\n }\n}\n"],"mappings":"AACA,SAAS,kBAAkB;AAE3B,SAAS,kBAAkB;AAE3B,SAAS,kBAA8B,WAAW;AAElD,SAAS,yBAAyB;AAElC;AAAA,EAEI;AAAA,EAEA;AAAA,OAEG;AACP,SAAS,oBAAoB;AAQtB,MAAM,wBAGH,cAA0D;AAAA,EAKhE,YACY,QACR,SACQ,QACR,UAAkC,CAAC,GAErC;AACE,UAAM,OAAO;AANL;AAEA;AAKR,SAAK,SAAS,QAAQ,UAAU,IAAI,WAAW;AAAA,EACnD;AAAA,EAbA,QAAiB,UAAU,IAAY;AAAA,EAE/B;AAAA,EAaR,aACI,OACA,QACA,eACA,oBACwB;AACxB,WAAO,IAAI,sBAAsB,KAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ,eAAe,kBAAkB;AAAA,EAC/G;AAAA,EAES,YACL,aACA,SAAkC,CAAC,GAClC;AACD,UAAM,KAAK,IAAI,oBAAoB,SAAS,KAAK,SAAS,MAAM,KAAK,MAAM;AAC3E,SAAK,IAAI,IAAI,IAAI,QAAQ,QAAQ,WAAW,MAAM,OAAO,WAAW,EAAE,EAAE,CAAC;AACzE,QAAI;AACA,YAAM,SAAS,YAAY,EAAE;AAC7B,WAAK,IAAI,WAAW;AACpB,aAAO;AAAA,IACX,SAAS,KAAK;AACV,WAAK,IAAI,aAAa;AACtB,YAAM;AAAA,IACV;AAAA,EACJ;AACJ;AAEO,MAAM,4BAGH,kBAA8D;AAAA,EACpE,QAAiB,UAAU,IAAY;AAAA,EAE9B,YAAe,aAAsE;AAC1F,UAAM,gBAAgB,KAAK,KAAK,WAAW;AAC3C,UAAM,KAAK,IAAI,oBAAoB,SAAS,KAAK,SAAS,KAAK,SAAS,KAAK,QAAQ,KAAK,cAAc,CAAC;AACzG,SAAK,QAAQ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AQ,qBAAqB,oBAAoB,OAAO,QAAQ,OAAO,IAAI;AACnF,UAAM,SAAS,iBAAiB,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AACrE,WAAO,SAAS,MAAM,KAAK,MAAM;AACjC,QAAI,CAAC,UAAU,CAAC,oBAAoB;AAChC,YAAMA,QAAO,OAAO,QAAQ,MAAM,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAChE,aAAOA,MAAK,CAAC;AAAA,IACjB;AAEA,UAAM,OAAO,MAAM,KAAK,OAAO,iBAAiB;AAChD,UAAM,MAAM,KAAK,CAAC;AAElB,QAAI,CAAC,KAAK;AACN,aAAO;AAAA,IACX;AAEA,QAAI,oBAAoB;AACpB,aAAO,mBAAmB,IAAI;AAAA,IAClC;AAEA,WAAO,aAAa,QAAS,KAAK,mBAAmB;AAAA,EACzD;AAAA,EAEA,OAAO,mBAAmE;AACtE,UAAM,SAAS,iBAAiB,KAAK,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AAC1E,SAAK,OAAO,SAAS,KAAK,MAAM,KAAK,MAAM;AAC3C,WAAO,KAAK,OAAO,gBAAgB,KAAK,MAAM,KAAK,MAAM;AAAA,EAC7D;AACJ;","names":["rows"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-orm",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.1-e01313e",
|
|
4
4
|
"description": "Drizzle ORM package for SQL databases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "git+https://github.com/drizzle-team/drizzle-orm.git"
|
|
24
24
|
},
|
|
25
|
-
"homepage": "https://
|
|
25
|
+
"homepage": "https://orm.drizzle.team",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"drizzle",
|
|
28
28
|
"orm",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@cloudflare/workers-types": ">=3",
|
|
48
48
|
"@libsql/client": "*",
|
|
49
49
|
"@neondatabase/serverless": ">=0.1",
|
|
50
|
+
"@op-engineering/op-sqlite": ">=2",
|
|
50
51
|
"@opentelemetry/api": "^1.4.1",
|
|
51
52
|
"@planetscale/database": ">=1",
|
|
52
53
|
"@types/better-sqlite3": "*",
|
|
@@ -127,6 +128,9 @@
|
|
|
127
128
|
"expo-sqlite": {
|
|
128
129
|
"optional": true
|
|
129
130
|
},
|
|
131
|
+
"@op-engineering/op-sqlite": {
|
|
132
|
+
"optional": true
|
|
133
|
+
},
|
|
130
134
|
"react": {
|
|
131
135
|
"optional": true
|
|
132
136
|
},
|
|
@@ -139,6 +143,7 @@
|
|
|
139
143
|
"@cloudflare/workers-types": "^4.20230904.0",
|
|
140
144
|
"@libsql/client": "^0.1.6",
|
|
141
145
|
"@neondatabase/serverless": "^0.4.24",
|
|
146
|
+
"@op-engineering/op-sqlite": "^2.0.16",
|
|
142
147
|
"@opentelemetry/api": "^1.4.1",
|
|
143
148
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
144
149
|
"@planetscale/database": "^1.16.0",
|
|
@@ -456,54 +461,6 @@
|
|
|
456
461
|
"types": "./view-common.d.ts",
|
|
457
462
|
"default": "./view-common.js"
|
|
458
463
|
},
|
|
459
|
-
"./bun-sqlite/driver": {
|
|
460
|
-
"import": {
|
|
461
|
-
"types": "./bun-sqlite/driver.d.ts",
|
|
462
|
-
"default": "./bun-sqlite/driver.js"
|
|
463
|
-
},
|
|
464
|
-
"require": {
|
|
465
|
-
"types": "./bun-sqlite/driver.d.cts",
|
|
466
|
-
"default": "./bun-sqlite/driver.cjs"
|
|
467
|
-
},
|
|
468
|
-
"types": "./bun-sqlite/driver.d.ts",
|
|
469
|
-
"default": "./bun-sqlite/driver.js"
|
|
470
|
-
},
|
|
471
|
-
"./bun-sqlite": {
|
|
472
|
-
"import": {
|
|
473
|
-
"types": "./bun-sqlite/index.d.ts",
|
|
474
|
-
"default": "./bun-sqlite/index.js"
|
|
475
|
-
},
|
|
476
|
-
"require": {
|
|
477
|
-
"types": "./bun-sqlite/index.d.cts",
|
|
478
|
-
"default": "./bun-sqlite/index.cjs"
|
|
479
|
-
},
|
|
480
|
-
"types": "./bun-sqlite/index.d.ts",
|
|
481
|
-
"default": "./bun-sqlite/index.js"
|
|
482
|
-
},
|
|
483
|
-
"./bun-sqlite/migrator": {
|
|
484
|
-
"import": {
|
|
485
|
-
"types": "./bun-sqlite/migrator.d.ts",
|
|
486
|
-
"default": "./bun-sqlite/migrator.js"
|
|
487
|
-
},
|
|
488
|
-
"require": {
|
|
489
|
-
"types": "./bun-sqlite/migrator.d.cts",
|
|
490
|
-
"default": "./bun-sqlite/migrator.cjs"
|
|
491
|
-
},
|
|
492
|
-
"types": "./bun-sqlite/migrator.d.ts",
|
|
493
|
-
"default": "./bun-sqlite/migrator.js"
|
|
494
|
-
},
|
|
495
|
-
"./bun-sqlite/session": {
|
|
496
|
-
"import": {
|
|
497
|
-
"types": "./bun-sqlite/session.d.ts",
|
|
498
|
-
"default": "./bun-sqlite/session.js"
|
|
499
|
-
},
|
|
500
|
-
"require": {
|
|
501
|
-
"types": "./bun-sqlite/session.d.cts",
|
|
502
|
-
"default": "./bun-sqlite/session.cjs"
|
|
503
|
-
},
|
|
504
|
-
"types": "./bun-sqlite/session.d.ts",
|
|
505
|
-
"default": "./bun-sqlite/session.js"
|
|
506
|
-
},
|
|
507
464
|
"./better-sqlite3/driver": {
|
|
508
465
|
"import": {
|
|
509
466
|
"types": "./better-sqlite3/driver.d.ts",
|
|
@@ -552,6 +509,54 @@
|
|
|
552
509
|
"types": "./better-sqlite3/session.d.ts",
|
|
553
510
|
"default": "./better-sqlite3/session.js"
|
|
554
511
|
},
|
|
512
|
+
"./bun-sqlite/driver": {
|
|
513
|
+
"import": {
|
|
514
|
+
"types": "./bun-sqlite/driver.d.ts",
|
|
515
|
+
"default": "./bun-sqlite/driver.js"
|
|
516
|
+
},
|
|
517
|
+
"require": {
|
|
518
|
+
"types": "./bun-sqlite/driver.d.cts",
|
|
519
|
+
"default": "./bun-sqlite/driver.cjs"
|
|
520
|
+
},
|
|
521
|
+
"types": "./bun-sqlite/driver.d.ts",
|
|
522
|
+
"default": "./bun-sqlite/driver.js"
|
|
523
|
+
},
|
|
524
|
+
"./bun-sqlite": {
|
|
525
|
+
"import": {
|
|
526
|
+
"types": "./bun-sqlite/index.d.ts",
|
|
527
|
+
"default": "./bun-sqlite/index.js"
|
|
528
|
+
},
|
|
529
|
+
"require": {
|
|
530
|
+
"types": "./bun-sqlite/index.d.cts",
|
|
531
|
+
"default": "./bun-sqlite/index.cjs"
|
|
532
|
+
},
|
|
533
|
+
"types": "./bun-sqlite/index.d.ts",
|
|
534
|
+
"default": "./bun-sqlite/index.js"
|
|
535
|
+
},
|
|
536
|
+
"./bun-sqlite/migrator": {
|
|
537
|
+
"import": {
|
|
538
|
+
"types": "./bun-sqlite/migrator.d.ts",
|
|
539
|
+
"default": "./bun-sqlite/migrator.js"
|
|
540
|
+
},
|
|
541
|
+
"require": {
|
|
542
|
+
"types": "./bun-sqlite/migrator.d.cts",
|
|
543
|
+
"default": "./bun-sqlite/migrator.cjs"
|
|
544
|
+
},
|
|
545
|
+
"types": "./bun-sqlite/migrator.d.ts",
|
|
546
|
+
"default": "./bun-sqlite/migrator.js"
|
|
547
|
+
},
|
|
548
|
+
"./bun-sqlite/session": {
|
|
549
|
+
"import": {
|
|
550
|
+
"types": "./bun-sqlite/session.d.ts",
|
|
551
|
+
"default": "./bun-sqlite/session.js"
|
|
552
|
+
},
|
|
553
|
+
"require": {
|
|
554
|
+
"types": "./bun-sqlite/session.d.cts",
|
|
555
|
+
"default": "./bun-sqlite/session.cjs"
|
|
556
|
+
},
|
|
557
|
+
"types": "./bun-sqlite/session.d.ts",
|
|
558
|
+
"default": "./bun-sqlite/session.js"
|
|
559
|
+
},
|
|
555
560
|
"./d1/driver": {
|
|
556
561
|
"import": {
|
|
557
562
|
"types": "./d1/driver.d.ts",
|
|
@@ -1176,6 +1181,54 @@
|
|
|
1176
1181
|
"types": "./node-postgres/session.d.ts",
|
|
1177
1182
|
"default": "./node-postgres/session.js"
|
|
1178
1183
|
},
|
|
1184
|
+
"./op-sqlite/driver": {
|
|
1185
|
+
"import": {
|
|
1186
|
+
"types": "./op-sqlite/driver.d.ts",
|
|
1187
|
+
"default": "./op-sqlite/driver.js"
|
|
1188
|
+
},
|
|
1189
|
+
"require": {
|
|
1190
|
+
"types": "./op-sqlite/driver.d.cts",
|
|
1191
|
+
"default": "./op-sqlite/driver.cjs"
|
|
1192
|
+
},
|
|
1193
|
+
"types": "./op-sqlite/driver.d.ts",
|
|
1194
|
+
"default": "./op-sqlite/driver.js"
|
|
1195
|
+
},
|
|
1196
|
+
"./op-sqlite": {
|
|
1197
|
+
"import": {
|
|
1198
|
+
"types": "./op-sqlite/index.d.ts",
|
|
1199
|
+
"default": "./op-sqlite/index.js"
|
|
1200
|
+
},
|
|
1201
|
+
"require": {
|
|
1202
|
+
"types": "./op-sqlite/index.d.cts",
|
|
1203
|
+
"default": "./op-sqlite/index.cjs"
|
|
1204
|
+
},
|
|
1205
|
+
"types": "./op-sqlite/index.d.ts",
|
|
1206
|
+
"default": "./op-sqlite/index.js"
|
|
1207
|
+
},
|
|
1208
|
+
"./op-sqlite/migrator": {
|
|
1209
|
+
"import": {
|
|
1210
|
+
"types": "./op-sqlite/migrator.d.ts",
|
|
1211
|
+
"default": "./op-sqlite/migrator.js"
|
|
1212
|
+
},
|
|
1213
|
+
"require": {
|
|
1214
|
+
"types": "./op-sqlite/migrator.d.cts",
|
|
1215
|
+
"default": "./op-sqlite/migrator.cjs"
|
|
1216
|
+
},
|
|
1217
|
+
"types": "./op-sqlite/migrator.d.ts",
|
|
1218
|
+
"default": "./op-sqlite/migrator.js"
|
|
1219
|
+
},
|
|
1220
|
+
"./op-sqlite/session": {
|
|
1221
|
+
"import": {
|
|
1222
|
+
"types": "./op-sqlite/session.d.ts",
|
|
1223
|
+
"default": "./op-sqlite/session.js"
|
|
1224
|
+
},
|
|
1225
|
+
"require": {
|
|
1226
|
+
"types": "./op-sqlite/session.d.cts",
|
|
1227
|
+
"default": "./op-sqlite/session.cjs"
|
|
1228
|
+
},
|
|
1229
|
+
"types": "./op-sqlite/session.d.ts",
|
|
1230
|
+
"default": "./op-sqlite/session.js"
|
|
1231
|
+
},
|
|
1179
1232
|
"./pg-core/alias": {
|
|
1180
1233
|
"import": {
|
|
1181
1234
|
"types": "./pg-core/alias.d.ts",
|
package/sqlite-core/dialect.cjs
CHANGED
|
@@ -574,7 +574,7 @@ class SQLiteSyncDialect extends SQLiteDialect {
|
|
|
574
574
|
class SQLiteAsyncDialect extends SQLiteDialect {
|
|
575
575
|
static [import_entity.entityKind] = "SQLiteAsyncDialect";
|
|
576
576
|
async migrate(migrations, session, config) {
|
|
577
|
-
const migrationsTable = typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
577
|
+
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
|
578
578
|
const migrationTableCreate = import_sql2.sql`
|
|
579
579
|
CREATE TABLE IF NOT EXISTS ${import_sql2.sql.identifier(migrationsTable)} (
|
|
580
580
|
id SERIAL PRIMARY KEY,
|