drizzle-orm 0.33.0-ff1dcd9 → 0.34.0-178591
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/aws-data-api/common/index.d.cts +1 -1
- package/aws-data-api/common/index.d.ts +1 -1
- package/better-sqlite3/driver.cjs +7 -1
- package/better-sqlite3/driver.cjs.map +1 -1
- package/better-sqlite3/driver.d.cts +4 -1
- package/better-sqlite3/driver.d.ts +4 -1
- package/better-sqlite3/driver.js +6 -1
- package/better-sqlite3/driver.js.map +1 -1
- package/bun-sqlite/driver.cjs +7 -1
- package/bun-sqlite/driver.cjs.map +1 -1
- package/bun-sqlite/driver.d.cts +4 -1
- package/bun-sqlite/driver.d.ts +4 -1
- package/bun-sqlite/driver.js +6 -1
- package/bun-sqlite/driver.js.map +1 -1
- package/expo-sqlite/driver.cjs +7 -1
- package/expo-sqlite/driver.cjs.map +1 -1
- package/expo-sqlite/driver.d.cts +4 -1
- package/expo-sqlite/driver.d.ts +4 -1
- package/expo-sqlite/driver.js +6 -1
- package/expo-sqlite/driver.js.map +1 -1
- package/index.cjs +4 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/libsql/migrator.cjs.map +1 -1
- package/libsql/migrator.d.cts +1 -1
- package/libsql/migrator.d.ts +1 -1
- package/libsql/migrator.js.map +1 -1
- package/monodriver.cjs +177 -0
- package/monodriver.cjs.map +1 -0
- package/monodriver.d.cts +140 -0
- package/monodriver.d.ts +140 -0
- package/monodriver.js +143 -0
- package/monodriver.js.map +1 -0
- package/monomigrator.cjs +95 -0
- package/monomigrator.cjs.map +1 -0
- package/monomigrator.d.cts +15 -0
- package/monomigrator.d.ts +15 -0
- package/monomigrator.js +61 -0
- package/monomigrator.js.map +1 -0
- package/mysql-core/db.cjs +4 -0
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +4 -1
- package/mysql-core/db.d.ts +4 -1
- package/mysql-core/db.js +4 -0
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/query-builders/count.cjs +73 -0
- package/mysql-core/query-builders/count.cjs.map +1 -0
- package/mysql-core/query-builders/count.d.cts +27 -0
- package/mysql-core/query-builders/count.d.ts +27 -0
- package/mysql-core/query-builders/count.js +49 -0
- package/mysql-core/query-builders/count.js.map +1 -0
- package/mysql-core/session.cjs +6 -0
- package/mysql-core/session.cjs.map +1 -1
- package/mysql-core/session.d.cts +1 -0
- package/mysql-core/session.d.ts +1 -0
- package/mysql-core/session.js +6 -0
- package/mysql-core/session.js.map +1 -1
- package/mysql-proxy/driver.cjs +7 -1
- package/mysql-proxy/driver.cjs.map +1 -1
- package/mysql-proxy/driver.d.cts +4 -1
- package/mysql-proxy/driver.d.ts +4 -1
- package/mysql-proxy/driver.js +6 -1
- package/mysql-proxy/driver.js.map +1 -1
- package/mysql2/driver.cjs +6 -1
- package/mysql2/driver.cjs.map +1 -1
- package/mysql2/driver.d.cts +3 -1
- package/mysql2/driver.d.ts +3 -1
- package/mysql2/driver.js +5 -1
- package/mysql2/driver.js.map +1 -1
- package/mysql2/migrator.cjs +4 -1
- package/mysql2/migrator.cjs.map +1 -1
- package/mysql2/migrator.d.cts +1 -1
- package/mysql2/migrator.d.ts +1 -1
- package/mysql2/migrator.js +4 -1
- package/mysql2/migrator.js.map +1 -1
- package/neon-http/session.cjs +6 -0
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +2 -1
- package/neon-http/session.d.ts +2 -1
- package/neon-http/session.js +6 -0
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/driver.cjs +6 -1
- package/neon-serverless/driver.cjs.map +1 -1
- package/neon-serverless/driver.d.cts +3 -1
- package/neon-serverless/driver.d.ts +3 -1
- package/neon-serverless/driver.js +5 -1
- package/neon-serverless/driver.js.map +1 -1
- package/node-postgres/driver.cjs +6 -1
- package/node-postgres/driver.cjs.map +1 -1
- package/node-postgres/driver.d.cts +3 -1
- package/node-postgres/driver.d.ts +3 -1
- package/node-postgres/driver.js +5 -1
- package/node-postgres/driver.js.map +1 -1
- package/node-postgres/session.cjs +6 -0
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +2 -1
- package/node-postgres/session.d.ts +2 -1
- package/node-postgres/session.js +6 -0
- package/node-postgres/session.js.map +1 -1
- package/op-sqlite/driver.cjs +7 -1
- package/op-sqlite/driver.cjs.map +1 -1
- package/op-sqlite/driver.d.cts +4 -1
- package/op-sqlite/driver.d.ts +4 -1
- package/op-sqlite/driver.js +6 -1
- package/op-sqlite/driver.js.map +1 -1
- package/operations.cjs.map +1 -1
- package/package.json +61 -1
- package/pg-core/db.cjs +4 -0
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +5 -2
- package/pg-core/db.d.ts +5 -2
- package/pg-core/db.js +4 -0
- package/pg-core/db.js.map +1 -1
- package/pg-core/query-builders/count.cjs +73 -0
- package/pg-core/query-builders/count.cjs.map +1 -0
- package/pg-core/query-builders/count.d.cts +26 -0
- package/pg-core/query-builders/count.d.ts +26 -0
- package/pg-core/query-builders/count.js +49 -0
- package/pg-core/query-builders/count.js.map +1 -0
- package/pg-core/session.cjs +6 -0
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +1 -0
- package/pg-core/session.d.ts +1 -0
- package/pg-core/session.js +6 -0
- package/pg-core/session.js.map +1 -1
- package/pg-proxy/driver.cjs +7 -1
- package/pg-proxy/driver.cjs.map +1 -1
- package/pg-proxy/driver.d.cts +4 -1
- package/pg-proxy/driver.d.ts +4 -1
- package/pg-proxy/driver.js +6 -1
- package/pg-proxy/driver.js.map +1 -1
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.js.map +1 -1
- package/pglite/driver.cjs +6 -1
- package/pglite/driver.cjs.map +1 -1
- package/pglite/driver.d.cts +3 -1
- package/pglite/driver.d.ts +3 -1
- package/pglite/driver.js +5 -1
- package/pglite/driver.js.map +1 -1
- package/pglite/session.cjs +6 -0
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.d.cts +2 -1
- package/pglite/session.d.ts +2 -1
- package/pglite/session.js +6 -0
- package/pglite/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +7 -1
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +4 -1
- package/planetscale-serverless/driver.d.ts +4 -1
- package/planetscale-serverless/driver.js +6 -1
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/migrator.cjs +4 -1
- package/planetscale-serverless/migrator.cjs.map +1 -1
- package/planetscale-serverless/migrator.d.cts +1 -1
- package/planetscale-serverless/migrator.d.ts +1 -1
- package/planetscale-serverless/migrator.js +4 -1
- package/planetscale-serverless/migrator.js.map +1 -1
- package/planetscale-serverless/session.cjs +6 -0
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +1 -0
- package/planetscale-serverless/session.d.ts +1 -0
- package/planetscale-serverless/session.js +6 -0
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/driver.cjs +7 -1
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.d.cts +4 -1
- package/postgres-js/driver.d.ts +4 -1
- package/postgres-js/driver.js +6 -1
- package/postgres-js/driver.js.map +1 -1
- package/sqlite-core/db.cjs +4 -0
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +4 -1
- package/sqlite-core/db.d.ts +4 -1
- package/sqlite-core/db.js +4 -0
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/query-builders/count.cjs +72 -0
- package/sqlite-core/query-builders/count.cjs.map +1 -0
- package/sqlite-core/query-builders/count.d.cts +27 -0
- package/sqlite-core/query-builders/count.d.ts +27 -0
- package/sqlite-core/query-builders/count.js +48 -0
- package/sqlite-core/query-builders/count.js.map +1 -0
- package/sqlite-core/session.cjs +4 -0
- package/sqlite-core/session.cjs.map +1 -1
- package/sqlite-core/session.d.cts +1 -0
- package/sqlite-core/session.d.ts +1 -0
- package/sqlite-core/session.js +4 -0
- package/sqlite-core/session.js.map +1 -1
- package/tidb-serverless/driver.cjs +7 -1
- package/tidb-serverless/driver.cjs.map +1 -1
- package/tidb-serverless/driver.d.cts +4 -1
- package/tidb-serverless/driver.d.ts +4 -1
- package/tidb-serverless/driver.js +6 -1
- package/tidb-serverless/driver.js.map +1 -1
- package/tidb-serverless/session.cjs +6 -0
- package/tidb-serverless/session.cjs.map +1 -1
- package/tidb-serverless/session.d.cts +1 -0
- package/tidb-serverless/session.d.ts +1 -0
- package/tidb-serverless/session.js +6 -0
- package/tidb-serverless/session.js.map +1 -1
- package/vercel-postgres/driver.cjs +6 -1
- package/vercel-postgres/driver.cjs.map +1 -1
- package/vercel-postgres/driver.d.cts +3 -1
- package/vercel-postgres/driver.d.ts +3 -1
- package/vercel-postgres/driver.js +5 -1
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monodriver.ts"],"sourcesContent":["/* eslint-disable import/extensions */\nimport type { RDSDataClient, RDSDataClientConfig, RDSDataClientConfig as RDSConfig } from '@aws-sdk/client-rds-data';\nimport type { Client as LibsqlClient, Config as LibsqlConfig } from '@libsql/client';\nimport type {\n\tHTTPTransactionOptions as NeonHttpConfig,\n\tNeonQueryFunction,\n\tPool as NeonServerlessPool,\n\tPoolConfig as NeonServerlessConfig,\n} from '@neondatabase/serverless';\nimport type { Client as PlanetscaleClient, Config as PlanetscaleConfig } from '@planetscale/database';\nimport type { Config as TiDBServerlessConfig, Connection as TiDBConnection } from '@tidbcloud/serverless';\nimport type { QueryResult, QueryResultRow, VercelPool } from '@vercel/postgres';\nimport type { Database as BetterSQLite3Database, Options as BetterSQLite3Options } from 'better-sqlite3';\nimport type { Database as BunDatabase } from 'bun:sqlite';\nimport type { Pool as Mysql2Pool, PoolOptions as Mysql2Config } from 'mysql2';\nimport type { Pool as NodePgPool, PoolConfig as NodePGPoolConfig } from 'pg';\nimport type {\n\tOptions as PostgresJSOptions,\n\tPostgresType as PostgresJSPostgresType,\n\tSql as PostgresJsClient,\n} from 'postgres';\nimport type { AwsDataApiPgDatabase, DrizzleAwsDataApiPgConfig } from './aws-data-api/pg/index.ts';\nimport type { BetterSQLite3Database as DrizzleBetterSQLite3Database } from './better-sqlite3/index.ts';\nimport type { BunSQLiteDatabase } from './bun-sqlite/index.ts';\nimport type { DrizzleD1Database } from './d1/index.ts';\nimport type { LibSQLDatabase } from './libsql/index.ts';\nimport type { MySql2Database, MySql2DrizzleConfig } from './mysql2/index.ts';\nimport type { NeonHttpDatabase } from './neon-http/index.ts';\nimport type { NeonDatabase } from './neon-serverless/index.ts';\nimport type { NodePgDatabase } from './node-postgres/index.ts';\nimport type { PlanetScaleDatabase } from './planetscale-serverless/index.ts';\nimport type { PostgresJsDatabase } from './postgres-js/index.ts';\nimport type { TiDBServerlessDatabase } from './tidb-serverless/index.ts';\nimport type { DrizzleConfig } from './utils.ts';\nimport type { VercelPgDatabase } from './vercel-postgres/index.ts';\n\ntype BunSqliteDatabaseOptions =\n\t| number\n\t| {\n\t\t/**\n\t\t * Open the database as read-only (no write operations, no create).\n\t\t *\n\t\t * Equivalent to {@link constants.SQLITE_OPEN_READONLY}\n\t\t */\n\t\treadonly?: boolean;\n\t\t/**\n\t\t * Allow creating a new database\n\t\t *\n\t\t * Equivalent to {@link constants.SQLITE_OPEN_CREATE}\n\t\t */\n\t\tcreate?: boolean;\n\t\t/**\n\t\t * Open the database as read-write\n\t\t *\n\t\t * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}\n\t\t */\n\t\treadwrite?: boolean;\n\t};\n\ntype BunSqliteDatabaseConfig =\n\t| {\n\t\tfilename?: ':memory:' | (string & {});\n\t\toptions?: BunSqliteDatabaseOptions;\n\t}\n\t| ':memory:'\n\t| (string & {})\n\t| undefined;\n\ntype BetterSQLite3DatabaseConfig =\n\t| {\n\t\tfilename?:\n\t\t\t| ':memory:'\n\t\t\t| (string & {})\n\t\t\t| Buffer;\n\t\toptions?: BetterSQLite3Options;\n\t}\n\t| ':memory:'\n\t| (string & {})\n\t| undefined;\n\ntype MonodriverNeonHttpConfig = {\n\tconnectionString: string;\n\toptions?: NeonHttpConfig<boolean, boolean>;\n};\n\ntype VercelPrimitive = string | number | boolean | undefined | null;\n\ntype DatabaseClient =\n\t| 'node-postgres'\n\t| 'postgres-js'\n\t| 'neon-serverless'\n\t| 'neon-http'\n\t| 'vercel-postgres'\n\t| 'aws-data-api-pg'\n\t| 'planetscale'\n\t| 'mysql2'\n\t| 'tidb-serverless'\n\t| 'libsql'\n\t| 'd1'\n\t| 'bun:sqlite'\n\t| 'better-sqlite3';\n\ntype ClientDrizzleInstanceMap<TSchema extends Record<string, any>> = {\n\t'node-postgres': NodePgDatabase<TSchema>;\n\t'postgres-js': PostgresJsDatabase<TSchema>;\n\t'neon-serverless': NeonDatabase<TSchema>;\n\t'neon-http': NeonHttpDatabase<TSchema>;\n\t'vercel-postgres': VercelPgDatabase<TSchema>;\n\t'aws-data-api-pg': AwsDataApiPgDatabase<TSchema>;\n\tplanetscale: PlanetScaleDatabase<TSchema>;\n\tmysql2: MySql2Database<TSchema>;\n\t'tidb-serverless': TiDBServerlessDatabase<TSchema>;\n\tlibsql: LibSQLDatabase<TSchema>;\n\td1: DrizzleD1Database<TSchema>;\n\t'bun:sqlite': BunSQLiteDatabase<TSchema>;\n\t'better-sqlite3': DrizzleBetterSQLite3Database<TSchema>;\n};\n\ntype ClientInstanceMap = {\n\t'node-postgres': NodePgPool;\n\t'postgres-js': PostgresJsClient;\n\t'neon-serverless': NeonServerlessPool;\n\t'neon-http': NeonQueryFunction<boolean, boolean>;\n\t'vercel-postgres':\n\t\t& VercelPool\n\t\t& (<O extends QueryResultRow>(\n\t\t\tstrings: TemplateStringsArray,\n\t\t\t...values: VercelPrimitive[]\n\t\t) => Promise<QueryResult<O>>);\n\t'aws-data-api-pg': RDSDataClient;\n\tplanetscale: PlanetscaleClient;\n\tmysql2: Mysql2Pool;\n\t'tidb-serverless': TiDBConnection;\n\tlibsql: LibsqlClient;\n\td1: D1Database;\n\t'bun:sqlite': BunDatabase;\n\t'better-sqlite3': BetterSQLite3Database;\n};\n\ntype InitializerParams = {\n\t'node-postgres': {\n\t\tconnection: NodePGPoolConfig;\n\t};\n\t'postgres-js': {\n\t\tconnection: string | PostgresJSOptions<Record<string, PostgresJSPostgresType>>;\n\t};\n\t'neon-serverless': {\n\t\tconnection: NeonServerlessConfig;\n\t};\n\t'neon-http': {\n\t\tconnection: MonodriverNeonHttpConfig;\n\t};\n\t'vercel-postgres': {\n\t\tconnection: VercelPool;\n\t};\n\t'aws-data-api-pg': {\n\t\tconnection?: RDSConfig;\n\t};\n\tplanetscale: {\n\t\tconnection: PlanetscaleConfig;\n\t};\n\tmysql2: {\n\t\tconnection: Mysql2Config | string;\n\t};\n\t'tidb-serverless': {\n\t\tconnection: TiDBServerlessConfig;\n\t};\n\tlibsql: {\n\t\tconnection: LibsqlConfig;\n\t};\n\td1: {\n\t\tconnection: D1Database;\n\t};\n\t'bun:sqlite': {\n\t\tconnection?: BunSqliteDatabaseConfig;\n\t};\n\t'better-sqlite3': {\n\t\tconnection?: BetterSQLite3DatabaseConfig;\n\t};\n};\n\ntype DetermineClient<\n\tTClient extends DatabaseClient,\n\tTSchema extends Record<string, unknown>,\n> =\n\t& ClientDrizzleInstanceMap<\n\t\tTSchema\n\t>[TClient]\n\t& {\n\t\t$client: ClientInstanceMap[TClient];\n\t};\n\nconst importError = (libName: string) => {\n\tthrow new Error(\n\t\t`Please install '${libName}' for Drizzle ORM to connect to database`,\n\t);\n};\n\nfunction assertUnreachable(_: never | undefined): never {\n\tthrow new Error(\"Didn't expect to get here\");\n}\n\nexport async function drizzle<\n\tTClient extends DatabaseClient,\n\tTSchema extends Record<string, unknown> = Record<string, never>,\n>(\n\tclient: TClient,\n\tparams:\n\t\t& InitializerParams[TClient]\n\t\t& (TClient extends 'mysql2' ? MySql2DrizzleConfig<TSchema>\n\t\t\t: TClient extends 'aws-data-api-pg' ? DrizzleAwsDataApiPgConfig<TSchema>\n\t\t\t: TClient extends 'neon-serverless' ? DrizzleConfig<TSchema> & {\n\t\t\t\t\tws?: any;\n\t\t\t\t}\n\t\t\t: DrizzleConfig<TSchema>),\n): Promise<DetermineClient<TClient, TSchema>> {\n\tconst { connection, ws, ...drizzleConfig } = params as typeof params & {\n\t\tws?: any;\n\t};\n\n\tswitch (client) {\n\t\tcase 'node-postgres': {\n\t\t\tconst { Pool } = await import('pg').catch(() => importError('pg'));\n\t\t\tconst { drizzle } = await import('./node-postgres');\n\t\t\tconst instance = new Pool(connection as NodePGPoolConfig);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'aws-data-api-pg': {\n\t\t\tconst { RDSDataClient } = await import('@aws-sdk/client-rds-data').catch(() =>\n\t\t\t\timportError('@aws-sdk/client-rds-data')\n\t\t\t);\n\t\t\tconst { drizzle } = await import('./aws-data-api/pg');\n\t\t\tconst instance = new RDSDataClient(connection as RDSDataClientConfig);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig as any as DrizzleAwsDataApiPgConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'better-sqlite3': {\n\t\t\tconst { default: Client } = await import('better-sqlite3').catch(() => importError('better-sqlite3'));\n\t\t\tconst { drizzle } = await import('./better-sqlite3');\n\n\t\t\tif (typeof connection === 'object') {\n\t\t\t\tconst { filename, options } = connection as Exclude<BetterSQLite3DatabaseConfig, string | undefined>;\n\n\t\t\t\tconst instance = new Client(filename, options);\n\n\t\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\t\tdb.$client = instance;\n\n\t\t\t\treturn db;\n\t\t\t}\n\n\t\t\tconst instance = new Client(connection);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'bun:sqlite': {\n\t\t\tconst { Database: Client } = await import('bun:sqlite').catch(() => importError('bun:sqlite'));\n\t\t\tconst { drizzle } = await import('./bun-sqlite');\n\n\t\t\tif (typeof connection === 'object') {\n\t\t\t\tconst { filename, options } = connection as Exclude<BunSqliteDatabaseConfig, string | undefined>;\n\n\t\t\t\tconst instance = new Client(filename, options);\n\n\t\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\t\tdb.$client = instance;\n\n\t\t\t\treturn db;\n\t\t\t}\n\n\t\t\tconst instance = new Client(connection);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'd1': {\n\t\t\tconst { drizzle } = await import('./d1');\n\n\t\t\tconst db = drizzle(connection as D1Database, drizzleConfig) as any;\n\t\t\tdb.$client = connection;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'libsql': {\n\t\t\tconst { createClient } = await import('@libsql/client').catch(() => importError('@libsql/client'));\n\t\t\tconst { drizzle } = await import('./libsql');\n\t\t\tconst instance = createClient(connection as LibsqlConfig);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'mysql2': {\n\t\t\tconst { createPool } = await import('mysql2/promise').catch(() => importError('mysql2/promise'));\n\t\t\tconst instance = createPool(connection as Mysql2Config);\n\t\t\tconst { drizzle } = await import('./mysql2');\n\n\t\t\tconst db = drizzle(instance, drizzleConfig as MySql2DrizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'neon-http': {\n\t\t\tconst { neon } = await import('@neondatabase/serverless').catch(() => importError('@neondatabase/serverless'));\n\t\t\tconst { connectionString, options } = connection as MonodriverNeonHttpConfig;\n\t\t\tconst { drizzle } = await import('./neon-http');\n\t\t\tconst instance = neon(connectionString, options);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'neon-serverless': {\n\t\t\tconst { Pool, neonConfig } = await import('@neondatabase/serverless').catch(() =>\n\t\t\t\timportError('@neondatabase/serverless')\n\t\t\t);\n\t\t\tconst { drizzle } = await import('./neon-serverless');\n\t\t\tconst instance = new Pool(connection as NeonServerlessConfig);\n\n\t\t\tif (ws) {\n\t\t\t\tneonConfig.webSocketConstructor = ws;\n\t\t\t}\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'planetscale': {\n\t\t\tconst { Client } = await import('@planetscale/database').catch(() => importError('@planetscale/database'));\n\t\t\tconst { drizzle } = await import('./planetscale-serverless');\n\t\t\tconst instance = new Client(\n\t\t\t\tconnection as PlanetscaleConfig,\n\t\t\t);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'postgres-js': {\n\t\t\tconst { default: client } = await import('postgres').catch(() => importError('postgres'));\n\t\t\tconst { drizzle } = await import('./postgres-js');\n\t\t\tconst instance = client(connection as PostgresJSOptions<Record<string, PostgresJSPostgresType>>);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'tidb-serverless': {\n\t\t\tconst { connect } = await import('@tidbcloud/serverless').catch(() => importError('@tidbcloud/serverless'));\n\t\t\tconst { drizzle } = await import('./tidb-serverless');\n\t\t\tconst instance = connect(connection as TiDBServerlessConfig);\n\n\t\t\tconst db = drizzle(instance, drizzleConfig) as any;\n\t\t\tdb.$client = instance;\n\n\t\t\treturn db;\n\t\t}\n\t\tcase 'vercel-postgres': {\n\t\t\tconst { sql } = await import('@vercel/postgres').catch(() => importError('@vercel/postgres'));\n\t\t\tconst { drizzle } = await import('./vercel-postgres');\n\n\t\t\tconst db = drizzle(sql, drizzleConfig) as any;\n\t\t\tdb.$client = sql;\n\n\t\t\treturn db;\n\t\t}\n\t}\n\n\tassertUnreachable(client);\n}\n"],"mappings":"AAgMA,MAAM,cAAc,CAAC,YAAoB;AACxC,QAAM,IAAI;AAAA,IACT,mBAAmB,OAAO;AAAA,EAC3B;AACD;AAEA,SAAS,kBAAkB,GAA6B;AACvD,QAAM,IAAI,MAAM,2BAA2B;AAC5C;AAEA,eAAsB,QAIrB,QACA,QAQ6C;AAC7C,QAAM,EAAE,YAAY,IAAI,GAAG,cAAc,IAAI;AAI7C,UAAQ,QAAQ;AAAA,IACf,KAAK,iBAAiB;AACrB,YAAM,EAAE,KAAK,IAAI,MAAM,OAAO,IAAI,EAAE,MAAM,MAAM,YAAY,IAAI,CAAC;AACjE,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,iBAAiB;AAClD,YAAM,WAAW,IAAI,KAAK,UAA8B;AAExD,YAAM,KAAKA,SAAQ,UAAU,aAAa;AAC1C,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,IACA,KAAK,mBAAmB;AACvB,YAAM,EAAE,cAAc,IAAI,MAAM,OAAO,0BAA0B,EAAE;AAAA,QAAM,MACxE,YAAY,0BAA0B;AAAA,MACvC;AACA,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mBAAmB;AACpD,YAAM,WAAW,IAAI,cAAc,UAAiC;AAEpE,YAAM,KAAKA,SAAQ,UAAU,aAAiD;AAC9E,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,IACA,KAAK,kBAAkB;AACtB,YAAM,EAAE,SAAS,OAAO,IAAI,MAAM,OAAO,gBAAgB,EAAE,MAAM,MAAM,YAAY,gBAAgB,CAAC;AACpG,YAAM,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WAAW,IAAI;AAAA,QACpB;AAAA,MACD;AAEA,YAAM,KAAKA,SAAQ,UAAU,aAAa;AAC1C,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,IACA,KAAK,eAAe;AACnB,YAAM,EAAE,SAASG,QAAO,IAAI,MAAM,OAAO,UAAU,EAAE,MAAM,MAAM,YAAY,UAAU,CAAC;AACxF,YAAM,EAAE,SAAAH,SAAQ,IAAI,MAAM,OAAO,eAAe;AAChD,YAAM,WAAWG,QAAO,UAAuE;AAE/F,YAAM,KAAKH,SAAQ,UAAU,aAAa;AAC1C,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,IACA,KAAK,mBAAmB;AACvB,YAAM,EAAE,QAAQ,IAAI,MAAM,OAAO,uBAAuB,EAAE,MAAM,MAAM,YAAY,uBAAuB,CAAC;AAC1G,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mBAAmB;AACpD,YAAM,WAAW,QAAQ,UAAkC;AAE3D,YAAM,KAAKA,SAAQ,UAAU,aAAa;AAC1C,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,IACA,KAAK,mBAAmB;AACvB,YAAM,EAAE,IAAI,IAAI,MAAM,OAAO,kBAAkB,EAAE,MAAM,MAAM,YAAY,kBAAkB,CAAC;AAC5F,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mBAAmB;AAEpD,YAAM,KAAKA,SAAQ,KAAK,aAAa;AACrC,SAAG,UAAU;AAEb,aAAO;AAAA,IACR;AAAA,EACD;AAEA,oBAAkB,MAAM;AACzB;","names":["drizzle","instance","db","client"]}
|
package/monomigrator.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var monomigrator_exports = {};
|
|
30
|
+
__export(monomigrator_exports, {
|
|
31
|
+
migrate: () => migrate
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(monomigrator_exports);
|
|
34
|
+
var import_entity = require("./entity.cjs");
|
|
35
|
+
async function migrate(db, config) {
|
|
36
|
+
switch (db.constructor[import_entity.entityKind]) {
|
|
37
|
+
case "AwsDataApiPgDatabase": {
|
|
38
|
+
const { migrate: migrate2 } = await import("./aws-data-api/pg/migrator");
|
|
39
|
+
return migrate2(db, config);
|
|
40
|
+
}
|
|
41
|
+
case "BetterSQLite3Database": {
|
|
42
|
+
const { migrate: migrate2 } = await import("./better-sqlite3/migrator");
|
|
43
|
+
return migrate2(db, config);
|
|
44
|
+
}
|
|
45
|
+
case "BunSQLiteDatabase": {
|
|
46
|
+
const { migrate: migrate2 } = await import("./bun-sqlite/migrator");
|
|
47
|
+
return migrate2(db, config);
|
|
48
|
+
}
|
|
49
|
+
case "D1Database": {
|
|
50
|
+
const { migrate: migrate2 } = await import("./d1/migrator");
|
|
51
|
+
return migrate2(db, config);
|
|
52
|
+
}
|
|
53
|
+
case "LibSQLDatabase": {
|
|
54
|
+
const { migrate: migrate2 } = await import("./libsql/migrator");
|
|
55
|
+
return migrate2(db, config);
|
|
56
|
+
}
|
|
57
|
+
case "MySql2Database": {
|
|
58
|
+
const { migrate: migrate2 } = await import("./mysql2/migrator");
|
|
59
|
+
return migrate2(db, config);
|
|
60
|
+
}
|
|
61
|
+
case "NeonHttpDatabase": {
|
|
62
|
+
const { migrate: migrate2 } = await import("./neon-http/migrator");
|
|
63
|
+
return migrate2(db, config);
|
|
64
|
+
}
|
|
65
|
+
case "NeonServerlessDatabase": {
|
|
66
|
+
const { migrate: migrate2 } = await import("./neon-serverless/migrator");
|
|
67
|
+
return migrate2(db, config);
|
|
68
|
+
}
|
|
69
|
+
case "NodePgDatabase": {
|
|
70
|
+
const { migrate: migrate2 } = await import("./node-postgres/migrator");
|
|
71
|
+
return migrate2(db, config);
|
|
72
|
+
}
|
|
73
|
+
case "PlanetScaleDatabase": {
|
|
74
|
+
const { migrate: migrate2 } = await import("./planetscale-serverless/migrator");
|
|
75
|
+
return migrate2(db, config);
|
|
76
|
+
}
|
|
77
|
+
case "PostgresJsDatabase": {
|
|
78
|
+
const { migrate: migrate2 } = await import("./postgres-js/migrator");
|
|
79
|
+
return migrate2(db, config);
|
|
80
|
+
}
|
|
81
|
+
case "TiDBServerlessDatabase": {
|
|
82
|
+
const { migrate: migrate2 } = await import("./tidb-serverless/migrator");
|
|
83
|
+
return migrate2(db, config);
|
|
84
|
+
}
|
|
85
|
+
case "VercelPgDatabase": {
|
|
86
|
+
const { migrate: migrate2 } = await import("./vercel-postgres/migrator");
|
|
87
|
+
return migrate2(db, config);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
migrate
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=monomigrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monomigrator.ts"],"sourcesContent":["/* eslint-disable import/extensions */\nimport type { AwsDataApiPgDatabase } from './aws-data-api/pg/index.ts';\nimport type { BetterSQLite3Database } from './better-sqlite3/index.ts';\nimport type { BunSQLiteDatabase } from './bun-sqlite/index.ts';\nimport type { DrizzleD1Database } from './d1/index.ts';\nimport { entityKind } from './entity.ts';\nimport type { LibSQLDatabase } from './libsql/index.ts';\nimport type { MigrationConfig } from './migrator.ts';\nimport type { MySql2Database } from './mysql2/index.ts';\nimport type { NeonHttpDatabase } from './neon-http/index.ts';\nimport type { NeonDatabase } from './neon-serverless/index.ts';\nimport type { NodePgDatabase } from './node-postgres/index.ts';\nimport type { PlanetScaleDatabase } from './planetscale-serverless/index.ts';\nimport type { PostgresJsDatabase } from './postgres-js/index.ts';\nimport type { TiDBServerlessDatabase } from './tidb-serverless/index.ts';\nimport type { VercelPgDatabase } from './vercel-postgres/index.ts';\n\nexport async function migrate(\n\tdb:\n\t\t| AwsDataApiPgDatabase<any>\n\t\t| BetterSQLite3Database<any>\n\t\t| BunSQLiteDatabase<any>\n\t\t| DrizzleD1Database<any>\n\t\t| LibSQLDatabase<any>\n\t\t| MySql2Database<any>\n\t\t| NeonHttpDatabase<any>\n\t\t| NeonDatabase<any>\n\t\t| NodePgDatabase<any>\n\t\t| PlanetScaleDatabase<any>\n\t\t| PostgresJsDatabase<any>\n\t\t| VercelPgDatabase<any>\n\t\t| TiDBServerlessDatabase<any>,\n\tconfig:\n\t\t| string\n\t\t| MigrationConfig,\n) {\n\tswitch ((<any> db).constructor[entityKind]) {\n\t\tcase 'AwsDataApiPgDatabase': {\n\t\t\tconst { migrate } = await import('./aws-data-api/pg/migrator');\n\n\t\t\treturn migrate(db as AwsDataApiPgDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'BetterSQLite3Database': {\n\t\t\tconst { migrate } = await import('./better-sqlite3/migrator');\n\n\t\t\treturn migrate(db as BetterSQLite3Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'BunSQLiteDatabase': {\n\t\t\tconst { migrate } = await import('./bun-sqlite/migrator');\n\n\t\t\treturn migrate(db as BunSQLiteDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'D1Database': {\n\t\t\tconst { migrate } = await import('./d1/migrator');\n\n\t\t\treturn migrate(db as DrizzleD1Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'LibSQLDatabase': {\n\t\t\tconst { migrate } = await import('./libsql/migrator');\n\n\t\t\treturn migrate(db as LibSQLDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'MySql2Database': {\n\t\t\tconst { migrate } = await import('./mysql2/migrator');\n\n\t\t\treturn migrate(db as MySql2Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NeonHttpDatabase': {\n\t\t\tconst { migrate } = await import('./neon-http/migrator');\n\n\t\t\treturn migrate(db as NeonHttpDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NeonServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./neon-serverless/migrator');\n\n\t\t\treturn migrate(db as NeonDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NodePgDatabase': {\n\t\t\tconst { migrate } = await import('./node-postgres/migrator');\n\n\t\t\treturn migrate(db as NodePgDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'PlanetScaleDatabase': {\n\t\t\tconst { migrate } = await import('./planetscale-serverless/migrator');\n\n\t\t\treturn migrate(db as PlanetScaleDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'PostgresJsDatabase': {\n\t\t\tconst { migrate } = await import('./postgres-js/migrator');\n\n\t\t\treturn migrate(db as PostgresJsDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'TiDBServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./tidb-serverless/migrator');\n\n\t\t\treturn migrate(db as TiDBServerlessDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'VercelPgDatabase': {\n\t\t\tconst { migrate } = await import('./vercel-postgres/migrator');\n\n\t\t\treturn migrate(db as VercelPgDatabase, config as string | MigrationConfig);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAA2B;AAY3B,eAAsB,QACrB,IAcA,QAGC;AACD,UAAe,GAAI,YAAY,wBAAU,GAAG;AAAA,IAC3C,KAAK,wBAAwB;AAC5B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAA4B,MAAkC;AAAA,IAC9E;AAAA,IACA,KAAK,yBAAyB;AAC7B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,2BAA2B;AAE5D,aAAOA,SAAQ,IAA6B,MAAkC;AAAA,IAC/E;AAAA,IACA,KAAK,qBAAqB;AACzB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,uBAAuB;AAExD,aAAOA,SAAQ,IAAyB,MAAkC;AAAA,IAC3E;AAAA,IACA,KAAK,cAAc;AAClB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,eAAe;AAEhD,aAAOA,SAAQ,IAAyB,MAAkC;AAAA,IAC3E;AAAA,IACA,KAAK,kBAAkB;AACtB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mBAAmB;AAEpD,aAAOA,SAAQ,IAAsB,MAAkC;AAAA,IAC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";
|
|
3
|
+
import type { BunSQLiteDatabase } from "./bun-sqlite/index.cjs";
|
|
4
|
+
import type { DrizzleD1Database } from "./d1/index.cjs";
|
|
5
|
+
import type { LibSQLDatabase } from "./libsql/index.cjs";
|
|
6
|
+
import type { MigrationConfig } from "./migrator.cjs";
|
|
7
|
+
import type { MySql2Database } from "./mysql2/index.cjs";
|
|
8
|
+
import type { NeonHttpDatabase } from "./neon-http/index.cjs";
|
|
9
|
+
import type { NeonDatabase } from "./neon-serverless/index.cjs";
|
|
10
|
+
import type { NodePgDatabase } from "./node-postgres/index.cjs";
|
|
11
|
+
import type { PlanetScaleDatabase } from "./planetscale-serverless/index.cjs";
|
|
12
|
+
import type { PostgresJsDatabase } from "./postgres-js/index.cjs";
|
|
13
|
+
import type { TiDBServerlessDatabase } from "./tidb-serverless/index.cjs";
|
|
14
|
+
import type { VercelPgDatabase } from "./vercel-postgres/index.cjs";
|
|
15
|
+
export declare function migrate(db: AwsDataApiPgDatabase<any> | BetterSQLite3Database<any> | BunSQLiteDatabase<any> | DrizzleD1Database<any> | LibSQLDatabase<any> | MySql2Database<any> | NeonHttpDatabase<any> | NeonDatabase<any> | NodePgDatabase<any> | PlanetScaleDatabase<any> | PostgresJsDatabase<any> | VercelPgDatabase<any> | TiDBServerlessDatabase<any>, config: string | MigrationConfig): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwsDataApiPgDatabase } from "./aws-data-api/pg/index.js";
|
|
2
|
+
import type { BetterSQLite3Database } from "./better-sqlite3/index.js";
|
|
3
|
+
import type { BunSQLiteDatabase } from "./bun-sqlite/index.js";
|
|
4
|
+
import type { DrizzleD1Database } from "./d1/index.js";
|
|
5
|
+
import type { LibSQLDatabase } from "./libsql/index.js";
|
|
6
|
+
import type { MigrationConfig } from "./migrator.js";
|
|
7
|
+
import type { MySql2Database } from "./mysql2/index.js";
|
|
8
|
+
import type { NeonHttpDatabase } from "./neon-http/index.js";
|
|
9
|
+
import type { NeonDatabase } from "./neon-serverless/index.js";
|
|
10
|
+
import type { NodePgDatabase } from "./node-postgres/index.js";
|
|
11
|
+
import type { PlanetScaleDatabase } from "./planetscale-serverless/index.js";
|
|
12
|
+
import type { PostgresJsDatabase } from "./postgres-js/index.js";
|
|
13
|
+
import type { TiDBServerlessDatabase } from "./tidb-serverless/index.js";
|
|
14
|
+
import type { VercelPgDatabase } from "./vercel-postgres/index.js";
|
|
15
|
+
export declare function migrate(db: AwsDataApiPgDatabase<any> | BetterSQLite3Database<any> | BunSQLiteDatabase<any> | DrizzleD1Database<any> | LibSQLDatabase<any> | MySql2Database<any> | NeonHttpDatabase<any> | NeonDatabase<any> | NodePgDatabase<any> | PlanetScaleDatabase<any> | PostgresJsDatabase<any> | VercelPgDatabase<any> | TiDBServerlessDatabase<any>, config: string | MigrationConfig): Promise<void>;
|
package/monomigrator.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { entityKind } from "./entity.js";
|
|
2
|
+
async function migrate(db, config) {
|
|
3
|
+
switch (db.constructor[entityKind]) {
|
|
4
|
+
case "AwsDataApiPgDatabase": {
|
|
5
|
+
const { migrate: migrate2 } = await import("./aws-data-api/pg/migrator");
|
|
6
|
+
return migrate2(db, config);
|
|
7
|
+
}
|
|
8
|
+
case "BetterSQLite3Database": {
|
|
9
|
+
const { migrate: migrate2 } = await import("./better-sqlite3/migrator");
|
|
10
|
+
return migrate2(db, config);
|
|
11
|
+
}
|
|
12
|
+
case "BunSQLiteDatabase": {
|
|
13
|
+
const { migrate: migrate2 } = await import("./bun-sqlite/migrator");
|
|
14
|
+
return migrate2(db, config);
|
|
15
|
+
}
|
|
16
|
+
case "D1Database": {
|
|
17
|
+
const { migrate: migrate2 } = await import("./d1/migrator");
|
|
18
|
+
return migrate2(db, config);
|
|
19
|
+
}
|
|
20
|
+
case "LibSQLDatabase": {
|
|
21
|
+
const { migrate: migrate2 } = await import("./libsql/migrator");
|
|
22
|
+
return migrate2(db, config);
|
|
23
|
+
}
|
|
24
|
+
case "MySql2Database": {
|
|
25
|
+
const { migrate: migrate2 } = await import("./mysql2/migrator");
|
|
26
|
+
return migrate2(db, config);
|
|
27
|
+
}
|
|
28
|
+
case "NeonHttpDatabase": {
|
|
29
|
+
const { migrate: migrate2 } = await import("./neon-http/migrator");
|
|
30
|
+
return migrate2(db, config);
|
|
31
|
+
}
|
|
32
|
+
case "NeonServerlessDatabase": {
|
|
33
|
+
const { migrate: migrate2 } = await import("./neon-serverless/migrator");
|
|
34
|
+
return migrate2(db, config);
|
|
35
|
+
}
|
|
36
|
+
case "NodePgDatabase": {
|
|
37
|
+
const { migrate: migrate2 } = await import("./node-postgres/migrator");
|
|
38
|
+
return migrate2(db, config);
|
|
39
|
+
}
|
|
40
|
+
case "PlanetScaleDatabase": {
|
|
41
|
+
const { migrate: migrate2 } = await import("./planetscale-serverless/migrator");
|
|
42
|
+
return migrate2(db, config);
|
|
43
|
+
}
|
|
44
|
+
case "PostgresJsDatabase": {
|
|
45
|
+
const { migrate: migrate2 } = await import("./postgres-js/migrator");
|
|
46
|
+
return migrate2(db, config);
|
|
47
|
+
}
|
|
48
|
+
case "TiDBServerlessDatabase": {
|
|
49
|
+
const { migrate: migrate2 } = await import("./tidb-serverless/migrator");
|
|
50
|
+
return migrate2(db, config);
|
|
51
|
+
}
|
|
52
|
+
case "VercelPgDatabase": {
|
|
53
|
+
const { migrate: migrate2 } = await import("./vercel-postgres/migrator");
|
|
54
|
+
return migrate2(db, config);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
migrate
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=monomigrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/monomigrator.ts"],"sourcesContent":["/* eslint-disable import/extensions */\nimport type { AwsDataApiPgDatabase } from './aws-data-api/pg/index.ts';\nimport type { BetterSQLite3Database } from './better-sqlite3/index.ts';\nimport type { BunSQLiteDatabase } from './bun-sqlite/index.ts';\nimport type { DrizzleD1Database } from './d1/index.ts';\nimport { entityKind } from './entity.ts';\nimport type { LibSQLDatabase } from './libsql/index.ts';\nimport type { MigrationConfig } from './migrator.ts';\nimport type { MySql2Database } from './mysql2/index.ts';\nimport type { NeonHttpDatabase } from './neon-http/index.ts';\nimport type { NeonDatabase } from './neon-serverless/index.ts';\nimport type { NodePgDatabase } from './node-postgres/index.ts';\nimport type { PlanetScaleDatabase } from './planetscale-serverless/index.ts';\nimport type { PostgresJsDatabase } from './postgres-js/index.ts';\nimport type { TiDBServerlessDatabase } from './tidb-serverless/index.ts';\nimport type { VercelPgDatabase } from './vercel-postgres/index.ts';\n\nexport async function migrate(\n\tdb:\n\t\t| AwsDataApiPgDatabase<any>\n\t\t| BetterSQLite3Database<any>\n\t\t| BunSQLiteDatabase<any>\n\t\t| DrizzleD1Database<any>\n\t\t| LibSQLDatabase<any>\n\t\t| MySql2Database<any>\n\t\t| NeonHttpDatabase<any>\n\t\t| NeonDatabase<any>\n\t\t| NodePgDatabase<any>\n\t\t| PlanetScaleDatabase<any>\n\t\t| PostgresJsDatabase<any>\n\t\t| VercelPgDatabase<any>\n\t\t| TiDBServerlessDatabase<any>,\n\tconfig:\n\t\t| string\n\t\t| MigrationConfig,\n) {\n\tswitch ((<any> db).constructor[entityKind]) {\n\t\tcase 'AwsDataApiPgDatabase': {\n\t\t\tconst { migrate } = await import('./aws-data-api/pg/migrator');\n\n\t\t\treturn migrate(db as AwsDataApiPgDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'BetterSQLite3Database': {\n\t\t\tconst { migrate } = await import('./better-sqlite3/migrator');\n\n\t\t\treturn migrate(db as BetterSQLite3Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'BunSQLiteDatabase': {\n\t\t\tconst { migrate } = await import('./bun-sqlite/migrator');\n\n\t\t\treturn migrate(db as BunSQLiteDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'D1Database': {\n\t\t\tconst { migrate } = await import('./d1/migrator');\n\n\t\t\treturn migrate(db as DrizzleD1Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'LibSQLDatabase': {\n\t\t\tconst { migrate } = await import('./libsql/migrator');\n\n\t\t\treturn migrate(db as LibSQLDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'MySql2Database': {\n\t\t\tconst { migrate } = await import('./mysql2/migrator');\n\n\t\t\treturn migrate(db as MySql2Database, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NeonHttpDatabase': {\n\t\t\tconst { migrate } = await import('./neon-http/migrator');\n\n\t\t\treturn migrate(db as NeonHttpDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NeonServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./neon-serverless/migrator');\n\n\t\t\treturn migrate(db as NeonDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'NodePgDatabase': {\n\t\t\tconst { migrate } = await import('./node-postgres/migrator');\n\n\t\t\treturn migrate(db as NodePgDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'PlanetScaleDatabase': {\n\t\t\tconst { migrate } = await import('./planetscale-serverless/migrator');\n\n\t\t\treturn migrate(db as PlanetScaleDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'PostgresJsDatabase': {\n\t\t\tconst { migrate } = await import('./postgres-js/migrator');\n\n\t\t\treturn migrate(db as PostgresJsDatabase, config as string | MigrationConfig);\n\t\t}\n\t\tcase 'TiDBServerlessDatabase': {\n\t\t\tconst { migrate } = await import('./tidb-serverless/migrator');\n\n\t\t\treturn migrate(db as TiDBServerlessDatabase, config as MigrationConfig);\n\t\t}\n\t\tcase 'VercelPgDatabase': {\n\t\t\tconst { migrate } = await import('./vercel-postgres/migrator');\n\n\t\t\treturn migrate(db as VercelPgDatabase, config as string | MigrationConfig);\n\t\t}\n\t}\n}\n"],"mappings":"AAKA,SAAS,kBAAkB;AAY3B,eAAsB,QACrB,IAcA,QAGC;AACD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A,IACA,KAAK,uBAAuB;AAC3B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,mCAAmC;AAEpE,aAAOA,SAAQ,IAA2B,MAAkC;AAAA,IAC7E;AAAA,IACA,KAAK,sBAAsB;AAC1B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,wBAAwB;AAEzD,aAAOA,SAAQ,IAA0B,MAAkC;AAAA,IAC5E;AAAA,IACA,KAAK,0BAA0B;AAC9B,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAA8B,MAAyB;AAAA,IACvE;AAAA,IACA,KAAK,oBAAoB;AACxB,YAAM,EAAE,SAAAA,SAAQ,IAAI,MAAM,OAAO,4BAA4B;AAE7D,aAAOA,SAAQ,IAAwB,MAAkC;AAAA,IAC1E;AAAA,EACD;AACD;","names":["migrate"]}
|
package/mysql-core/db.cjs
CHANGED
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(db_exports);
|
|
|
25
25
|
var import_entity = require("../entity.cjs");
|
|
26
26
|
var import_selection_proxy = require("../selection-proxy.cjs");
|
|
27
27
|
var import_subquery = require("../subquery.cjs");
|
|
28
|
+
var import_count = require("./query-builders/count.cjs");
|
|
28
29
|
var import_query_builders = require("./query-builders/index.cjs");
|
|
29
30
|
var import_query = require("./query-builders/query.cjs");
|
|
30
31
|
class MySqlDatabase {
|
|
@@ -104,6 +105,9 @@ class MySqlDatabase {
|
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
}
|
|
108
|
+
$count(source, filters) {
|
|
109
|
+
return new import_count.MySqlCountBuilder({ source, filters, session: this.session });
|
|
110
|
+
}
|
|
107
111
|
/**
|
|
108
112
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
109
113
|
*
|
package/mysql-core/db.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAG3B,6BAAsC;AAEtC,sBAA6B;AAG7B,4BAMO;AACP,mBAAuC;AAchC,MAAM,cAKX;AAA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,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA2B;AAG3B,6BAAsC;AAEtC,sBAA6B;AAG7B,mBAAkC;AAClC,4BAMO;AACP,mBAAuC;AAehC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ,CAAC;AACd,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,QAAC,KAAK,MAAuF,SAAS,IACrG,IAAI;AAAA,UACH,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA,UACP,KAAK,EAAE;AAAA,UACP,OAAQ,WAAW,SAAS;AAAA,UAC5B;AAAA,UACA;AAAA,UACA;AAAA,UACA,KAAK;AAAA,QACN;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAjDA,QAAiB,wBAAU,IAAY;AAAA,EAQvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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ACa;AACb,WAAO,KAAK,QAAQ,YAAY,aAAa,MAAM;AAAA,EACpD;AACD;AAIO,MAAM,eAAe,CAY3B,SACA,UACA,aAAmC,MAAM,SAAS,KAAK,MAAM,KAAK,OAAO,IAAI,SAAS,MAAM,CAAC,MACnE;AAC1B,QAAM,SAAsB,IAAI,SAAa,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AAChF,QAAM,iBAAsC,IAAI,SAAa,WAAW,QAAQ,EAAE,eAAe,GAAG,IAAI;AACxG,QAAM,QAAmB,IAAI,SAAa,WAAW,QAAQ,EAAE,KAAK,GAAG,IAAI;AAE3E,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,UAAwB,IAAI,SAAgB,QAAQ,QAAQ,GAAG,IAAI;AACzE,QAAM,cAAgC,IAAI,SAAqB,QAAQ,YAAY,GAAG,IAAI;AAE1F,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
package/mysql-core/db.d.cts
CHANGED
|
@@ -2,16 +2,18 @@ import type { ResultSetHeader } from 'mysql2/promise';
|
|
|
2
2
|
import { entityKind } from "../entity.cjs";
|
|
3
3
|
import type { TypedQueryBuilder } from "../query-builders/query-builder.cjs";
|
|
4
4
|
import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.cjs";
|
|
5
|
-
import type { ColumnsSelection, SQLWrapper } from "../sql/sql.cjs";
|
|
5
|
+
import type { ColumnsSelection, SQL, SQLWrapper } from "../sql/sql.cjs";
|
|
6
6
|
import { WithSubquery } from "../subquery.cjs";
|
|
7
7
|
import type { DrizzleTypeError } from "../utils.cjs";
|
|
8
8
|
import type { MySqlDialect } from "./dialect.cjs";
|
|
9
|
+
import { MySqlCountBuilder } from "./query-builders/count.cjs";
|
|
9
10
|
import { MySqlDeleteBase, MySqlInsertBuilder, MySqlSelectBuilder, MySqlUpdateBuilder, QueryBuilder } from "./query-builders/index.cjs";
|
|
10
11
|
import { RelationalQueryBuilder } from "./query-builders/query.cjs";
|
|
11
12
|
import type { SelectedFields } from "./query-builders/select.types.cjs";
|
|
12
13
|
import type { Mode, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, MySqlTransaction, MySqlTransactionConfig, PreparedQueryHKTBase } from "./session.cjs";
|
|
13
14
|
import type { WithSubqueryWithSelection } from "./subquery.cjs";
|
|
14
15
|
import type { MySqlTable } from "./table.cjs";
|
|
16
|
+
import type { MySqlViewBase } from "./view-base.cjs";
|
|
15
17
|
export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
16
18
|
protected readonly mode: Mode;
|
|
17
19
|
static readonly [entityKind]: string;
|
|
@@ -63,6 +65,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
63
65
|
$with<TAlias extends string>(alias: TAlias): {
|
|
64
66
|
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
65
67
|
};
|
|
68
|
+
$count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any>>;
|
|
66
69
|
/**
|
|
67
70
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
68
71
|
*
|
package/mysql-core/db.d.ts
CHANGED
|
@@ -2,16 +2,18 @@ import type { ResultSetHeader } from 'mysql2/promise';
|
|
|
2
2
|
import { entityKind } from "../entity.js";
|
|
3
3
|
import type { TypedQueryBuilder } from "../query-builders/query-builder.js";
|
|
4
4
|
import type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from "../relations.js";
|
|
5
|
-
import type { ColumnsSelection, SQLWrapper } from "../sql/sql.js";
|
|
5
|
+
import type { ColumnsSelection, SQL, SQLWrapper } from "../sql/sql.js";
|
|
6
6
|
import { WithSubquery } from "../subquery.js";
|
|
7
7
|
import type { DrizzleTypeError } from "../utils.js";
|
|
8
8
|
import type { MySqlDialect } from "./dialect.js";
|
|
9
|
+
import { MySqlCountBuilder } from "./query-builders/count.js";
|
|
9
10
|
import { MySqlDeleteBase, MySqlInsertBuilder, MySqlSelectBuilder, MySqlUpdateBuilder, QueryBuilder } from "./query-builders/index.js";
|
|
10
11
|
import { RelationalQueryBuilder } from "./query-builders/query.js";
|
|
11
12
|
import type { SelectedFields } from "./query-builders/select.types.js";
|
|
12
13
|
import type { Mode, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, MySqlTransaction, MySqlTransactionConfig, PreparedQueryHKTBase } from "./session.js";
|
|
13
14
|
import type { WithSubqueryWithSelection } from "./subquery.js";
|
|
14
15
|
import type { MySqlTable } from "./table.js";
|
|
16
|
+
import type { MySqlViewBase } from "./view-base.js";
|
|
15
17
|
export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPreparedQueryHKT extends PreparedQueryHKTBase, TFullSchema extends Record<string, unknown> = {}, TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>> {
|
|
16
18
|
protected readonly mode: Mode;
|
|
17
19
|
static readonly [entityKind]: string;
|
|
@@ -63,6 +65,7 @@ export declare class MySqlDatabase<TQueryResult extends MySqlQueryResultHKT, TPr
|
|
|
63
65
|
$with<TAlias extends string>(alias: TAlias): {
|
|
64
66
|
as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>)): WithSubqueryWithSelection<TSelection, TAlias>;
|
|
65
67
|
};
|
|
68
|
+
$count(source: MySqlTable | MySqlViewBase | SQL | SQLWrapper, filters?: SQL<unknown>): MySqlCountBuilder<MySqlSession<any, any, any, any>>;
|
|
66
69
|
/**
|
|
67
70
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
68
71
|
*
|
package/mysql-core/db.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { entityKind } from "../entity.js";
|
|
2
2
|
import { SelectionProxyHandler } from "../selection-proxy.js";
|
|
3
3
|
import { WithSubquery } from "../subquery.js";
|
|
4
|
+
import { MySqlCountBuilder } from "./query-builders/count.js";
|
|
4
5
|
import {
|
|
5
6
|
MySqlDeleteBase,
|
|
6
7
|
MySqlInsertBuilder,
|
|
@@ -86,6 +87,9 @@ class MySqlDatabase {
|
|
|
86
87
|
}
|
|
87
88
|
};
|
|
88
89
|
}
|
|
90
|
+
$count(source, filters) {
|
|
91
|
+
return new MySqlCountBuilder({ source, filters, session: this.session });
|
|
92
|
+
}
|
|
89
93
|
/**
|
|
90
94
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
91
95
|
*
|
package/mysql-core/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AAEtC,SAAS,oBAAoB;AAG7B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AAchC,MAAM,cAKX;AAAA,EAeD,YAEU,SAEA,SACT,QACmB,MAClB;AALQ;AAEA;AAEU;AAEnB,SAAK,IAAI,SACN;AAAA,MACD,QAAQ,OAAO;AAAA,MACf,YAAY,OAAO;AAAA,MACnB,eAAe,OAAO;AAAA,IACvB,IACE;AAAA,MACD,QAAQ;AAAA,MACR,YAAY,CAAC;AAAA,MACb,eAAe,CAAC;AAAA,IACjB;AACD,SAAK,QAAQ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
|
|
1
|
+
{"version":3,"sources":["../../src/mysql-core/db.ts"],"sourcesContent":["import type { ResultSetHeader } from 'mysql2/promise';\nimport { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport type { MySqlDialect } from './dialect.ts';\nimport { MySqlCountBuilder } from './query-builders/count.ts';\nimport {\n\tMySqlDeleteBase,\n\tMySqlInsertBuilder,\n\tMySqlSelectBuilder,\n\tMySqlUpdateBuilder,\n\tQueryBuilder,\n} from './query-builders/index.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type {\n\tMode,\n\tMySqlQueryResultHKT,\n\tMySqlQueryResultKind,\n\tMySqlSession,\n\tMySqlTransaction,\n\tMySqlTransactionConfig,\n\tPreparedQueryHKTBase,\n} from './session.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\nimport type { MySqlTable } from './table.ts';\nimport type { MySqlViewBase } from './view-base.ts';\n\nexport class MySqlDatabase<\n\tTQueryResult extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown> = {},\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'MySqlDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly fullSchema: TFullSchema;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TPreparedQueryHKT, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\t/** @internal */\n\t\treadonly dialect: MySqlDialect,\n\t\t/** @internal */\n\t\treadonly session: MySqlSession<any, any, any, any>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t\tprotected readonly mode: Mode,\n\t) {\n\t\tthis._ = schema\n\t\t\t? {\n\t\t\t\tschema: schema.schema,\n\t\t\t\tfullSchema: schema.fullSchema as TFullSchema,\n\t\t\t\ttableNamesMap: schema.tableNamesMap,\n\t\t\t}\n\t\t\t: {\n\t\t\t\tschema: undefined,\n\t\t\t\tfullSchema: {} as TFullSchema,\n\t\t\t\ttableNamesMap: {},\n\t\t\t};\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\t(this.query as MySqlDatabase<TQueryResult, TPreparedQueryHKT, Record<string, any>>['query'])[tableName] =\n\t\t\t\t\tnew RelationalQueryBuilder(\n\t\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\t\tthis._.schema,\n\t\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\t\tschema!.fullSchema[tableName] as MySqlTable,\n\t\t\t\t\t\tcolumns,\n\t\t\t\t\t\tdialect,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tthis.mode,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t$count(\n\t\tsource: MySqlTable | MySqlViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t) {\n\t\treturn new MySqlCountBuilder({ source, filters, session: this.session });\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction select(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\t\treturn new MySqlSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlUpdateBuilder(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends MySqlTable>(\n\t\t\ttable: TTable,\n\t\t): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\t\treturn new MySqlDeleteBase(table, self.session, self.dialect, queries);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselect<TSelection extends SelectedFields>(fields: TSelection): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselect(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): MySqlSelectBuilder<undefined, TPreparedQueryHKT>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): MySqlSelectBuilder<TSelection, TPreparedQueryHKT>;\n\tselectDistinct(fields?: SelectedFields): MySqlSelectBuilder<SelectedFields | undefined, TPreparedQueryHKT> {\n\t\treturn new MySqlSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * ```\n\t */\n\tupdate<TTable extends MySqlTable>(table: TTable): MySqlUpdateBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * ```\n\t */\n\tinsert<TTable extends MySqlTable>(table: TTable): MySqlInsertBuilder<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlInsertBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * ```\n\t */\n\tdelete<TTable extends MySqlTable>(table: TTable): MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT> {\n\t\treturn new MySqlDeleteBase(table, this.session, this.dialect);\n\t}\n\n\texecute<T extends { [column: string]: any } = ResultSetHeader>(\n\t\tquery: SQLWrapper,\n\t): Promise<MySqlQueryResultKind<TQueryResult, T>> {\n\t\treturn this.session.execute(query.getSQL());\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (\n\t\t\ttx: MySqlTransaction<TQueryResult, TPreparedQueryHKT, TFullSchema, TSchema>,\n\t\t\tconfig?: MySqlTransactionConfig,\n\t\t) => Promise<T>,\n\t\tconfig?: MySqlTransactionConfig,\n\t): Promise<T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type MySQLWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tHKT extends MySqlQueryResultHKT,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends MySqlDatabase<\n\t\tHKT,\n\t\tTPreparedQueryHKT,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): MySQLWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst execute: Q['execute'] = (...args: [any]) => primary.execute(...args);\n\tconst transaction: Q['transaction'] = (...args: [any, any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\texecute,\n\t\ttransaction,\n\t\t$primary: primary,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