drizzle-orm 0.35.1-74d2f4c → 0.35.2
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/better-sqlite3/driver.cjs +10 -9
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.cts +1 -1
- package/better-sqlite3/driver.d.ts +1 -1
- package/better-sqlite3/driver.js +10 -9
- package/better-sqlite3/driver.js.map +1 -1
- package/bun-sqlite/driver.cjs +10 -9
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.cts +1 -1
- package/bun-sqlite/driver.d.ts +1 -1
- package/bun-sqlite/driver.js +10 -9
- package/bun-sqlite/driver.js.map +1 -1
- package/libsql/driver.cjs +11 -13
- package/libsql/driver.cjs.map +1 -1
- package/libsql/driver.d.cts +1 -1
- package/libsql/driver.d.ts +1 -1
- package/libsql/driver.js +11 -13
- package/libsql/driver.js.map +1 -1
- package/mysql2/driver.cjs +11 -11
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +1 -1
- package/mysql2/driver.d.ts +1 -1
- package/mysql2/driver.js +11 -11
- package/mysql2/driver.js.map +1 -1
- package/neon-http/driver.cjs +10 -9
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +1 -1
- package/neon-http/driver.d.ts +1 -1
- package/neon-http/driver.js +10 -9
- package/neon-http/driver.js.map +1 -1
- package/neon-serverless/driver.cjs +10 -9
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +1 -1
- package/neon-serverless/driver.d.ts +1 -1
- package/neon-serverless/driver.js +10 -9
- package/neon-serverless/driver.js.map +1 -1
- package/node-postgres/driver.cjs +10 -10
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +2 -2
- package/node-postgres/driver.d.ts +2 -2
- package/node-postgres/driver.js +10 -10
- package/node-postgres/driver.js.map +1 -1
- package/package.json +50 -50
- package/pglite/driver.cjs +10 -9
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +1 -1
- package/pglite/driver.d.ts +1 -1
- package/pglite/driver.js +10 -9
- package/pglite/driver.js.map +1 -1
- package/planetscale-serverless/driver.cjs +10 -9
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +1 -1
- package/planetscale-serverless/driver.d.ts +1 -1
- package/planetscale-serverless/driver.js +10 -9
- package/planetscale-serverless/driver.js.map +1 -1
- package/postgres-js/driver.cjs +10 -9
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +1 -1
- package/postgres-js/driver.d.ts +1 -1
- package/postgres-js/driver.js +10 -9
- package/postgres-js/driver.js.map +1 -1
- package/tidb-serverless/driver.cjs +13 -12
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +2 -2
- package/tidb-serverless/driver.d.ts +2 -2
- package/tidb-serverless/driver.js +14 -13
- package/tidb-serverless/driver.js.map +1 -1
- package/utils.cjs +48 -0
- package/utils.cjs.map +1 -1
- package/utils.d.cts +2 -1
- package/utils.d.ts +2 -1
- package/utils.js +47 -0
- package/utils.js.map +1 -1
- package/vercel-postgres/driver.cjs +5 -7
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +3 -5
- package/vercel-postgres/driver.d.ts +3 -5
- package/vercel-postgres/driver.js +5 -7
- package/vercel-postgres/driver.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
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { AnyColumn } from './column.ts';\nimport { Column } from './column.ts';\nimport { is } from './entity.ts';\nimport type { Logger } from './logger.ts';\nimport type { SelectedFieldsOrdered } from './operations.ts';\nimport type { TableLike } from './query-builders/select.types.ts';\nimport { Param, SQL, View } from './sql/sql.ts';\nimport type { DriverValueDecoder } from './sql/sql.ts';\nimport { Subquery } from './subquery.ts';\nimport { getTableName, Table } from './table.ts';\nimport { ViewBaseConfig } from './view-common.ts';\n\n/** @internal */\nexport function mapResultRow<TResult>(\n\tcolumns: SelectedFieldsOrdered<AnyColumn>,\n\trow: unknown[],\n\tjoinsNotNullableMap: Record<string, boolean> | undefined,\n): TResult {\n\t// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise\n\tconst nullifyMap: Record<string, string | false> = {};\n\n\tconst result = columns.reduce<Record<string, any>>(\n\t\t(result, { path, field }, columnIndex) => {\n\t\t\tlet decoder: DriverValueDecoder<unknown, unknown>;\n\t\t\tif (is(field, Column)) {\n\t\t\t\tdecoder = field;\n\t\t\t} else if (is(field, SQL)) {\n\t\t\t\tdecoder = field.decoder;\n\t\t\t} else {\n\t\t\t\tdecoder = field.sql.decoder;\n\t\t\t}\n\t\t\tlet node = result;\n\t\t\tfor (const [pathChunkIndex, pathChunk] of path.entries()) {\n\t\t\t\tif (pathChunkIndex < path.length - 1) {\n\t\t\t\t\tif (!(pathChunk in node)) {\n\t\t\t\t\t\tnode[pathChunk] = {};\n\t\t\t\t\t}\n\t\t\t\t\tnode = node[pathChunk];\n\t\t\t\t} else {\n\t\t\t\t\tconst rawValue = row[columnIndex]!;\n\t\t\t\t\tconst value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);\n\n\t\t\t\t\tif (joinsNotNullableMap && is(field, Column) && path.length === 2) {\n\t\t\t\t\t\tconst objectName = path[0]!;\n\t\t\t\t\t\tif (!(objectName in nullifyMap)) {\n\t\t\t\t\t\t\tnullifyMap[objectName] = value === null ? getTableName(field.table) : false;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\ttypeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnullifyMap[objectName] = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t},\n\t\t{},\n\t);\n\n\t// Nullify all nested objects from nullifyMap that are nullable\n\tif (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {\n\t\tfor (const [objectName, tableName] of Object.entries(nullifyMap)) {\n\t\t\tif (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {\n\t\t\t\tresult[objectName] = null;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result as TResult;\n}\n\n/** @internal */\nexport function orderSelectedFields<TColumn extends AnyColumn>(\n\tfields: Record<string, unknown>,\n\tpathPrefix?: string[],\n): SelectedFieldsOrdered<TColumn> {\n\treturn Object.entries(fields).reduce<SelectedFieldsOrdered<AnyColumn>>((result, [name, field]) => {\n\t\tif (typeof name !== 'string') {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst newPath = pathPrefix ? [...pathPrefix, name] : [name];\n\t\tif (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased)) {\n\t\t\tresult.push({ path: newPath, field });\n\t\t} else if (is(field, Table)) {\n\t\t\tresult.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));\n\t\t} else {\n\t\t\tresult.push(...orderSelectedFields(field as Record<string, unknown>, newPath));\n\t\t}\n\t\treturn result;\n\t}, []) as SelectedFieldsOrdered<TColumn>;\n}\n\nexport function haveSameKeys(left: Record<string, unknown>, right: Record<string, unknown>) {\n\tconst leftKeys = Object.keys(left);\n\tconst rightKeys = Object.keys(right);\n\n\tif (leftKeys.length !== rightKeys.length) {\n\t\treturn false;\n\t}\n\n\tfor (const [index, key] of leftKeys.entries()) {\n\t\tif (key !== rightKeys[index]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/** @internal */\nexport function mapUpdateSet(table: Table, values: Record<string, unknown>): UpdateSet {\n\tconst entries: [string, UpdateSet[string]][] = Object.entries(values)\n\t\t.filter(([, value]) => value !== undefined)\n\t\t.map(([key, value]) => {\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (is(value, SQL)) {\n\t\t\t\treturn [key, value];\n\t\t\t} else {\n\t\t\t\treturn [key, new Param(value, table[Table.Symbol.Columns][key])];\n\t\t\t}\n\t\t});\n\n\tif (entries.length === 0) {\n\t\tthrow new Error('No values to set');\n\t}\n\n\treturn Object.fromEntries(entries);\n}\n\nexport type UpdateSet = Record<string, SQL | Param | null | undefined>;\n\nexport type OneOrMany<T> = T | T[];\n\nexport type Update<T, TUpdate> =\n\t& {\n\t\t[K in Exclude<keyof T, keyof TUpdate>]: T[K];\n\t}\n\t& TUpdate;\n\nexport type Simplify<T> =\n\t& {\n\t\t// @ts-ignore - \"Type parameter 'K' has a circular constraint\", not sure why\n\t\t[K in keyof T]: T[K];\n\t}\n\t& {};\n\nexport type SimplifyMappedType<T> = [T] extends [unknown] ? T : never;\n\nexport type ShallowRecord<K extends keyof any, T> = SimplifyMappedType<{ [P in K]: T }>;\n\nexport type Assume<T, U> = T extends U ? T : U;\n\nexport type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;\n\nexport interface DrizzleTypeError<T extends string> {\n\t$drizzleTypeError: T;\n}\n\nexport type ValueOrArray<T> = T | T[];\n\n/** @internal */\nexport function applyMixins(baseClass: any, extendedClasses: any[]) {\n\tfor (const extendedClass of extendedClasses) {\n\t\tfor (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {\n\t\t\tif (name === 'constructor') continue;\n\n\t\t\tObject.defineProperty(\n\t\t\t\tbaseClass.prototype,\n\t\t\t\tname,\n\t\t\t\tObject.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null),\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport type Or<T1, T2> = T1 extends true ? true : T2 extends true ? true : false;\n\nexport type IfThenElse<If, Then, Else> = If extends true ? Then : Else;\n\nexport type PromiseOf<T> = T extends Promise<infer U> ? U : T;\n\nexport type Writable<T> = {\n\t-readonly [P in keyof T]: T[P];\n};\n\nexport function getTableColumns<T extends Table>(table: T): T['_']['columns'] {\n\treturn table[Table.Symbol.Columns];\n}\n\n/** @internal */\nexport function getTableLikeName(table: TableLike): string | undefined {\n\treturn is(table, Subquery)\n\t\t? table._.alias\n\t\t: is(table, View)\n\t\t? table[ViewBaseConfig].name\n\t\t: is(table, SQL)\n\t\t? undefined\n\t\t: table[Table.Symbol.IsAlias]\n\t\t? table[Table.Symbol.Name]\n\t\t: table[Table.Symbol.BaseName];\n}\n\nexport type ColumnsWithTable<\n\tTTableName extends string,\n\tTForeignTableName extends string,\n\tTColumns extends AnyColumn<{ tableName: TTableName }>[],\n> = { [Key in keyof TColumns]: AnyColumn<{ tableName: TForeignTableName }> };\n\nexport type Casing = 'snake_case' | 'camelCase';\n\nexport interface DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> {\n\tlogger?: boolean | Logger;\n\tschema?: TSchema;\n\tcasing?: Casing;\n}\nexport type ValidateShape<T, ValidShape, TResult = T> = T extends ValidShape\n\t? Exclude<keyof T, keyof ValidShape> extends never ? TResult\n\t: DrizzleTypeError<\n\t\t`Invalid key(s): ${Exclude<(keyof T) & (string | number | bigint | boolean | null | undefined), keyof ValidShape>}`\n\t>\n\t: never;\n\nexport type KnownKeysOnly<T, U> = {\n\t[K in keyof T]: K extends keyof U ? T[K] : never;\n};\n\nexport type IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/** @internal */\nexport function getColumnNameAndConfig<\n\tTConfig extends Record<string, any> | undefined,\n>(a: string | TConfig | undefined, b: TConfig | undefined) {\n\treturn {\n\t\tname: typeof a === 'string' && a.length > 0 ? a : '' as string,\n\t\tconfig: typeof a === 'object' ? a : b as TConfig,\n\t};\n}\n\nexport type IfNotImported<T, Y, N> = unknown extends T ? Y : N;\n\nexport type ImportTypeError<TPackageName extends string> =\n\t`Please install \\`${TPackageName}\\`to allow Drizzle ORM to connect to the database`;\n\nexport type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends any\n\t?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1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { AnyColumn } from './column.ts';\nimport { Column } from './column.ts';\nimport { is } from './entity.ts';\nimport type { Logger } from './logger.ts';\nimport type { SelectedFieldsOrdered } from './operations.ts';\nimport type { TableLike } from './query-builders/select.types.ts';\nimport { Param, SQL, View } from './sql/sql.ts';\nimport type { DriverValueDecoder } from './sql/sql.ts';\nimport { Subquery } from './subquery.ts';\nimport { getTableName, Table } from './table.ts';\nimport { ViewBaseConfig } from './view-common.ts';\n\n/** @internal */\nexport function mapResultRow<TResult>(\n\tcolumns: SelectedFieldsOrdered<AnyColumn>,\n\trow: unknown[],\n\tjoinsNotNullableMap: Record<string, boolean> | undefined,\n): TResult {\n\t// Key -> nested object key, value -> table name if all fields in the nested object are from the same table, false otherwise\n\tconst nullifyMap: Record<string, string | false> = {};\n\n\tconst result = columns.reduce<Record<string, any>>(\n\t\t(result, { path, field }, columnIndex) => {\n\t\t\tlet decoder: DriverValueDecoder<unknown, unknown>;\n\t\t\tif (is(field, Column)) {\n\t\t\t\tdecoder = field;\n\t\t\t} else if (is(field, SQL)) {\n\t\t\t\tdecoder = field.decoder;\n\t\t\t} else {\n\t\t\t\tdecoder = field.sql.decoder;\n\t\t\t}\n\t\t\tlet node = result;\n\t\t\tfor (const [pathChunkIndex, pathChunk] of path.entries()) {\n\t\t\t\tif (pathChunkIndex < path.length - 1) {\n\t\t\t\t\tif (!(pathChunk in node)) {\n\t\t\t\t\t\tnode[pathChunk] = {};\n\t\t\t\t\t}\n\t\t\t\t\tnode = node[pathChunk];\n\t\t\t\t} else {\n\t\t\t\t\tconst rawValue = row[columnIndex]!;\n\t\t\t\t\tconst value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);\n\n\t\t\t\t\tif (joinsNotNullableMap && is(field, Column) && path.length === 2) {\n\t\t\t\t\t\tconst objectName = path[0]!;\n\t\t\t\t\t\tif (!(objectName in nullifyMap)) {\n\t\t\t\t\t\t\tnullifyMap[objectName] = value === null ? getTableName(field.table) : false;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\ttypeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnullifyMap[objectName] = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t},\n\t\t{},\n\t);\n\n\t// Nullify all nested objects from nullifyMap that are nullable\n\tif (joinsNotNullableMap && Object.keys(nullifyMap).length > 0) {\n\t\tfor (const [objectName, tableName] of Object.entries(nullifyMap)) {\n\t\t\tif (typeof tableName === 'string' && !joinsNotNullableMap[tableName]) {\n\t\t\t\tresult[objectName] = null;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result as TResult;\n}\n\n/** @internal */\nexport function orderSelectedFields<TColumn extends AnyColumn>(\n\tfields: Record<string, unknown>,\n\tpathPrefix?: string[],\n): SelectedFieldsOrdered<TColumn> {\n\treturn Object.entries(fields).reduce<SelectedFieldsOrdered<AnyColumn>>((result, [name, field]) => {\n\t\tif (typeof name !== 'string') {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst newPath = pathPrefix ? [...pathPrefix, name] : [name];\n\t\tif (is(field, Column) || is(field, SQL) || is(field, SQL.Aliased)) {\n\t\t\tresult.push({ path: newPath, field });\n\t\t} else if (is(field, Table)) {\n\t\t\tresult.push(...orderSelectedFields(field[Table.Symbol.Columns], newPath));\n\t\t} else {\n\t\t\tresult.push(...orderSelectedFields(field as Record<string, unknown>, newPath));\n\t\t}\n\t\treturn result;\n\t}, []) as SelectedFieldsOrdered<TColumn>;\n}\n\nexport function haveSameKeys(left: Record<string, unknown>, right: Record<string, unknown>) {\n\tconst leftKeys = Object.keys(left);\n\tconst rightKeys = Object.keys(right);\n\n\tif (leftKeys.length !== rightKeys.length) {\n\t\treturn false;\n\t}\n\n\tfor (const [index, key] of leftKeys.entries()) {\n\t\tif (key !== rightKeys[index]) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/** @internal */\nexport function mapUpdateSet(table: Table, values: Record<string, unknown>): UpdateSet {\n\tconst entries: [string, UpdateSet[string]][] = Object.entries(values)\n\t\t.filter(([, value]) => value !== undefined)\n\t\t.map(([key, value]) => {\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (is(value, SQL)) {\n\t\t\t\treturn [key, value];\n\t\t\t} else {\n\t\t\t\treturn [key, new Param(value, table[Table.Symbol.Columns][key])];\n\t\t\t}\n\t\t});\n\n\tif (entries.length === 0) {\n\t\tthrow new Error('No values to set');\n\t}\n\n\treturn Object.fromEntries(entries);\n}\n\nexport type UpdateSet = Record<string, SQL | Param | null | undefined>;\n\nexport type OneOrMany<T> = T | T[];\n\nexport type Update<T, TUpdate> =\n\t& {\n\t\t[K in Exclude<keyof T, keyof TUpdate>]: T[K];\n\t}\n\t& TUpdate;\n\nexport type Simplify<T> =\n\t& {\n\t\t// @ts-ignore - \"Type parameter 'K' has a circular constraint\", not sure why\n\t\t[K in keyof T]: T[K];\n\t}\n\t& {};\n\nexport type SimplifyMappedType<T> = [T] extends [unknown] ? T : never;\n\nexport type ShallowRecord<K extends keyof any, T> = SimplifyMappedType<{ [P in K]: T }>;\n\nexport type Assume<T, U> = T extends U ? T : U;\n\nexport type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;\n\nexport interface DrizzleTypeError<T extends string> {\n\t$drizzleTypeError: T;\n}\n\nexport type ValueOrArray<T> = T | T[];\n\n/** @internal */\nexport function applyMixins(baseClass: any, extendedClasses: any[]) {\n\tfor (const extendedClass of extendedClasses) {\n\t\tfor (const name of Object.getOwnPropertyNames(extendedClass.prototype)) {\n\t\t\tif (name === 'constructor') continue;\n\n\t\t\tObject.defineProperty(\n\t\t\t\tbaseClass.prototype,\n\t\t\t\tname,\n\t\t\t\tObject.getOwnPropertyDescriptor(extendedClass.prototype, name) || Object.create(null),\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport type Or<T1, T2> = T1 extends true ? true : T2 extends true ? true : false;\n\nexport type IfThenElse<If, Then, Else> = If extends true ? Then : Else;\n\nexport type PromiseOf<T> = T extends Promise<infer U> ? U : T;\n\nexport type Writable<T> = {\n\t-readonly [P in keyof T]: T[P];\n};\n\nexport function getTableColumns<T extends Table>(table: T): T['_']['columns'] {\n\treturn table[Table.Symbol.Columns];\n}\n\n/** @internal */\nexport function getTableLikeName(table: TableLike): string | undefined {\n\treturn is(table, Subquery)\n\t\t? table._.alias\n\t\t: is(table, View)\n\t\t? table[ViewBaseConfig].name\n\t\t: is(table, SQL)\n\t\t? undefined\n\t\t: table[Table.Symbol.IsAlias]\n\t\t? table[Table.Symbol.Name]\n\t\t: table[Table.Symbol.BaseName];\n}\n\nexport type ColumnsWithTable<\n\tTTableName extends string,\n\tTForeignTableName extends string,\n\tTColumns extends AnyColumn<{ tableName: TTableName }>[],\n> = { [Key in keyof TColumns]: AnyColumn<{ tableName: TForeignTableName }> };\n\nexport type Casing = 'snake_case' | 'camelCase';\n\nexport interface DrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> {\n\tlogger?: boolean | Logger;\n\tschema?: TSchema;\n\tcasing?: Casing;\n}\nexport type ValidateShape<T, ValidShape, TResult = T> = T extends ValidShape\n\t? Exclude<keyof T, keyof ValidShape> extends never ? TResult\n\t: DrizzleTypeError<\n\t\t`Invalid key(s): ${Exclude<(keyof T) & (string | number | bigint | boolean | null | undefined), keyof ValidShape>}`\n\t>\n\t: never;\n\nexport type KnownKeysOnly<T, U> = {\n\t[K in keyof T]: K extends keyof U ? T[K] : never;\n};\n\nexport type IsAny<T> = 0 extends (1 & T) ? true : false;\n\n/** @internal */\nexport function getColumnNameAndConfig<\n\tTConfig extends Record<string, any> | undefined,\n>(a: string | TConfig | undefined, b: TConfig | undefined) {\n\treturn {\n\t\tname: typeof a === 'string' && a.length > 0 ? a : '' as string,\n\t\tconfig: typeof a === 'object' ? a : b as TConfig,\n\t};\n}\n\nexport type IfNotImported<T, Y, N> = unknown extends T ? Y : N;\n\nexport type ImportTypeError<TPackageName extends string> =\n\t`Please install \\`${TPackageName}\\` to allow Drizzle ORM to connect to the database`;\n\nexport type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Keys extends any\n\t? Required<Pick<T, Keys>> & Partial<Omit<T, Keys>>\n\t: never;\n\ntype ExpectedConfigShape = {\n\tlogger?: boolean | {\n\t\tlogQuery(query: string, params: unknown[]): void;\n\t};\n\tschema?: Record<string, never>;\n\tcasing?: 'snake_case' | 'camelCase';\n};\n\n// If this errors, you must update config shape checker function with new config specs\nconst _: DrizzleConfig = {} as ExpectedConfigShape;\nconst __: ExpectedConfigShape = {} as DrizzleConfig;\n\nexport function isConfig(data: any): boolean {\n\tif (typeof data !== 'object' || data === null) return false;\n\n\tif (data.constructor.name !== 'Object') return false;\n\n\tif ('logger' in data) {\n\t\tconst type = typeof data['logger'];\n\t\tif (\n\t\t\ttype !== 'boolean' && (type !== 'object' || typeof data['logger']['logQuery'] !== 'function')\n\t\t\t&& type !== 'undefined'\n\t\t) return false;\n\n\t\treturn true;\n\t}\n\n\tif ('schema' in data) {\n\t\tconst type = typeof data['logger'];\n\t\tif (type !== 'object' && type !== 'undefined') return false;\n\n\t\treturn true;\n\t}\n\n\tif ('casing' in data) {\n\t\tconst type = typeof data['logger'];\n\t\tif (type !== 'string' && type !== 'undefined') return false;\n\n\t\treturn true;\n\t}\n\n\tif ('mode' in data) {\n\t\tif (data['mode'] !== 'default' || data['mode'] !== 'planetscale' || data['mode'] !== undefined) return false;\n\n\t\treturn true;\n\t}\n\n\tif ('connection' in data) {\n\t\tconst type = typeof data['connection'];\n\t\tif (type !== 'string' && type !== 'object' && type !== 'undefined') return false;\n\n\t\treturn true;\n\t}\n\n\tif ('client' in data) {\n\t\tconst type = typeof data['client'];\n\t\tif (type !== 'object' && type !== 'undefined') return false;\n\n\t\treturn true;\n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,IAAmB,CAAC;AAC1B,MAAM,KAA0B,CAAC;AAE1B,SAAS,SAAS,MAAoB;AAC5C,MAAI,OAAO,SAAS,YAAY,SAAS;AAAM,WAAO;AAEtD,MAAI,KAAK,YAAY,SAAS;AAAU,WAAO;AAE/C,MAAI,YAAY,MAAM;AACrB,UAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,QACC,SAAS,cAAc,SAAS,YAAY,OAAO,KAAK,QAAQ,EAAE,UAAU,MAAM,eAC/E,SAAS;AACX,aAAO;AAET,WAAO;AAAA,EACR;AAEA,MAAI,YAAY,MAAM;AACrB,UAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,QAAI,SAAS,YAAY,SAAS;AAAa,aAAO;AAEtD,WAAO;AAAA,EACR;AAEA,MAAI,YAAY,MAAM;AACrB,UAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,QAAI,SAAS,YAAY,SAAS;AAAa,aAAO;AAEtD,WAAO;AAAA,EACR;AAEA,MAAI,UAAU,MAAM;AACnB,QAAI,KAAK,MAAM,MAAM,aAAa,KAAK,MAAM,MAAM,iBAAiB,KAAK,MAAM,MAAM;AAAW,aAAO;AAEvG,WAAO;AAAA,EACR;AAEA,MAAI,gBAAgB,MAAM;AACzB,UAAM,OAAO,OAAO,KAAK,YAAY;AACrC,QAAI,SAAS,YAAY,SAAS,YAAY,SAAS;AAAa,aAAO;AAE3E,WAAO;AAAA,EACR;AAEA,MAAI,YAAY,MAAM;AACrB,UAAM,OAAO,OAAO,KAAK,QAAQ;AACjC,QAAI,SAAS,YAAY,SAAS;AAAa,aAAO;AAEtD,WAAO;AAAA,EACR;AAEA,MAAI,OAAO,KAAK,IAAI,EAAE,WAAW;AAAG,WAAO;AAE3C,SAAO;AACR;","names":["result"]}
|
|
@@ -29,6 +29,7 @@ var import_logger = require("../logger.cjs");
|
|
|
29
29
|
var import_db = require("../pg-core/db.cjs");
|
|
30
30
|
var import_pg_core = require("../pg-core/index.cjs");
|
|
31
31
|
var import_relations = require("../relations.cjs");
|
|
32
|
+
var import_utils = require("../utils.cjs");
|
|
32
33
|
var import_session = require("./session.cjs");
|
|
33
34
|
class VercelPgDriver {
|
|
34
35
|
constructor(client, dialect, options = {}) {
|
|
@@ -71,14 +72,11 @@ function construct(client, config = {}) {
|
|
|
71
72
|
return db;
|
|
72
73
|
}
|
|
73
74
|
function drizzle(...params) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
75
|
+
if ((0, import_utils.isConfig)(params[0])) {
|
|
76
|
+
const { client, ...drizzleConfig } = params[0];
|
|
77
|
+
return construct(client ?? import_postgres.sql, drizzleConfig);
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
return construct(import_postgres.sql, params[0]);
|
|
79
|
-
}
|
|
80
|
-
const { client, ...drizzleConfig } = params[0];
|
|
81
|
-
return construct(client ?? import_postgres.sql, drizzleConfig);
|
|
79
|
+
return construct(params[0] ?? import_postgres.sql, params[1]);
|
|
82
80
|
}
|
|
83
81
|
((drizzle2) => {
|
|
84
82
|
function mock(config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vercel-postgres/driver.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/vercel-postgres/driver.ts"],"sourcesContent":["import { sql, type VercelPool } from '@vercel/postgres';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { PgDatabase } from '~/pg-core/db.ts';\nimport { PgDialect } from '~/pg-core/index.ts';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport { type VercelPgClient, type VercelPgQueryResultHKT, VercelPgSession } from './session.ts';\n\nexport interface VercelPgDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class VercelPgDriver {\n\tstatic readonly [entityKind]: string = 'VercelPgDriver';\n\n\tconstructor(\n\t\tprivate client: VercelPgClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: VercelPgDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): VercelPgSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new VercelPgSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport class VercelPgDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends PgDatabase<VercelPgQueryResultHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'VercelPgDatabase';\n}\n\nfunction construct<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: VercelPgClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): VercelPgDatabase<TSchema> & {\n\t$client: VercelPgClient;\n} {\n\tconst dialect = new PgDialect({ 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 driver = new VercelPgDriver(client, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new VercelPgDatabase(dialect, session, schema as any) as VercelPgDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends VercelPgClient = typeof sql,\n>(\n\t...params: IfNotImported<\n\t\tVercelPool,\n\t\t[ImportTypeError<'@vercel/postgres'>],\n\t\t[] | [\n\t\t\tTClient,\n\t\t] | [\n\t\t\tTClient,\n\t\t\tDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& DrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tclient?: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): VercelPgDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (isConfig(params[0])) {\n\t\tconst { client, ...drizzleConfig } = params[0] as ({ client?: TClient } & DrizzleConfig<TSchema>);\n\t\treturn construct(client ?? sql, drizzleConfig) as any;\n\t}\n\n\treturn construct((params[0] ?? sql) as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: DrizzleConfig<TSchema>,\n\t): VercelPgDatabase<TSchema> & {\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;AAAA;AAAA,sBAAqC;AACrC,oBAA2B;AAE3B,oBAA8B;AAC9B,gBAA2B;AAC3B,qBAA0B;AAC1B,uBAKO;AACP,mBAAuF;AACvF,qBAAkF;AAM3E,MAAM,eAAe;AAAA,EAG3B,YACS,QACA,SACA,UAAiC,CAAC,GACzC;AAHO;AACA;AACA;AAAA,EAET;AAAA,EAPA,QAAiB,wBAAU,IAAY;AAAA,EASvC,cACC,QACmE;AACnE,WAAO,IAAI,+BAAgB,KAAK,QAAQ,KAAK,SAAS,QAAQ,EAAE,QAAQ,KAAK,QAAQ,OAAO,CAAC;AAAA,EAC9F;AACD;AAEO,MAAM,yBAEH,qBAA4C;AAAA,EACrD,QAA0B,wBAAU,IAAY;AACjD;AAEA,SAAS,UACR,QACA,SAAiC,CAAC,GAGjC;AACD,QAAM,UAAU,IAAI,yBAAU,EAAE,QAAQ,OAAO,OAAO,CAAC;AACvD,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,SAAS,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,CAAC;AAC7D,QAAM,UAAU,OAAO,cAAc,MAAM;AAC3C,QAAM,KAAK,IAAI,iBAAiB,SAAS,SAAS,MAAa;AAC/D,EAAO,GAAI,UAAU;AAErB,SAAO;AACR;AAEO,SAAS,WAIZ,QAmBF;AACD,UAAI,uBAAS,OAAO,CAAC,CAAC,GAAG;AACxB,UAAM,EAAE,QAAQ,GAAG,cAAc,IAAI,OAAO,CAAC;AAC7C,WAAO,UAAU,UAAU,qBAAK,aAAa;AAAA,EAC9C;AAEA,SAAO,UAAW,OAAO,CAAC,KAAK,qBAAiB,OAAO,CAAC,CAAuC;AAChG;AAAA,CAEO,CAAUA,aAAV;AACC,WAAS,KACf,QAGC;AACD,WAAO,UAAU,CAAC,GAAU,MAAM;AAAA,EACnC;AANO,EAAAA,SAAS;AAAA,GADA;","names":["drizzle"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql, type VercelPool } from '@vercel/postgres';
|
|
2
2
|
import { entityKind } from "../entity.cjs";
|
|
3
3
|
import type { Logger } from "../logger.cjs";
|
|
4
4
|
import { PgDatabase } from "../pg-core/db.cjs";
|
|
5
5
|
import { PgDialect } from "../pg-core/index.cjs";
|
|
6
6
|
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.cjs";
|
|
7
|
-
import type
|
|
7
|
+
import { type DrizzleConfig, type IfNotImported, type ImportTypeError } from "../utils.cjs";
|
|
8
8
|
import { type VercelPgClient, type VercelPgQueryResultHKT, VercelPgSession } from "./session.cjs";
|
|
9
9
|
export interface VercelPgDriverOptions {
|
|
10
10
|
logger?: Logger;
|
|
@@ -20,8 +20,7 @@ export declare class VercelPgDriver {
|
|
|
20
20
|
export declare class VercelPgDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<VercelPgQueryResultHKT, TSchema> {
|
|
21
21
|
static readonly [entityKind]: string;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends VercelPgClient = VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>)>(...params: IfNotImported<VercelPool, [
|
|
23
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends VercelPgClient = typeof sql>(...params: IfNotImported<VercelPool, [
|
|
25
24
|
ImportTypeError<'@vercel/postgres'>
|
|
26
25
|
], [
|
|
27
26
|
] | [
|
|
@@ -41,4 +40,3 @@ export declare namespace drizzle {
|
|
|
41
40
|
$client: '$client is not available on drizzle.mock()';
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql, type VercelPool } from '@vercel/postgres';
|
|
2
2
|
import { entityKind } from "../entity.js";
|
|
3
3
|
import type { Logger } from "../logger.js";
|
|
4
4
|
import { PgDatabase } from "../pg-core/db.js";
|
|
5
5
|
import { PgDialect } from "../pg-core/index.js";
|
|
6
6
|
import { type RelationalSchemaConfig, type TablesRelationalConfig } from "../relations.js";
|
|
7
|
-
import type
|
|
7
|
+
import { type DrizzleConfig, type IfNotImported, type ImportTypeError } from "../utils.js";
|
|
8
8
|
import { type VercelPgClient, type VercelPgQueryResultHKT, VercelPgSession } from "./session.js";
|
|
9
9
|
export interface VercelPgDriverOptions {
|
|
10
10
|
logger?: Logger;
|
|
@@ -20,8 +20,7 @@ export declare class VercelPgDriver {
|
|
|
20
20
|
export declare class VercelPgDatabase<TSchema extends Record<string, unknown> = Record<string, never>> extends PgDatabase<VercelPgQueryResultHKT, TSchema> {
|
|
21
21
|
static readonly [entityKind]: string;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends VercelPgClient = VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>)>(...params: IfNotImported<VercelPool, [
|
|
23
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>, TClient extends VercelPgClient = typeof sql>(...params: IfNotImported<VercelPool, [
|
|
25
24
|
ImportTypeError<'@vercel/postgres'>
|
|
26
25
|
], [
|
|
27
26
|
] | [
|
|
@@ -41,4 +40,3 @@ export declare namespace drizzle {
|
|
|
41
40
|
$client: '$client is not available on drizzle.mock()';
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
export {};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createTableRelationsHelpers,
|
|
8
8
|
extractTablesRelationalConfig
|
|
9
9
|
} from "../relations.js";
|
|
10
|
+
import { isConfig } from "../utils.js";
|
|
10
11
|
import { VercelPgSession } from "./session.js";
|
|
11
12
|
class VercelPgDriver {
|
|
12
13
|
constructor(client, dialect, options = {}) {
|
|
@@ -49,14 +50,11 @@ function construct(client, config = {}) {
|
|
|
49
50
|
return db;
|
|
50
51
|
}
|
|
51
52
|
function drizzle(...params) {
|
|
52
|
-
if (
|
|
53
|
-
|
|
53
|
+
if (isConfig(params[0])) {
|
|
54
|
+
const { client, ...drizzleConfig } = params[0];
|
|
55
|
+
return construct(client ?? sql, drizzleConfig);
|
|
54
56
|
}
|
|
55
|
-
|
|
56
|
-
return construct(sql, params[0]);
|
|
57
|
-
}
|
|
58
|
-
const { client, ...drizzleConfig } = params[0];
|
|
59
|
-
return construct(client ?? sql, drizzleConfig);
|
|
57
|
+
return construct(params[0] ?? sql, params[1]);
|
|
60
58
|
}
|
|
61
59
|
((drizzle2) => {
|
|
62
60
|
function mock(config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vercel-postgres/driver.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/vercel-postgres/driver.ts"],"sourcesContent":["import { sql, type VercelPool } from '@vercel/postgres';\nimport { entityKind } from '~/entity.ts';\nimport type { Logger } from '~/logger.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport { PgDatabase } from '~/pg-core/db.ts';\nimport { PgDialect } from '~/pg-core/index.ts';\nimport {\n\tcreateTableRelationsHelpers,\n\textractTablesRelationalConfig,\n\ttype RelationalSchemaConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';\nimport { type VercelPgClient, type VercelPgQueryResultHKT, VercelPgSession } from './session.ts';\n\nexport interface VercelPgDriverOptions {\n\tlogger?: Logger;\n}\n\nexport class VercelPgDriver {\n\tstatic readonly [entityKind]: string = 'VercelPgDriver';\n\n\tconstructor(\n\t\tprivate client: VercelPgClient,\n\t\tprivate dialect: PgDialect,\n\t\tprivate options: VercelPgDriverOptions = {},\n\t) {\n\t}\n\n\tcreateSession(\n\t\tschema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,\n\t): VercelPgSession<Record<string, unknown>, TablesRelationalConfig> {\n\t\treturn new VercelPgSession(this.client, this.dialect, schema, { logger: this.options.logger });\n\t}\n}\n\nexport class VercelPgDatabase<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n> extends PgDatabase<VercelPgQueryResultHKT, TSchema> {\n\tstatic override readonly [entityKind]: string = 'VercelPgDatabase';\n}\n\nfunction construct<TSchema extends Record<string, unknown> = Record<string, never>>(\n\tclient: VercelPgClient,\n\tconfig: DrizzleConfig<TSchema> = {},\n): VercelPgDatabase<TSchema> & {\n\t$client: VercelPgClient;\n} {\n\tconst dialect = new PgDialect({ 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 driver = new VercelPgDriver(client, dialect, { logger });\n\tconst session = driver.createSession(schema);\n\tconst db = new VercelPgDatabase(dialect, session, schema as any) as VercelPgDatabase<TSchema>;\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n\tTClient extends VercelPgClient = typeof sql,\n>(\n\t...params: IfNotImported<\n\t\tVercelPool,\n\t\t[ImportTypeError<'@vercel/postgres'>],\n\t\t[] | [\n\t\t\tTClient,\n\t\t] | [\n\t\t\tTClient,\n\t\t\tDrizzleConfig<TSchema>,\n\t\t] | [\n\t\t\t(\n\t\t\t\t& DrizzleConfig<TSchema>\n\t\t\t\t& ({\n\t\t\t\t\tclient?: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n\t>\n): VercelPgDatabase<TSchema> & {\n\t$client: TClient;\n} {\n\tif (isConfig(params[0])) {\n\t\tconst { client, ...drizzleConfig } = params[0] as ({ client?: TClient } & DrizzleConfig<TSchema>);\n\t\treturn construct(client ?? sql, drizzleConfig) as any;\n\t}\n\n\treturn construct((params[0] ?? sql) as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TSchema extends Record<string, unknown> = Record<string, never>>(\n\t\tconfig?: DrizzleConfig<TSchema>,\n\t): VercelPgDatabase<TSchema> & {\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,WAA4B;AACrC,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAuE,gBAAgB;AACvF,SAA2D,uBAAuB;AAM3E,MAAM,eAAe;AAAA,EAG3B,YACS,QACA,SACA,UAAiC,CAAC,GACzC;AAHO;AACA;AACA;AAAA,EAET;AAAA,EAPA,QAAiB,UAAU,IAAY;AAAA,EASvC,cACC,QACmE;AACnE,WAAO,IAAI,gBAAgB,KAAK,QAAQ,KAAK,SAAS,QAAQ,EAAE,QAAQ,KAAK,QAAQ,OAAO,CAAC;AAAA,EAC9F;AACD;AAEO,MAAM,yBAEH,WAA4C;AAAA,EACrD,QAA0B,UAAU,IAAY;AACjD;AAEA,SAAS,UACR,QACA,SAAiC,CAAC,GAGjC;AACD,QAAM,UAAU,IAAI,UAAU,EAAE,QAAQ,OAAO,OAAO,CAAC;AACvD,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,SAAS,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,CAAC;AAC7D,QAAM,UAA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