drizzle-orm 1.0.0-beta.1-860c2f2 → 1.0.0-beta.1-ac4ce44
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/d1/driver.cjs.map +1 -1
- package/d1/driver.d.cts +1 -1
- package/d1/driver.d.ts +1 -1
- package/d1/driver.js.map +1 -1
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +1 -1
- package/d1/session.d.ts +1 -1
- package/d1/session.js.map +1 -1
- package/gel-core/db.cjs +1 -0
- package/gel-core/db.cjs.map +1 -1
- package/gel-core/db.d.cts +1 -0
- package/gel-core/db.d.ts +1 -0
- package/gel-core/db.js +1 -0
- package/gel-core/db.js.map +1 -1
- package/mysql-core/db.cjs +1 -0
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +1 -0
- package/mysql-core/db.d.ts +1 -0
- package/mysql-core/db.js +1 -0
- package/mysql-core/db.js.map +1 -1
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.js.map +1 -1
- package/package.json +137 -50
- package/pg-core/db.cjs +1 -0
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +1 -0
- package/pg-core/db.d.ts +1 -0
- package/pg-core/db.js +1 -0
- package/pg-core/db.js.map +1 -1
- package/singlestore-core/db.cjs +1 -0
- package/singlestore-core/db.cjs.map +1 -1
- package/singlestore-core/db.d.cts +1 -0
- package/singlestore-core/db.d.ts +1 -0
- package/singlestore-core/db.js +1 -0
- package/singlestore-core/db.js.map +1 -1
- package/sqlite-core/db.cjs +1 -0
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +1 -0
- package/sqlite-core/db.d.ts +1 -0
- package/sqlite-core/db.js +1 -0
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/dialect.cjs +1 -1
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +1 -1
- package/sqlite-core/dialect.js.map +1 -1
- package/tursodatabase/database.cjs +50 -0
- package/tursodatabase/database.cjs.map +1 -0
- package/tursodatabase/database.d.cts +28 -0
- package/tursodatabase/database.d.ts +28 -0
- package/tursodatabase/database.js +26 -0
- package/tursodatabase/database.js.map +1 -0
- package/tursodatabase/driver-core.cjs +91 -0
- package/tursodatabase/driver-core.cjs.map +1 -0
- package/tursodatabase/driver-core.d.cts +8 -0
- package/tursodatabase/driver-core.d.ts +8 -0
- package/tursodatabase/driver-core.js +56 -0
- package/tursodatabase/driver-core.js.map +1 -0
- package/tursodatabase/index.cjs +25 -0
- package/tursodatabase/index.cjs.map +1 -0
- package/tursodatabase/index.d.cts +2 -0
- package/tursodatabase/index.d.ts +2 -0
- package/tursodatabase/index.js +3 -0
- package/tursodatabase/index.js.map +1 -0
- package/tursodatabase/migrator.cjs +33 -0
- package/tursodatabase/migrator.cjs.map +1 -0
- package/tursodatabase/migrator.d.cts +4 -0
- package/tursodatabase/migrator.d.ts +4 -0
- package/tursodatabase/migrator.js +9 -0
- package/tursodatabase/migrator.js.map +1 -0
- package/tursodatabase/session.cjs +205 -0
- package/tursodatabase/session.cjs.map +1 -0
- package/tursodatabase/session.d.cts +70 -0
- package/tursodatabase/session.d.ts +70 -0
- package/tursodatabase/session.js +179 -0
- package/tursodatabase/session.js.map +1 -0
- package/tursodatabase/wasm.cjs +50 -0
- package/tursodatabase/wasm.cjs.map +1 -0
- package/tursodatabase/wasm.d.cts +28 -0
- package/tursodatabase/wasm.d.ts +28 -0
- package/tursodatabase/wasm.js +26 -0
- package/tursodatabase/wasm.js.map +1 -0
- 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,179 @@
|
|
|
1
|
+
import { NoopCache } from "../cache/core/index.js";
|
|
2
|
+
import { entityKind } from "../entity.js";
|
|
3
|
+
import { DrizzleError } from "../errors.js";
|
|
4
|
+
import { NoopLogger } from "../logger.js";
|
|
5
|
+
import { fillPlaceholders } from "../sql/sql.js";
|
|
6
|
+
import { SQLiteTransaction } from "../sqlite-core/index.js";
|
|
7
|
+
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
|
|
8
|
+
import { mapResultRow } from "../utils.js";
|
|
9
|
+
class TursoDatabaseSession extends SQLiteSession {
|
|
10
|
+
constructor(client, dialect, relations, schema, options) {
|
|
11
|
+
super(dialect);
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.relations = relations;
|
|
14
|
+
this.schema = schema;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
17
|
+
this.cache = options.cache ?? new NoopCache();
|
|
18
|
+
}
|
|
19
|
+
static [entityKind] = "TursoDatabaseSession";
|
|
20
|
+
logger;
|
|
21
|
+
cache;
|
|
22
|
+
prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper, queryMetadata, cacheConfig) {
|
|
23
|
+
const stmt = this.client.prepare(query.sql);
|
|
24
|
+
return new TursoDatabasePreparedQuery(
|
|
25
|
+
stmt,
|
|
26
|
+
query,
|
|
27
|
+
this.logger,
|
|
28
|
+
this.cache,
|
|
29
|
+
queryMetadata,
|
|
30
|
+
cacheConfig,
|
|
31
|
+
fields,
|
|
32
|
+
executeMethod,
|
|
33
|
+
isResponseInArrayMode,
|
|
34
|
+
customResultMapper
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
prepareRelationalQuery(query, fields, executeMethod, customResultMapper) {
|
|
38
|
+
const stmt = this.client.prepare(query.sql);
|
|
39
|
+
return new TursoDatabasePreparedQuery(
|
|
40
|
+
stmt,
|
|
41
|
+
query,
|
|
42
|
+
this.logger,
|
|
43
|
+
this.cache,
|
|
44
|
+
void 0,
|
|
45
|
+
void 0,
|
|
46
|
+
fields,
|
|
47
|
+
executeMethod,
|
|
48
|
+
false,
|
|
49
|
+
customResultMapper,
|
|
50
|
+
true
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async transaction(transaction, _config, tx) {
|
|
54
|
+
const session = new TursoDatabaseSession(
|
|
55
|
+
this.client,
|
|
56
|
+
this.dialect,
|
|
57
|
+
this.relations,
|
|
58
|
+
this.schema,
|
|
59
|
+
this.options
|
|
60
|
+
);
|
|
61
|
+
const localTx = tx ?? new TursoDatabaseTransaction(
|
|
62
|
+
"async",
|
|
63
|
+
this.dialect,
|
|
64
|
+
session,
|
|
65
|
+
this.relations,
|
|
66
|
+
this.schema
|
|
67
|
+
);
|
|
68
|
+
const clientTx = this.client.transaction(async () => await transaction(localTx));
|
|
69
|
+
const result = await clientTx();
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
async run(query) {
|
|
73
|
+
const staticQuery = this.dialect.sqlToQuery(query);
|
|
74
|
+
try {
|
|
75
|
+
return await this.prepareOneTimeQuery(staticQuery, void 0, "run", false).run();
|
|
76
|
+
} catch (err) {
|
|
77
|
+
throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async all(query) {
|
|
81
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).all();
|
|
82
|
+
}
|
|
83
|
+
async get(query) {
|
|
84
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).get();
|
|
85
|
+
}
|
|
86
|
+
async values(query) {
|
|
87
|
+
return await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
class TursoDatabaseTransaction extends SQLiteTransaction {
|
|
91
|
+
static [entityKind] = "TursoDatabaseTransaction";
|
|
92
|
+
async transaction(_transaction) {
|
|
93
|
+
throw new Error("Nested transactions are not supported");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class TursoDatabasePreparedQuery extends SQLitePreparedQuery {
|
|
97
|
+
constructor(stmt, query, logger, cache, queryMetadata, cacheConfig, fields, executeMethod, _isResponseInArrayMode, customResultMapper, isRqbV2Query) {
|
|
98
|
+
super("async", executeMethod, query, cache, queryMetadata, cacheConfig);
|
|
99
|
+
this.stmt = stmt;
|
|
100
|
+
this.logger = logger;
|
|
101
|
+
this.fields = fields;
|
|
102
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
103
|
+
this.customResultMapper = customResultMapper;
|
|
104
|
+
this.isRqbV2Query = isRqbV2Query;
|
|
105
|
+
this.customResultMapper = customResultMapper;
|
|
106
|
+
this.fields = fields;
|
|
107
|
+
}
|
|
108
|
+
static [entityKind] = "TursoDatabasePreparedQuery";
|
|
109
|
+
async run(placeholderValues) {
|
|
110
|
+
const { stmt, query, logger } = this;
|
|
111
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
112
|
+
logger.logQuery(query.sql, params);
|
|
113
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
114
|
+
return await (params.length ? stmt.run(...params) : stmt.run());
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async all(placeholderValues) {
|
|
118
|
+
if (this.isRqbV2Query) return await this.allRqbV2(placeholderValues);
|
|
119
|
+
const { fields, logger, query, customResultMapper, joinsNotNullableMap, stmt } = this;
|
|
120
|
+
if (!fields && !customResultMapper) {
|
|
121
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
122
|
+
logger.logQuery(query.sql, params);
|
|
123
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
124
|
+
return await (params.length ? stmt.raw(false).all(...params) : stmt.raw(false).all());
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const rows = await this.values(placeholderValues);
|
|
128
|
+
return rows.map((row) => mapResultRow(fields, row, joinsNotNullableMap));
|
|
129
|
+
}
|
|
130
|
+
async allRqbV2(placeholderValues) {
|
|
131
|
+
const { logger, query, customResultMapper, stmt } = this;
|
|
132
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
133
|
+
logger.logQuery(query.sql, params);
|
|
134
|
+
const rows = await (params.length ? stmt.raw(false).all(...params) : stmt.raw(false).all());
|
|
135
|
+
return customResultMapper(rows);
|
|
136
|
+
}
|
|
137
|
+
async get(placeholderValues) {
|
|
138
|
+
if (this.isRqbV2Query) return await this.getRqbV2(placeholderValues);
|
|
139
|
+
const { fields, logger, query, stmt, customResultMapper, joinsNotNullableMap } = this;
|
|
140
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
141
|
+
if (!fields && !customResultMapper) {
|
|
142
|
+
logger.logQuery(query.sql, params);
|
|
143
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
144
|
+
return await (params.length ? stmt.raw(false).get(...params) : stmt.raw(false).get());
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const row = await this.queryWithCache(query.sql, params, async () => {
|
|
148
|
+
return await (params.length ? stmt.raw(true).get(...params) : stmt.raw(true).get());
|
|
149
|
+
});
|
|
150
|
+
if (row === void 0) return row;
|
|
151
|
+
return mapResultRow(fields, row, joinsNotNullableMap);
|
|
152
|
+
}
|
|
153
|
+
async getRqbV2(placeholderValues) {
|
|
154
|
+
const { logger, query, stmt, customResultMapper } = this;
|
|
155
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
156
|
+
logger.logQuery(query.sql, params);
|
|
157
|
+
const row = await (params.length ? stmt.raw(false).get(...params) : stmt.raw(false).get());
|
|
158
|
+
if (row === void 0) return row;
|
|
159
|
+
return customResultMapper([row]);
|
|
160
|
+
}
|
|
161
|
+
async values(placeholderValues) {
|
|
162
|
+
const { logger, stmt, query } = this;
|
|
163
|
+
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
164
|
+
logger.logQuery(query.sql, params);
|
|
165
|
+
return await this.queryWithCache(query.sql, params, async () => {
|
|
166
|
+
return await (params.length ? stmt.raw(true).all(...params) : stmt.raw(true).all());
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/** @internal */
|
|
170
|
+
isResponseInArrayMode() {
|
|
171
|
+
return this._isResponseInArrayMode;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
TursoDatabasePreparedQuery,
|
|
176
|
+
TursoDatabaseSession,
|
|
177
|
+
TursoDatabaseTransaction
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tursodatabase/session.ts"],"sourcesContent":["import type { DatabasePromise } from '@tursodatabase/database-common';\nimport type * as V1 from '~/_relations.ts';\nimport { type Cache, NoopCache } from '~/cache/core/index.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { fillPlaceholders, type Query, type 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 type {\n\tPreparedQueryConfig as PreparedQueryConfigBase,\n\tResult,\n\tSQLiteExecuteMethod,\n\tSQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { mapResultRow } from '~/utils.ts';\nimport type { TursoDatabaseRunResult } from './driver-core.ts';\n\nexport interface TursoDatabaseSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class TursoDatabaseSession<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends SQLiteSession<'async', TursoDatabaseRunResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'TursoDatabaseSession';\n\n\tprivate logger: Logger;\n\tprivate cache: Cache;\n\n\tconstructor(\n\t\tprivate client: DatabasePromise,\n\t\tdialect: SQLiteAsyncDialect,\n\t\tprivate relations: TRelations,\n\t\tprivate schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\tprivate options: TursoDatabaseSessionOptions,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache ?? new NoopCache();\n\t}\n\n\tprepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => unknown,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t): TursoDatabasePreparedQuery<T> {\n\t\tconst stmt = this.client.prepare(query.sql);\n\n\t\treturn new TursoDatabasePreparedQuery(\n\t\t\tstmt,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\texecuteMethod,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tcustomResultMapper: (rows: Record<string, unknown>[]) => unknown,\n\t): TursoDatabasePreparedQuery<T, true> {\n\t\tconst stmt = this.client.prepare(query.sql);\n\n\t\treturn new TursoDatabasePreparedQuery(\n\t\t\tstmt,\n\t\t\tquery,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfields,\n\t\t\texecuteMethod,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride async transaction<T>(\n\t\ttransaction: (db: TursoDatabaseTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>,\n\t\t_config?: SQLiteTransactionConfig,\n\t\ttx?: TursoDatabaseTransaction<TFullSchema, TRelations, TSchema>,\n\t): Promise<T> {\n\t\tconst session = new TursoDatabaseSession<TFullSchema, TRelations, TSchema>(\n\t\t\tthis.client,\n\t\t\tthis.dialect,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t\tthis.options,\n\t\t);\n\t\tconst localTx = tx ?? new TursoDatabaseTransaction<TFullSchema, TRelations, TSchema>(\n\t\t\t'async',\n\t\t\tthis.dialect,\n\t\t\tsession,\n\t\t\tthis.relations,\n\t\t\tthis.schema,\n\t\t);\n\n\t\tconst clientTx = this.client.transaction(async () => await transaction(localTx));\n\n\t\tconst result = await clientTx();\n\t\treturn result;\n\t}\n\n\toverride async run(query: SQL): Result<'async', TursoDatabaseRunResult> {\n\t\tconst staticQuery = this.dialect.sqlToQuery(query);\n\t\ttry {\n\t\t\treturn await this.prepareOneTimeQuery(staticQuery, undefined, 'run', false).run() as Result<\n\t\t\t\t'async',\n\t\t\t\tTursoDatabaseRunResult\n\t\t\t>;\n\t\t} catch (err) {\n\t\t\tthrow new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });\n\t\t}\n\t}\n\n\toverride async all<T = unknown>(query: SQL): Result<'async', T[]> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).all() as Result<\n\t\t\t'async',\n\t\t\tT[]\n\t\t>;\n\t}\n\n\toverride async get<T = unknown>(query: SQL): Result<'async', T> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).get() as Result<\n\t\t\t'async',\n\t\t\tT\n\t\t>;\n\t}\n\n\toverride async values<T extends any[] = unknown[]>(\n\t\tquery: SQL,\n\t): Result<'async', T[]> {\n\t\treturn await this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), undefined, 'run', false).values() as Result<\n\t\t\t'async',\n\t\t\tT[]\n\t\t>;\n\t}\n}\n\nexport class TursoDatabaseTransaction<\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends SQLiteTransaction<'async', TursoDatabaseRunResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'TursoDatabaseTransaction';\n\n\toverride async transaction<T>(\n\t\t_transaction: (tx: TursoDatabaseTransaction<TFullSchema, TRelations, TSchema>) => Promise<T>,\n\t): Promise<T> {\n\t\t// Not supported by driver\n\t\tthrow new Error('Nested transactions are not supported');\n\n\t\t// const savepointName = `sp${this.nestedIndex}`;\n\n\t\t// const tx = new TursoDatabaseTransaction(\n\t\t// \t'async',\n\t\t// \tthis.dialect,\n\t\t// \tthis.session,\n\t\t// \tthis.relations,\n\t\t// \tthis.schema,\n\t\t// \tthis.nestedIndex + 1,\n\t\t// );\n\n\t\t// await this.session.run(sql.raw(`savepoint ${savepointName}`));\n\t\t// try {\n\t\t// \tconst result = await (<TursoDatabaseSession<TFullSchema, TRelations, TSchema>> (this.session)).transaction(\n\t\t// \t\ttransaction,\n\t\t// \t\tundefined,\n\t\t// \t\ttx,\n\t\t// \t);\n\t\t// \tawait this.session.run(sql.raw(`release savepoint ${savepointName}`));\n\t\t// \treturn result;\n\t\t// } catch (err) {\n\t\t// \tawait this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t// \tthrow err;\n\t\t// }\n\t}\n}\n\nexport class TursoDatabasePreparedQuery<\n\tT extends PreparedQueryConfig = PreparedQueryConfig,\n\tTIsRqbV2 extends boolean = false,\n> extends SQLitePreparedQuery<\n\t{\n\t\ttype: 'async';\n\t\trun: TursoDatabaseRunResult;\n\t\tall: T['all'];\n\t\tget: T['get'];\n\t\tvalues: T['values'];\n\t\texecute: T['execute'];\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'TursoDatabasePreparedQuery';\n\n\tconstructor(\n\t\tprivate stmt: ReturnType<DatabasePromise['prepare']>,\n\t\tquery: Query,\n\t\tprivate logger: Logger,\n\t\tcache: Cache,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\t/** @internal */ public fields: SelectedFieldsOrdered | undefined,\n\t\texecuteMethod: SQLiteExecuteMethod,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown,\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper('async', executeMethod, query, cache, queryMetadata, cacheConfig);\n\t\tthis.customResultMapper = customResultMapper;\n\t\tthis.fields = fields;\n\t}\n\n\tasync run(placeholderValues?: Record<string, unknown>): Promise<TursoDatabaseRunResult> {\n\t\tconst { stmt, query, logger } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await (params.length ? stmt.run(...params) : stmt.run());\n\t\t});\n\t}\n\n\tasync all(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n\t\tif (this.isRqbV2Query) return await this.allRqbV2(placeholderValues);\n\n\t\tconst { fields, logger, query, customResultMapper, joinsNotNullableMap, stmt } = this;\n\t\tif (!fields && !customResultMapper) {\n\t\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\t\tlogger.logQuery(query.sql, params);\n\t\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\t\treturn await (params.length ? stmt.raw(false).all(...params) : stmt.raw(false).all());\n\t\t\t});\n\t\t}\n\n\t\tconst rows = await this.values(placeholderValues) as unknown[][];\n\n\t\treturn rows.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));\n\t}\n\n\tprivate async allRqbV2(placeholderValues?: Record<string, unknown>): Promise<T['all']> {\n\t\tconst { logger, query, customResultMapper, stmt } = this;\n\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tconst rows = await (params.length ? stmt.raw(false).all(...params) : stmt.raw(false).all());\n\n\t\treturn (customResultMapper as (\n\t\t\trows: Record<string, unknown>[],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown)(rows as Record<string, unknown>[]) as T['all'];\n\t}\n\n\tasync get(placeholderValues?: Record<string, unknown>): Promise<T['get']> {\n\t\tif (this.isRqbV2Query) return await this.getRqbV2(placeholderValues);\n\n\t\tconst { fields, logger, query, stmt, customResultMapper, joinsNotNullableMap } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\tlogger.logQuery(query.sql, params);\n\t\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\t\treturn await (params.length ? stmt.raw(false).get(...params) : stmt.raw(false).get());\n\t\t\t});\n\t\t}\n\n\t\tconst row = await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await (params.length ? stmt.raw(true).get(...params) : stmt.raw(true).get());\n\t\t});\n\n\t\tif (row === undefined) return row;\n\n\t\treturn mapResultRow(fields!, row, joinsNotNullableMap);\n\t}\n\n\tprivate async getRqbV2(placeholderValues?: Record<string, unknown>) {\n\t\tconst { logger, query, stmt, customResultMapper } = this;\n\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tconst row = await (params.length ? stmt.raw(false).get(...params) : stmt.raw(false).get());\n\n\t\tif (row === undefined) return row;\n\n\t\treturn (customResultMapper as (\n\t\t\trows: Record<string, unknown>[],\n\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t) => unknown)([row] as Record<string, unknown>[]) as T['get'];\n\t}\n\n\tasync values(placeholderValues?: Record<string, unknown>): Promise<T['values']> {\n\t\tconst { logger, stmt, query } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn await this.queryWithCache(query.sql, params, async () => {\n\t\t\treturn await (params.length ? stmt.raw(true).all(...params) : stmt.raw(true).all());\n\t\t});\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n"],"mappings":"AAEA,SAAqB,iBAAiB;AAEtC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAE7B,SAAS,kBAAkB;AAE3B,SAAS,wBAA8C;AAEvD,SAAS,yBAAyB;AAQlC,SAAS,qBAAqB,qBAAqB;AACnD,SAAS,oBAAoB;AAUtB,MAAM,6BAIH,cAAiF;AAAA,EAM1F,YACS,QACR,SACQ,WACA,QACA,SACP;AACD,UAAM,OAAO;AANL;AAEA;AACA;AACA;AAGR,SAAK,SAAS,QAAQ,UAAU,IAAI,WAAW;AAC/C,SAAK,QAAQ,QAAQ,SAAS,IAAI,UAAU;AAAA,EAC7C;AAAA,EAfA,QAA0B,UAAU,IAAY;AAAA,EAExC;AAAA,EACA;AAAA,EAcR,aACC,OACA,QACA,eACA,uBACA,oBACA,eAIA,aACgC;AAChC,UAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AAE1C,WAAO,IAAI;AAAA,MACV;AAAA,MACA;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,uBACC,OACA,QACA,eACA,oBACsC;AACtC,UAAM,OAAO,KAAK,OAAO,QAAQ,MAAM,GAA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,KAAK,mBAAmB;AAAA,EACtD;AAAA,EAEA,MAAc,SAAS,mBAA6C;AACnE,UAAM,EAAE,QAAQ,OAAO,MAAM,mBAAmB,IAAI;AAEpD,UAAM,SAAS,iBAAiB,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AACrE,WAAO,SAAS,MAAM,KAAK,MAAM;AAEjC,UAAM,MAAM,OAAO,OAAO,SAAS,KAAK,IAAI,KAAK,EAAE,IAAI,GAAG,MAAM,IAAI,KAAK,IAAI,KAAK,EAAE,IAAI;AAExF,QAAI,QAAQ,OAAW,QAAO;AAE9B,WAAQ,mBAGM,CAAC,GAAG,CAA8B;AAAA,EACjD;AAAA,EAEA,MAAM,OAAO,mBAAmE;AAC/E,UAAM,EAAE,QAAQ,MAAM,MAAM,IAAI;AAChC,UAAM,SAAS,iBAAiB,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AACrE,WAAO,SAAS,MAAM,KAAK,MAAM;AACjC,WAAO,MAAM,KAAK,eAAe,MAAM,KAAK,QAAQ,YAAY;AAC/D,aAAO,OAAO,OAAO,SAAS,KAAK,IAAI,IAAI,EAAE,IAAI,GAAG,MAAM,IAAI,KAAK,IAAI,IAAI,EAAE,IAAI;AAAA,IAClF,CAAC;AAAA,EACF;AAAA;AAAA,EAGA,wBAAiC;AAChC,WAAO,KAAK;AAAA,EACb;AACD;","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 wasm_exports = {};
|
|
20
|
+
__export(wasm_exports, {
|
|
21
|
+
drizzle: () => drizzle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(wasm_exports);
|
|
24
|
+
var import_database_wasm = require("@tursodatabase/database-wasm");
|
|
25
|
+
var import_utils = require("../utils.cjs");
|
|
26
|
+
var import_driver_core = require("./driver-core.cjs");
|
|
27
|
+
function drizzle(...params) {
|
|
28
|
+
if (typeof params[0] === "string") {
|
|
29
|
+
const instance = new import_database_wasm.Database(params[0]);
|
|
30
|
+
return (0, import_driver_core.construct)(instance, params[1]);
|
|
31
|
+
}
|
|
32
|
+
if ((0, import_utils.isConfig)(params[0])) {
|
|
33
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
34
|
+
if (client) return (0, import_driver_core.construct)(client, drizzleConfig);
|
|
35
|
+
const instance = typeof connection === "string" ? new import_database_wasm.Database(connection) : new import_database_wasm.Database(connection.path, connection);
|
|
36
|
+
return (0, import_driver_core.construct)(instance, drizzleConfig);
|
|
37
|
+
}
|
|
38
|
+
return (0, import_driver_core.construct)(params[0], params[1]);
|
|
39
|
+
}
|
|
40
|
+
((drizzle2) => {
|
|
41
|
+
function mock(config) {
|
|
42
|
+
return (0, import_driver_core.construct)({}, config);
|
|
43
|
+
}
|
|
44
|
+
drizzle2.mock = mock;
|
|
45
|
+
})(drizzle || (drizzle = {}));
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
drizzle
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=wasm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tursodatabase/wasm.ts"],"sourcesContent":["import { Database } from '@tursodatabase/database-wasm';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport { type DrizzleConfig, isConfig } from '~/utils.ts';\nimport { construct, type TursoDatabaseDatabase } from './driver-core.ts';\n\nexport type DatabaseOpts = (Database extends { new(path: string, opts: infer D): any } ? D : any) & {\n\tpath: string;\n};\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTClient extends Database = Database,\n>(\n\t...params: [\n\t\tTClient | string,\n\t] | [\n\t\tTClient | string,\n\t\tDrizzleConfig<TSchema, TRelations>,\n\t] | [\n\t\t(\n\t\t\t& DrizzleConfig<TSchema, TRelations>\n\t\t\t& ({\n\t\t\t\tconnection: string | DatabaseOpts;\n\t\t\t} | {\n\t\t\t\tclient: TClient;\n\t\t\t})\n\t\t),\n\t]\n): TursoDatabaseDatabase<TSchema, TRelations> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst instance = new Database(params[0]);\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: DatabaseOpts; client?: TClient }\n\t\t\t& DrizzleConfig<TSchema, TRelations>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? new Database(connection)\n\t\t\t: new Database(connection.path, connection);\n\n\t\treturn construct(instance, drizzleConfig) as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema, TRelations> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<\n\t\tTSchema extends Record<string, unknown> = Record<string, never>,\n\t\tTRelations extends AnyRelations = EmptyRelations,\n\t>(\n\t\tconfig?: DrizzleConfig<TSchema, TRelations>,\n\t): TursoDatabaseDatabase<TSchema, TRelations> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAyB;AAEzB,mBAA6C;AAC7C,yBAAsD;AAM/C,SAAS,WAKZ,QAiBF;AACD,MAAI,OAAO,OAAO,CAAC,MAAM,UAAU;AAClC,UAAM,WAAW,IAAI,8BAAS,OAAO,CAAC,CAAC;AAEvC,eAAO,8BAAU,UAAU,OAAO,CAAC,CAAC;AAAA,EACrC;AAEA,UAAI,uBAAS,OAAO,CAAC,CAAC,GAAG;AACxB,UAAM,EAAE,YAAY,QAAQ,GAAG,cAAc,IAAI,OAAO,CAAC;AAIzD,QAAI,OAAQ,YAAO,8BAAU,QAAQ,aAAa;AAElD,UAAM,WAAW,OAAO,eAAe,WACpC,IAAI,8BAAS,UAAU,IACvB,IAAI,8BAAS,WAAW,MAAM,UAAU;AAE3C,eAAO,8BAAU,UAAU,aAAa;AAAA,EACzC;AAEA,aAAO,8BAAU,OAAO,CAAC,GAAc,OAAO,CAAC,CAAmD;AACnG;AAAA,CAEO,CAAUA,aAAV;AACC,WAAS,KAIf,QAGC;AACD,eAAO,8BAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AATO,EAAAA,SAAS;AAAA,GADA;","names":["drizzle"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Database } from '@tursodatabase/database-wasm';
|
|
2
|
+
import type { AnyRelations, EmptyRelations } from "../relations.cjs";
|
|
3
|
+
import { type DrizzleConfig } from "../utils.cjs";
|
|
4
|
+
import { type TursoDatabaseDatabase } from "./driver-core.cjs";
|
|
5
|
+
export type DatabaseOpts = (Database extends {
|
|
6
|
+
new (path: string, opts: infer D): any;
|
|
7
|
+
} ? D : any) & {
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TClient extends Database = Database>(...params: [
|
|
11
|
+
TClient | string
|
|
12
|
+
] | [
|
|
13
|
+
TClient | string,
|
|
14
|
+
DrizzleConfig<TSchema, TRelations>
|
|
15
|
+
] | [
|
|
16
|
+
(DrizzleConfig<TSchema, TRelations> & ({
|
|
17
|
+
connection: string | DatabaseOpts;
|
|
18
|
+
} | {
|
|
19
|
+
client: TClient;
|
|
20
|
+
}))
|
|
21
|
+
]): TursoDatabaseDatabase<TSchema, TRelations> & {
|
|
22
|
+
$client: TClient;
|
|
23
|
+
};
|
|
24
|
+
export declare namespace drizzle {
|
|
25
|
+
function mock<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(config?: DrizzleConfig<TSchema, TRelations>): TursoDatabaseDatabase<TSchema, TRelations> & {
|
|
26
|
+
$client: '$client is not available on drizzle.mock()';
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Database } from '@tursodatabase/database-wasm';
|
|
2
|
+
import type { AnyRelations, EmptyRelations } from "../relations.js";
|
|
3
|
+
import { type DrizzleConfig } from "../utils.js";
|
|
4
|
+
import { type TursoDatabaseDatabase } from "./driver-core.js";
|
|
5
|
+
export type DatabaseOpts = (Database extends {
|
|
6
|
+
new (path: string, opts: infer D): any;
|
|
7
|
+
} ? D : any) & {
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations, TClient extends Database = Database>(...params: [
|
|
11
|
+
TClient | string
|
|
12
|
+
] | [
|
|
13
|
+
TClient | string,
|
|
14
|
+
DrizzleConfig<TSchema, TRelations>
|
|
15
|
+
] | [
|
|
16
|
+
(DrizzleConfig<TSchema, TRelations> & ({
|
|
17
|
+
connection: string | DatabaseOpts;
|
|
18
|
+
} | {
|
|
19
|
+
client: TClient;
|
|
20
|
+
}))
|
|
21
|
+
]): TursoDatabaseDatabase<TSchema, TRelations> & {
|
|
22
|
+
$client: TClient;
|
|
23
|
+
};
|
|
24
|
+
export declare namespace drizzle {
|
|
25
|
+
function mock<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(config?: DrizzleConfig<TSchema, TRelations>): TursoDatabaseDatabase<TSchema, TRelations> & {
|
|
26
|
+
$client: '$client is not available on drizzle.mock()';
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Database } from "@tursodatabase/database-wasm";
|
|
2
|
+
import { isConfig } from "../utils.js";
|
|
3
|
+
import { construct } from "./driver-core.js";
|
|
4
|
+
function drizzle(...params) {
|
|
5
|
+
if (typeof params[0] === "string") {
|
|
6
|
+
const instance = new Database(params[0]);
|
|
7
|
+
return construct(instance, params[1]);
|
|
8
|
+
}
|
|
9
|
+
if (isConfig(params[0])) {
|
|
10
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
11
|
+
if (client) return construct(client, drizzleConfig);
|
|
12
|
+
const instance = typeof connection === "string" ? new Database(connection) : new Database(connection.path, connection);
|
|
13
|
+
return construct(instance, drizzleConfig);
|
|
14
|
+
}
|
|
15
|
+
return construct(params[0], params[1]);
|
|
16
|
+
}
|
|
17
|
+
((drizzle2) => {
|
|
18
|
+
function mock(config) {
|
|
19
|
+
return construct({}, config);
|
|
20
|
+
}
|
|
21
|
+
drizzle2.mock = mock;
|
|
22
|
+
})(drizzle || (drizzle = {}));
|
|
23
|
+
export {
|
|
24
|
+
drizzle
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=wasm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tursodatabase/wasm.ts"],"sourcesContent":["import { Database } from '@tursodatabase/database-wasm';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport { type DrizzleConfig, isConfig } from '~/utils.ts';\nimport { construct, type TursoDatabaseDatabase } from './driver-core.ts';\n\nexport type DatabaseOpts = (Database extends { new(path: string, opts: infer D): any } ? D : any) & {\n\tpath: string;\n};\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTClient extends Database = Database,\n>(\n\t...params: [\n\t\tTClient | string,\n\t] | [\n\t\tTClient | string,\n\t\tDrizzleConfig<TSchema, TRelations>,\n\t] | [\n\t\t(\n\t\t\t& DrizzleConfig<TSchema, TRelations>\n\t\t\t& ({\n\t\t\t\tconnection: string | DatabaseOpts;\n\t\t\t} | {\n\t\t\t\tclient: TClient;\n\t\t\t})\n\t\t),\n\t]\n): TursoDatabaseDatabase<TSchema, TRelations> & {\n\t$client: TClient;\n} {\n\tif (typeof params[0] === 'string') {\n\t\tconst instance = new Database(params[0]);\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tif (isConfig(params[0])) {\n\t\tconst { connection, client, ...drizzleConfig } = params[0] as\n\t\t\t& { connection?: DatabaseOpts; client?: TClient }\n\t\t\t& DrizzleConfig<TSchema, TRelations>;\n\n\t\tif (client) return construct(client, drizzleConfig) as any;\n\n\t\tconst instance = typeof connection === 'string'\n\t\t\t? new Database(connection)\n\t\t\t: new Database(connection.path, connection);\n\n\t\treturn construct(instance, drizzleConfig) as any;\n\t}\n\n\treturn construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema, TRelations> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<\n\t\tTSchema extends Record<string, unknown> = Record<string, never>,\n\t\tTRelations extends AnyRelations = EmptyRelations,\n\t>(\n\t\tconfig?: DrizzleConfig<TSchema, TRelations>,\n\t): TursoDatabaseDatabase<TSchema, TRelations> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,SAA6B,gBAAgB;AAC7C,SAAS,iBAA6C;AAM/C,SAAS,WAKZ,QAiBF;AACD,MAAI,OAAO,OAAO,CAAC,MAAM,UAAU;AAClC,UAAM,WAAW,IAAI,SAAS,OAAO,CAAC,CAAC;AAEvC,WAAO,UAAU,UAAU,OAAO,CAAC,CAAC;AAAA,EACrC;AAEA,MAAI,SAAS,OAAO,CAAC,CAAC,GAAG;AACxB,UAAM,EAAE,YAAY,QAAQ,GAAG,cAAc,IAAI,OAAO,CAAC;AAIzD,QAAI,OAAQ,QAAO,UAAU,QAAQ,aAAa;AAElD,UAAM,WAAW,OAAO,eAAe,WACpC,IAAI,SAAS,UAAU,IACvB,IAAI,SAAS,WAAW,MAAM,UAAU;AAE3C,WAAO,UAAU,UAAU,aAAa;AAAA,EACzC;AAEA,SAAO,UAAU,OAAO,CAAC,GAAc,OAAO,CAAC,CAAmD;AACnG;AAAA,CAEO,CAAUA,aAAV;AACC,WAAS,KAIf,QAGC;AACD,WAAO,UAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AATO,EAAAA,SAAS;AAAA,GADA;","names":["drizzle"]}
|
package/version.cjs
CHANGED
package/version.d.cts
CHANGED
package/version.d.ts
CHANGED
package/version.js
CHANGED