drizzle-orm 0.33.0-cd1f68c → 0.33.0-d11d7bb

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.
Files changed (207) hide show
  1. package/aws-data-api/pg/driver.cjs +3 -1
  2. package/aws-data-api/pg/driver.cjs.map +1 -1
  3. package/aws-data-api/pg/driver.d.cts +3 -1
  4. package/aws-data-api/pg/driver.d.ts +3 -1
  5. package/aws-data-api/pg/driver.js +3 -1
  6. package/aws-data-api/pg/driver.js.map +1 -1
  7. package/aws-data-api/pg/migrator.cjs.map +1 -1
  8. package/aws-data-api/pg/migrator.d.cts +1 -1
  9. package/aws-data-api/pg/migrator.d.ts +1 -1
  10. package/aws-data-api/pg/migrator.js.map +1 -1
  11. package/better-sqlite3/driver.cjs +3 -1
  12. package/better-sqlite3/driver.cjs.map +1 -1
  13. package/better-sqlite3/driver.d.cts +3 -1
  14. package/better-sqlite3/driver.d.ts +3 -1
  15. package/better-sqlite3/driver.js +3 -1
  16. package/better-sqlite3/driver.js.map +1 -1
  17. package/better-sqlite3/migrator.cjs.map +1 -1
  18. package/better-sqlite3/migrator.d.cts +1 -1
  19. package/better-sqlite3/migrator.d.ts +1 -1
  20. package/better-sqlite3/migrator.js.map +1 -1
  21. package/bun-sqlite/driver.cjs +3 -1
  22. package/bun-sqlite/driver.cjs.map +1 -1
  23. package/bun-sqlite/driver.d.cts +3 -1
  24. package/bun-sqlite/driver.d.ts +3 -1
  25. package/bun-sqlite/driver.js +3 -1
  26. package/bun-sqlite/driver.js.map +1 -1
  27. package/bun-sqlite/migrator.cjs.map +1 -1
  28. package/bun-sqlite/migrator.d.cts +1 -1
  29. package/bun-sqlite/migrator.d.ts +1 -1
  30. package/bun-sqlite/migrator.js.map +1 -1
  31. package/d1/driver.cjs +3 -1
  32. package/d1/driver.cjs.map +1 -1
  33. package/d1/driver.d.cts +6 -2
  34. package/d1/driver.d.ts +6 -2
  35. package/d1/driver.js +3 -1
  36. package/d1/driver.js.map +1 -1
  37. package/d1/migrator.cjs +1 -1
  38. package/d1/migrator.cjs.map +1 -1
  39. package/d1/migrator.d.cts +1 -1
  40. package/d1/migrator.d.ts +1 -1
  41. package/d1/migrator.js +1 -1
  42. package/d1/migrator.js.map +1 -1
  43. package/expo-sqlite/driver.cjs +3 -1
  44. package/expo-sqlite/driver.cjs.map +1 -1
  45. package/expo-sqlite/driver.d.cts +3 -1
  46. package/expo-sqlite/driver.d.ts +3 -1
  47. package/expo-sqlite/driver.js +3 -1
  48. package/expo-sqlite/driver.js.map +1 -1
  49. package/libsql/driver.cjs +3 -1
  50. package/libsql/driver.cjs.map +1 -1
  51. package/libsql/driver.d.cts +3 -1
  52. package/libsql/driver.d.ts +3 -1
  53. package/libsql/driver.js +3 -1
  54. package/libsql/driver.js.map +1 -1
  55. package/libsql/migrator.cjs +1 -1
  56. package/libsql/migrator.cjs.map +1 -1
  57. package/libsql/migrator.d.cts +1 -1
  58. package/libsql/migrator.d.ts +1 -1
  59. package/libsql/migrator.js +1 -1
  60. package/libsql/migrator.js.map +1 -1
  61. package/migrator.cjs +1 -12
  62. package/migrator.cjs.map +1 -1
  63. package/migrator.d.cts +1 -1
  64. package/migrator.d.ts +1 -1
  65. package/migrator.js +1 -12
  66. package/migrator.js.map +1 -1
  67. package/monodriver.cjs +37 -35
  68. package/monodriver.cjs.map +1 -1
  69. package/monodriver.d.cts +71 -50
  70. package/monodriver.d.ts +71 -50
  71. package/monodriver.js +37 -35
  72. package/monodriver.js.map +1 -1
  73. package/monomigrator.cjs.map +1 -1
  74. package/monomigrator.d.cts +1 -1
  75. package/monomigrator.d.ts +1 -1
  76. package/monomigrator.js.map +1 -1
  77. package/mysql2/driver.cjs +5 -5
  78. package/mysql2/driver.cjs.map +1 -1
  79. package/mysql2/driver.d.cts +3 -1
  80. package/mysql2/driver.d.ts +3 -1
  81. package/mysql2/driver.js +5 -5
  82. package/mysql2/driver.js.map +1 -1
  83. package/mysql2/migrator.cjs +1 -4
  84. package/mysql2/migrator.cjs.map +1 -1
  85. package/mysql2/migrator.d.cts +1 -1
  86. package/mysql2/migrator.d.ts +1 -1
  87. package/mysql2/migrator.js +1 -4
  88. package/mysql2/migrator.js.map +1 -1
  89. package/neon-http/driver.cjs +3 -1
  90. package/neon-http/driver.cjs.map +1 -1
  91. package/neon-http/driver.d.cts +3 -1
  92. package/neon-http/driver.d.ts +3 -1
  93. package/neon-http/driver.js +3 -1
  94. package/neon-http/driver.js.map +1 -1
  95. package/neon-http/migrator.cjs +2 -2
  96. package/neon-http/migrator.cjs.map +1 -1
  97. package/neon-http/migrator.d.cts +1 -1
  98. package/neon-http/migrator.d.ts +1 -1
  99. package/neon-http/migrator.js +2 -2
  100. package/neon-http/migrator.js.map +1 -1
  101. package/neon-serverless/driver.cjs +3 -1
  102. package/neon-serverless/driver.cjs.map +1 -1
  103. package/neon-serverless/driver.d.cts +3 -1
  104. package/neon-serverless/driver.d.ts +3 -1
  105. package/neon-serverless/driver.js +3 -1
  106. package/neon-serverless/driver.js.map +1 -1
  107. package/neon-serverless/migrator.cjs.map +1 -1
  108. package/neon-serverless/migrator.d.cts +1 -1
  109. package/neon-serverless/migrator.d.ts +1 -1
  110. package/neon-serverless/migrator.js.map +1 -1
  111. package/node-postgres/driver.cjs +3 -1
  112. package/node-postgres/driver.cjs.map +1 -1
  113. package/node-postgres/driver.d.cts +3 -1
  114. package/node-postgres/driver.d.ts +3 -1
  115. package/node-postgres/driver.js +3 -1
  116. package/node-postgres/driver.js.map +1 -1
  117. package/node-postgres/migrator.cjs.map +1 -1
  118. package/node-postgres/migrator.d.cts +1 -1
  119. package/node-postgres/migrator.d.ts +1 -1
  120. package/node-postgres/migrator.js.map +1 -1
  121. package/op-sqlite/driver.cjs +3 -1
  122. package/op-sqlite/driver.cjs.map +1 -1
  123. package/op-sqlite/driver.d.cts +3 -1
  124. package/op-sqlite/driver.d.ts +3 -1
  125. package/op-sqlite/driver.js +3 -1
  126. package/op-sqlite/driver.js.map +1 -1
  127. package/package.json +50 -49
  128. package/pg-proxy/migrator.cjs.map +1 -1
  129. package/pg-proxy/migrator.d.cts +1 -1
  130. package/pg-proxy/migrator.d.ts +1 -1
  131. package/pg-proxy/migrator.js.map +1 -1
  132. package/pglite/driver.cjs +3 -1
  133. package/pglite/driver.cjs.map +1 -1
  134. package/pglite/driver.d.cts +3 -1
  135. package/pglite/driver.d.ts +3 -1
  136. package/pglite/driver.js +3 -1
  137. package/pglite/driver.js.map +1 -1
  138. package/pglite/migrator.cjs.map +1 -1
  139. package/pglite/migrator.d.cts +1 -1
  140. package/pglite/migrator.d.ts +1 -1
  141. package/pglite/migrator.js.map +1 -1
  142. package/planetscale-serverless/driver.cjs +3 -1
  143. package/planetscale-serverless/driver.cjs.map +1 -1
  144. package/planetscale-serverless/driver.d.cts +3 -1
  145. package/planetscale-serverless/driver.d.ts +3 -1
  146. package/planetscale-serverless/driver.js +3 -1
  147. package/planetscale-serverless/driver.js.map +1 -1
  148. package/planetscale-serverless/migrator.cjs +1 -4
  149. package/planetscale-serverless/migrator.cjs.map +1 -1
  150. package/planetscale-serverless/migrator.d.cts +1 -1
  151. package/planetscale-serverless/migrator.d.ts +1 -1
  152. package/planetscale-serverless/migrator.js +1 -4
  153. package/planetscale-serverless/migrator.js.map +1 -1
  154. package/postgres-js/driver.cjs +3 -1
  155. package/postgres-js/driver.cjs.map +1 -1
  156. package/postgres-js/driver.d.cts +3 -1
  157. package/postgres-js/driver.d.ts +3 -1
  158. package/postgres-js/driver.js +3 -1
  159. package/postgres-js/driver.js.map +1 -1
  160. package/postgres-js/migrator.cjs.map +1 -1
  161. package/postgres-js/migrator.d.cts +1 -1
  162. package/postgres-js/migrator.d.ts +1 -1
  163. package/postgres-js/migrator.js.map +1 -1
  164. package/sql-js/migrator.cjs.map +1 -1
  165. package/sql-js/migrator.d.cts +1 -1
  166. package/sql-js/migrator.d.ts +1 -1
  167. package/sql-js/migrator.js.map +1 -1
  168. package/sqlite-proxy/migrator.cjs.map +1 -1
  169. package/sqlite-proxy/migrator.d.cts +1 -1
  170. package/sqlite-proxy/migrator.d.ts +1 -1
  171. package/sqlite-proxy/migrator.js.map +1 -1
  172. package/tidb-serverless/driver.cjs +3 -1
  173. package/tidb-serverless/driver.cjs.map +1 -1
  174. package/tidb-serverless/driver.d.cts +3 -1
  175. package/tidb-serverless/driver.d.ts +3 -1
  176. package/tidb-serverless/driver.js +3 -1
  177. package/tidb-serverless/driver.js.map +1 -1
  178. package/utils.cjs.map +1 -1
  179. package/utils.d.cts +1 -0
  180. package/utils.d.ts +1 -0
  181. package/utils.js.map +1 -1
  182. package/vercel-postgres/driver.cjs +3 -1
  183. package/vercel-postgres/driver.cjs.map +1 -1
  184. package/vercel-postgres/driver.d.cts +3 -1
  185. package/vercel-postgres/driver.d.ts +3 -1
  186. package/vercel-postgres/driver.js +3 -1
  187. package/vercel-postgres/driver.js.map +1 -1
  188. package/vercel-postgres/migrator.cjs.map +1 -1
  189. package/vercel-postgres/migrator.d.cts +1 -1
  190. package/vercel-postgres/migrator.d.ts +1 -1
  191. package/vercel-postgres/migrator.js.map +1 -1
  192. package/version.cjs +1 -1
  193. package/version.d.cts +1 -1
  194. package/version.d.ts +1 -1
  195. package/version.js +1 -1
  196. package/xata-http/driver.cjs +3 -1
  197. package/xata-http/driver.cjs.map +1 -1
  198. package/xata-http/driver.d.cts +3 -1
  199. package/xata-http/driver.d.ts +3 -1
  200. package/xata-http/driver.js +3 -1
  201. package/xata-http/driver.js.map +1 -1
  202. package/xata-http/migrator.cjs +1 -1
  203. package/xata-http/migrator.cjs.map +1 -1
  204. package/xata-http/migrator.d.cts +1 -1
  205. package/xata-http/migrator.d.ts +1 -1
  206. package/xata-http/migrator.js +1 -1
  207. package/xata-http/migrator.js.map +1 -1
package/monodriver.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
- /// <reference types="node" />
3
1
  /// <reference types="bun-types" />
2
+ /// <reference types="node" />
4
3
  import type { RDSDataClient, RDSDataClientConfig as RDSConfig } from '@aws-sdk/client-rds-data';
5
4
  import type { Client as LibsqlClient, Config as LibsqlConfig } from '@libsql/client';
6
5
  import type { HTTPTransactionOptions as NeonHttpConfig, NeonQueryFunction, Pool as NeonServerlessPool, PoolConfig as NeonServerlessConfig, QueryResult, QueryResultRow } from '@neondatabase/serverless';
@@ -10,21 +9,23 @@ import type { VercelPool } from '@vercel/postgres';
10
9
  import type { Database as BetterSQLite3Database, Options as BetterSQLite3Options } from 'better-sqlite3';
11
10
  import type { Database as BunDatabase } from 'bun:sqlite';
12
11
  import type { Pool as Mysql2Pool, PoolOptions as Mysql2Config } from 'mysql2';
12
+ import type { Pool as NodePgPool, PoolConfig as NodePgPoolConfig } from 'pg';
13
13
  import type { Options as PostgresJSOptions, PostgresType as PostgresJSPostgresType, Sql as PostgresJsClient } from 'postgres';
14
14
  import type { AwsDataApiPgDatabase, DrizzleAwsDataApiPgConfig } from "./aws-data-api/pg/index.cjs";
15
15
  import type { BetterSQLite3Database as DrizzleBetterSQLite3Database } from "./better-sqlite3/index.cjs";
16
16
  import type { BunSQLiteDatabase } from "./bun-sqlite/index.cjs";
17
- import type { DrizzleD1Database } from "./d1/index.cjs";
17
+ import type { AnyD1Database, DrizzleD1Database } from "./d1/index.cjs";
18
18
  import type { LibSQLDatabase } from "./libsql/index.cjs";
19
19
  import type { MySql2Database, MySql2DrizzleConfig } from "./mysql2/index.cjs";
20
20
  import type { NeonHttpDatabase } from "./neon-http/index.cjs";
21
21
  import type { NeonDatabase } from "./neon-serverless/index.cjs";
22
+ import type { NodePgDatabase } from "./node-postgres/driver.cjs";
22
23
  import type { PlanetScaleDatabase } from "./planetscale-serverless/index.cjs";
23
24
  import type { PostgresJsDatabase } from "./postgres-js/index.cjs";
24
25
  import type { TiDBServerlessDatabase } from "./tidb-serverless/index.cjs";
25
- import type { DrizzleConfig } from "./utils.cjs";
26
+ import type { DrizzleConfig, IfNotImported } from "./utils.cjs";
26
27
  import type { VercelPgDatabase } from "./vercel-postgres/index.cjs";
27
- type BunSqliteDatabaseOptions = number | {
28
+ type BunSqliteDatabaseOptions = {
28
29
  /**
29
30
  * Open the database as read-only (no write operations, no create).
30
31
  *
@@ -44,22 +45,21 @@ type BunSqliteDatabaseOptions = number | {
44
45
  */
45
46
  readwrite?: boolean;
46
47
  };
47
- type BunSqliteDatabaseConfig = {
48
- filename?: ':memory:' | (string & {});
49
- options?: BunSqliteDatabaseOptions;
50
- } | ':memory:' | (string & {}) | undefined;
51
- type BetterSQLite3DatabaseConfig = {
52
- filename?: ':memory:' | (string & {}) | Buffer;
53
- options?: BetterSQLite3Options;
54
- } | ':memory:' | (string & {}) | undefined;
55
- type MonodriverNeonHttpConfig = {
48
+ type BunSqliteDatabaseConfig = ({
49
+ source?: string;
50
+ } & BunSqliteDatabaseOptions) | string | undefined;
51
+ type BetterSQLite3DatabaseConfig = ({
52
+ source?: string | Buffer;
53
+ } & BetterSQLite3Options) | string | undefined;
54
+ type MonodriverNeonHttpConfig = ({
56
55
  connectionString: string;
57
- options?: NeonHttpConfig<boolean, boolean>;
58
- } | string;
59
- type DatabaseClient = 'postgres-js' | 'neon-serverless' | 'neon-http' | 'vercel-postgres' | 'aws-data-api-pg' | 'planetscale' | 'mysql2' | 'tidb-serverless' | 'libsql' | 'turso' | 'd1' | 'bun:sqlite' | 'better-sqlite3';
56
+ } & NeonHttpConfig<boolean, boolean>) | string;
57
+ type AwsDataApiConnectionConfig = RDSConfig & Omit<DrizzleAwsDataApiPgConfig, keyof DrizzleConfig>;
58
+ type DatabaseClient = 'node-postgres' | 'postgres-js' | 'neon-websocket' | 'neon-http' | 'vercel-postgres' | 'aws-data-api-pg' | 'planetscale' | 'mysql2' | 'tidb-serverless' | 'libsql' | 'turso' | 'd1' | 'bun:sqlite' | 'better-sqlite3';
60
59
  type ClientDrizzleInstanceMap<TSchema extends Record<string, any>> = {
60
+ 'node-postgres': NodePgDatabase<TSchema>;
61
61
  'postgres-js': PostgresJsDatabase<TSchema>;
62
- 'neon-serverless': NeonDatabase<TSchema>;
62
+ 'neon-websocket': NeonDatabase<TSchema>;
63
63
  'neon-http': NeonHttpDatabase<TSchema>;
64
64
  'vercel-postgres': VercelPgDatabase<TSchema>;
65
65
  'aws-data-api-pg': AwsDataApiPgDatabase<TSchema>;
@@ -74,8 +74,9 @@ type ClientDrizzleInstanceMap<TSchema extends Record<string, any>> = {
74
74
  };
75
75
  type Primitive = string | number | boolean | undefined | null;
76
76
  type ClientInstanceMap = {
77
+ 'node-postgres': NodePgPool;
77
78
  'postgres-js': PostgresJsClient;
78
- 'neon-serverless': NeonServerlessPool;
79
+ 'neon-websocket': NeonServerlessPool;
79
80
  'neon-http': NeonQueryFunction<boolean, boolean>;
80
81
  'vercel-postgres': VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>);
81
82
  'aws-data-api-pg': RDSDataClient;
@@ -84,23 +85,45 @@ type ClientInstanceMap = {
84
85
  'tidb-serverless': TiDBConnection;
85
86
  libsql: LibsqlClient;
86
87
  turso: LibsqlClient;
87
- d1: D1Database;
88
+ d1: AnyD1Database;
88
89
  'bun:sqlite': BunDatabase;
89
90
  'better-sqlite3': BetterSQLite3Database;
90
91
  };
92
+ type ClientTypeImportErrorMap = {
93
+ 'node-postgres': 'pg`, `@types/pg';
94
+ 'postgres-js': 'postgres';
95
+ 'neon-websocket': '@neondatabase/serverless';
96
+ 'neon-http': '@neondatabase/serverless';
97
+ 'vercel-postgres': '@vercel/postgres';
98
+ 'aws-data-api-pg': '@aws-sdk/client-rds-data';
99
+ planetscale: '@planetscale/database';
100
+ mysql2: 'mysql2';
101
+ 'tidb-serverless': '@tidbcloud/serverless';
102
+ libsql: '@libsql/client';
103
+ turso: '@libsql/client';
104
+ d1: '@cloudflare/workers-types` or `@miniflare/d1';
105
+ 'bun:sqlite': 'bun-types';
106
+ 'better-sqlite3': 'better-sqlite3';
107
+ };
108
+ type ImportTypeError<TClient extends DatabaseClient> = `Please install \`${ClientTypeImportErrorMap[TClient]}\` for Drizzle ORM to connect to database`;
91
109
  type InitializerParams = {
110
+ 'node-postgres': {
111
+ connection: string | NodePgPoolConfig;
112
+ };
92
113
  'postgres-js': {
93
- connection: string | PostgresJSOptions<Record<string, PostgresJSPostgresType>>;
114
+ connection: string | ({
115
+ url?: string;
116
+ } & PostgresJSOptions<Record<string, PostgresJSPostgresType>>);
94
117
  };
95
- 'neon-serverless': {
96
- connection?: string | NeonServerlessConfig;
118
+ 'neon-websocket': {
119
+ connection: string | NeonServerlessConfig;
97
120
  };
98
121
  'neon-http': {
99
122
  connection: MonodriverNeonHttpConfig;
100
123
  };
101
124
  'vercel-postgres': {};
102
125
  'aws-data-api-pg': {
103
- connection?: RDSConfig;
126
+ connection: AwsDataApiConnectionConfig;
104
127
  };
105
128
  planetscale: {
106
129
  connection: PlanetscaleConfig | string;
@@ -118,7 +141,7 @@ type InitializerParams = {
118
141
  connection: LibsqlConfig | string;
119
142
  };
120
143
  d1: {
121
- connection: D1Database;
144
+ connection: AnyD1Database;
122
145
  };
123
146
  'bun:sqlite': {
124
147
  connection?: BunSqliteDatabaseConfig;
@@ -132,32 +155,30 @@ type DetermineClient<TClient extends DatabaseClient, TSchema extends Record<stri
132
155
  };
133
156
  export declare function drizzle<TClient extends DatabaseClient, TSchema extends Record<string, unknown> = Record<string, never>>(client: TClient, ...params: TClient extends 'bun:sqlite' | 'better-sqlite3' ? ([
134
157
  ] | [
135
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
136
- ] | [
137
- ':memory:'
138
- ] | [
139
- (string & {})
140
- ]) : TClient extends 'vercel-postgres' ? ([] | [
141
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
142
- ]) : TClient extends 'postgres-js' | 'tidb-serverless' | 'libsql' | 'turso' | 'planetscale' ? ([
143
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
144
- ] | [
145
- string
146
- ]) : TClient extends 'mysql2' ? ([
147
- (InitializerParams[TClient] & MySql2DrizzleConfig<TSchema>)
148
- ] | [
149
- string
150
- ]) : TClient extends 'aws-data-api-pg' ? [
151
- InitializerParams[TClient] & DrizzleAwsDataApiPgConfig<TSchema>
152
- ] : TClient extends 'neon-serverless' ? ([
153
- InitializerParams[TClient] & DrizzleConfig<TSchema> & {
158
+ (IfNotImported<ClientInstanceMap[TClient], {
159
+ connection: ImportTypeError<TClient>;
160
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
161
+ ] | [string]) : TClient extends 'vercel-postgres' ? ([] | [
162
+ (IfNotImported<ClientInstanceMap[TClient], {
163
+ connection: ImportTypeError<TClient>;
164
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
165
+ ]) : TClient extends 'postgres-js' | 'tidb-serverless' | 'libsql' | 'turso' | 'planetscale' | 'neon-http' | 'node-postgres' ? ([
166
+ (IfNotImported<ClientInstanceMap[TClient], {
167
+ connection: ImportTypeError<TClient>;
168
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
169
+ ] | [string]) : TClient extends 'mysql2' ? ([
170
+ (IfNotImported<ClientInstanceMap[TClient], {
171
+ connection: ImportTypeError<TClient>;
172
+ }, InitializerParams[TClient]> & MySql2DrizzleConfig<TSchema>)
173
+ ] | [string]) : TClient extends 'neon-websocket' ? ([
174
+ IfNotImported<ClientInstanceMap[TClient], {
175
+ connection: ImportTypeError<TClient>;
176
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema> & {
154
177
  ws?: any;
155
178
  }
156
- ] | [string] | []) : TClient extends 'neon-http' ? ([
157
- InitializerParams[TClient] & DrizzleConfig<TSchema>
158
- ] | [
159
- string
160
- ]) : [
161
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
179
+ ] | [string]) : [
180
+ (IfNotImported<ClientInstanceMap[TClient], {
181
+ connection: ImportTypeError<TClient>;
182
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
162
183
  ]): Promise<DetermineClient<TClient, TSchema>>;
163
184
  export {};
package/monodriver.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- /// <reference types="@cloudflare/workers-types" />
2
- /// <reference types="node" />
3
1
  /// <reference types="bun-types" />
2
+ /// <reference types="node" />
4
3
  import type { RDSDataClient, RDSDataClientConfig as RDSConfig } from '@aws-sdk/client-rds-data';
5
4
  import type { Client as LibsqlClient, Config as LibsqlConfig } from '@libsql/client';
6
5
  import type { HTTPTransactionOptions as NeonHttpConfig, NeonQueryFunction, Pool as NeonServerlessPool, PoolConfig as NeonServerlessConfig, QueryResult, QueryResultRow } from '@neondatabase/serverless';
@@ -10,21 +9,23 @@ import type { VercelPool } from '@vercel/postgres';
10
9
  import type { Database as BetterSQLite3Database, Options as BetterSQLite3Options } from 'better-sqlite3';
11
10
  import type { Database as BunDatabase } from 'bun:sqlite';
12
11
  import type { Pool as Mysql2Pool, PoolOptions as Mysql2Config } from 'mysql2';
12
+ import type { Pool as NodePgPool, PoolConfig as NodePgPoolConfig } from 'pg';
13
13
  import type { Options as PostgresJSOptions, PostgresType as PostgresJSPostgresType, Sql as PostgresJsClient } from 'postgres';
14
14
  import type { AwsDataApiPgDatabase, DrizzleAwsDataApiPgConfig } from "./aws-data-api/pg/index.js";
15
15
  import type { BetterSQLite3Database as DrizzleBetterSQLite3Database } from "./better-sqlite3/index.js";
16
16
  import type { BunSQLiteDatabase } from "./bun-sqlite/index.js";
17
- import type { DrizzleD1Database } from "./d1/index.js";
17
+ import type { AnyD1Database, DrizzleD1Database } from "./d1/index.js";
18
18
  import type { LibSQLDatabase } from "./libsql/index.js";
19
19
  import type { MySql2Database, MySql2DrizzleConfig } from "./mysql2/index.js";
20
20
  import type { NeonHttpDatabase } from "./neon-http/index.js";
21
21
  import type { NeonDatabase } from "./neon-serverless/index.js";
22
+ import type { NodePgDatabase } from "./node-postgres/driver.js";
22
23
  import type { PlanetScaleDatabase } from "./planetscale-serverless/index.js";
23
24
  import type { PostgresJsDatabase } from "./postgres-js/index.js";
24
25
  import type { TiDBServerlessDatabase } from "./tidb-serverless/index.js";
25
- import type { DrizzleConfig } from "./utils.js";
26
+ import type { DrizzleConfig, IfNotImported } from "./utils.js";
26
27
  import type { VercelPgDatabase } from "./vercel-postgres/index.js";
27
- type BunSqliteDatabaseOptions = number | {
28
+ type BunSqliteDatabaseOptions = {
28
29
  /**
29
30
  * Open the database as read-only (no write operations, no create).
30
31
  *
@@ -44,22 +45,21 @@ type BunSqliteDatabaseOptions = number | {
44
45
  */
45
46
  readwrite?: boolean;
46
47
  };
47
- type BunSqliteDatabaseConfig = {
48
- filename?: ':memory:' | (string & {});
49
- options?: BunSqliteDatabaseOptions;
50
- } | ':memory:' | (string & {}) | undefined;
51
- type BetterSQLite3DatabaseConfig = {
52
- filename?: ':memory:' | (string & {}) | Buffer;
53
- options?: BetterSQLite3Options;
54
- } | ':memory:' | (string & {}) | undefined;
55
- type MonodriverNeonHttpConfig = {
48
+ type BunSqliteDatabaseConfig = ({
49
+ source?: string;
50
+ } & BunSqliteDatabaseOptions) | string | undefined;
51
+ type BetterSQLite3DatabaseConfig = ({
52
+ source?: string | Buffer;
53
+ } & BetterSQLite3Options) | string | undefined;
54
+ type MonodriverNeonHttpConfig = ({
56
55
  connectionString: string;
57
- options?: NeonHttpConfig<boolean, boolean>;
58
- } | string;
59
- type DatabaseClient = 'postgres-js' | 'neon-serverless' | 'neon-http' | 'vercel-postgres' | 'aws-data-api-pg' | 'planetscale' | 'mysql2' | 'tidb-serverless' | 'libsql' | 'turso' | 'd1' | 'bun:sqlite' | 'better-sqlite3';
56
+ } & NeonHttpConfig<boolean, boolean>) | string;
57
+ type AwsDataApiConnectionConfig = RDSConfig & Omit<DrizzleAwsDataApiPgConfig, keyof DrizzleConfig>;
58
+ type DatabaseClient = 'node-postgres' | 'postgres-js' | 'neon-websocket' | 'neon-http' | 'vercel-postgres' | 'aws-data-api-pg' | 'planetscale' | 'mysql2' | 'tidb-serverless' | 'libsql' | 'turso' | 'd1' | 'bun:sqlite' | 'better-sqlite3';
60
59
  type ClientDrizzleInstanceMap<TSchema extends Record<string, any>> = {
60
+ 'node-postgres': NodePgDatabase<TSchema>;
61
61
  'postgres-js': PostgresJsDatabase<TSchema>;
62
- 'neon-serverless': NeonDatabase<TSchema>;
62
+ 'neon-websocket': NeonDatabase<TSchema>;
63
63
  'neon-http': NeonHttpDatabase<TSchema>;
64
64
  'vercel-postgres': VercelPgDatabase<TSchema>;
65
65
  'aws-data-api-pg': AwsDataApiPgDatabase<TSchema>;
@@ -74,8 +74,9 @@ type ClientDrizzleInstanceMap<TSchema extends Record<string, any>> = {
74
74
  };
75
75
  type Primitive = string | number | boolean | undefined | null;
76
76
  type ClientInstanceMap = {
77
+ 'node-postgres': NodePgPool;
77
78
  'postgres-js': PostgresJsClient;
78
- 'neon-serverless': NeonServerlessPool;
79
+ 'neon-websocket': NeonServerlessPool;
79
80
  'neon-http': NeonQueryFunction<boolean, boolean>;
80
81
  'vercel-postgres': VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>);
81
82
  'aws-data-api-pg': RDSDataClient;
@@ -84,23 +85,45 @@ type ClientInstanceMap = {
84
85
  'tidb-serverless': TiDBConnection;
85
86
  libsql: LibsqlClient;
86
87
  turso: LibsqlClient;
87
- d1: D1Database;
88
+ d1: AnyD1Database;
88
89
  'bun:sqlite': BunDatabase;
89
90
  'better-sqlite3': BetterSQLite3Database;
90
91
  };
92
+ type ClientTypeImportErrorMap = {
93
+ 'node-postgres': 'pg`, `@types/pg';
94
+ 'postgres-js': 'postgres';
95
+ 'neon-websocket': '@neondatabase/serverless';
96
+ 'neon-http': '@neondatabase/serverless';
97
+ 'vercel-postgres': '@vercel/postgres';
98
+ 'aws-data-api-pg': '@aws-sdk/client-rds-data';
99
+ planetscale: '@planetscale/database';
100
+ mysql2: 'mysql2';
101
+ 'tidb-serverless': '@tidbcloud/serverless';
102
+ libsql: '@libsql/client';
103
+ turso: '@libsql/client';
104
+ d1: '@cloudflare/workers-types` or `@miniflare/d1';
105
+ 'bun:sqlite': 'bun-types';
106
+ 'better-sqlite3': 'better-sqlite3';
107
+ };
108
+ type ImportTypeError<TClient extends DatabaseClient> = `Please install \`${ClientTypeImportErrorMap[TClient]}\` for Drizzle ORM to connect to database`;
91
109
  type InitializerParams = {
110
+ 'node-postgres': {
111
+ connection: string | NodePgPoolConfig;
112
+ };
92
113
  'postgres-js': {
93
- connection: string | PostgresJSOptions<Record<string, PostgresJSPostgresType>>;
114
+ connection: string | ({
115
+ url?: string;
116
+ } & PostgresJSOptions<Record<string, PostgresJSPostgresType>>);
94
117
  };
95
- 'neon-serverless': {
96
- connection?: string | NeonServerlessConfig;
118
+ 'neon-websocket': {
119
+ connection: string | NeonServerlessConfig;
97
120
  };
98
121
  'neon-http': {
99
122
  connection: MonodriverNeonHttpConfig;
100
123
  };
101
124
  'vercel-postgres': {};
102
125
  'aws-data-api-pg': {
103
- connection?: RDSConfig;
126
+ connection: AwsDataApiConnectionConfig;
104
127
  };
105
128
  planetscale: {
106
129
  connection: PlanetscaleConfig | string;
@@ -118,7 +141,7 @@ type InitializerParams = {
118
141
  connection: LibsqlConfig | string;
119
142
  };
120
143
  d1: {
121
- connection: D1Database;
144
+ connection: AnyD1Database;
122
145
  };
123
146
  'bun:sqlite': {
124
147
  connection?: BunSqliteDatabaseConfig;
@@ -132,32 +155,30 @@ type DetermineClient<TClient extends DatabaseClient, TSchema extends Record<stri
132
155
  };
133
156
  export declare function drizzle<TClient extends DatabaseClient, TSchema extends Record<string, unknown> = Record<string, never>>(client: TClient, ...params: TClient extends 'bun:sqlite' | 'better-sqlite3' ? ([
134
157
  ] | [
135
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
136
- ] | [
137
- ':memory:'
138
- ] | [
139
- (string & {})
140
- ]) : TClient extends 'vercel-postgres' ? ([] | [
141
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
142
- ]) : TClient extends 'postgres-js' | 'tidb-serverless' | 'libsql' | 'turso' | 'planetscale' ? ([
143
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
144
- ] | [
145
- string
146
- ]) : TClient extends 'mysql2' ? ([
147
- (InitializerParams[TClient] & MySql2DrizzleConfig<TSchema>)
148
- ] | [
149
- string
150
- ]) : TClient extends 'aws-data-api-pg' ? [
151
- InitializerParams[TClient] & DrizzleAwsDataApiPgConfig<TSchema>
152
- ] : TClient extends 'neon-serverless' ? ([
153
- InitializerParams[TClient] & DrizzleConfig<TSchema> & {
158
+ (IfNotImported<ClientInstanceMap[TClient], {
159
+ connection: ImportTypeError<TClient>;
160
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
161
+ ] | [string]) : TClient extends 'vercel-postgres' ? ([] | [
162
+ (IfNotImported<ClientInstanceMap[TClient], {
163
+ connection: ImportTypeError<TClient>;
164
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
165
+ ]) : TClient extends 'postgres-js' | 'tidb-serverless' | 'libsql' | 'turso' | 'planetscale' | 'neon-http' | 'node-postgres' ? ([
166
+ (IfNotImported<ClientInstanceMap[TClient], {
167
+ connection: ImportTypeError<TClient>;
168
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
169
+ ] | [string]) : TClient extends 'mysql2' ? ([
170
+ (IfNotImported<ClientInstanceMap[TClient], {
171
+ connection: ImportTypeError<TClient>;
172
+ }, InitializerParams[TClient]> & MySql2DrizzleConfig<TSchema>)
173
+ ] | [string]) : TClient extends 'neon-websocket' ? ([
174
+ IfNotImported<ClientInstanceMap[TClient], {
175
+ connection: ImportTypeError<TClient>;
176
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema> & {
154
177
  ws?: any;
155
178
  }
156
- ] | [string] | []) : TClient extends 'neon-http' ? ([
157
- InitializerParams[TClient] & DrizzleConfig<TSchema>
158
- ] | [
159
- string
160
- ]) : [
161
- (InitializerParams[TClient] & DrizzleConfig<TSchema>)
179
+ ] | [string]) : [
180
+ (IfNotImported<ClientInstanceMap[TClient], {
181
+ connection: ImportTypeError<TClient>;
182
+ }, InitializerParams[TClient]> & DrizzleConfig<TSchema>)
162
183
  ]): Promise<DetermineClient<TClient, TSchema>>;
163
184
  export {};
package/monodriver.js CHANGED
@@ -8,15 +8,32 @@ function assertUnreachable(_) {
8
8
  }
9
9
  async function drizzle(client, ...params) {
10
10
  switch (client) {
11
+ case "node-postgres": {
12
+ const defpg = await import("pg").catch(() => importError("pg"));
13
+ const { drizzle: drizzle2 } = await import("./node-postgres");
14
+ if (typeof params[0] === "object") {
15
+ const { connection, ...drizzleConfig } = params[0];
16
+ const instance2 = typeof connection === "string" ? new defpg.default.Pool({
17
+ connectionString: connection
18
+ }) : new defpg.default.Pool(connection);
19
+ const db2 = drizzle2(instance2, drizzleConfig);
20
+ return db2;
21
+ }
22
+ const instance = typeof params[0] === "string" ? new defpg.default.Pool({
23
+ connectionString: params[0]
24
+ }) : new defpg.default.Pool(params[0]);
25
+ const db = drizzle2(instance);
26
+ return db;
27
+ }
11
28
  case "aws-data-api-pg": {
12
29
  const { connection, ...drizzleConfig } = params[0];
30
+ const { resourceArn, database, secretArn, ...rdsConfig } = connection;
13
31
  const { RDSDataClient } = await import("@aws-sdk/client-rds-data").catch(
14
32
  () => importError("@aws-sdk/client-rds-data")
15
33
  );
16
34
  const { drizzle: drizzle2 } = await import("./aws-data-api/pg");
17
- const instance = connection ? new RDSDataClient(connection) : new RDSDataClient();
18
- const db = drizzle2(instance, drizzleConfig);
19
- db.$client = instance;
35
+ const instance = new RDSDataClient(rdsConfig);
36
+ const db = drizzle2(instance, { resourceArn, database, secretArn, ...drizzleConfig });
20
37
  return db;
21
38
  }
22
39
  case "better-sqlite3": {
@@ -25,49 +42,45 @@ async function drizzle(client, ...params) {
25
42
  if (typeof params[0] === "object") {
26
43
  const { connection, ...drizzleConfig } = params[0];
27
44
  if (typeof connection === "object") {
28
- const { filename, options } = connection;
29
- const instance3 = new Client(filename, options);
45
+ const { source, ...options } = connection;
46
+ const instance3 = new Client(source, options);
30
47
  const db3 = drizzle2(instance3, drizzleConfig);
31
- db3.$client = instance3;
32
48
  return db3;
33
49
  }
34
50
  const instance2 = new Client(connection);
35
51
  const db2 = drizzle2(instance2, drizzleConfig);
36
- db2.$client = instance2;
37
52
  return db2;
38
53
  }
39
54
  const instance = new Client(params[0]);
40
55
  const db = drizzle2(instance);
41
- db.$client = instance;
42
56
  return db;
43
57
  }
44
58
  case "bun:sqlite": {
45
- const { Database: Client } = await import("bun:sqlite").catch(() => importError("bun:sqlite"));
59
+ const { Database: Client } = await import("bun:sqlite").catch(() => {
60
+ throw new Error(`Please use bun to use 'bun:sqlite' for Drizzle ORM to connect to database`);
61
+ });
46
62
  const { drizzle: drizzle2 } = await import("./bun-sqlite");
47
63
  if (typeof params[0] === "object") {
48
64
  const { connection, ...drizzleConfig } = params[0];
49
65
  if (typeof connection === "object") {
50
- const { filename, options } = connection;
51
- const instance3 = new Client(filename, options);
66
+ const { source, ...opts } = connection;
67
+ const options = Object.values(opts).filter((v) => v !== void 0).length ? opts : void 0;
68
+ const instance3 = new Client(source, options);
52
69
  const db3 = drizzle2(instance3, drizzleConfig);
53
- db3.$client = instance3;
54
70
  return db3;
55
71
  }
56
72
  const instance2 = new Client(connection);
57
73
  const db2 = drizzle2(instance2, drizzleConfig);
58
- db2.$client = instance2;
59
74
  return db2;
60
75
  }
61
76
  const instance = new Client(params[0]);
62
77
  const db = drizzle2(instance);
63
- db.$client = instance;
64
78
  return db;
65
79
  }
66
80
  case "d1": {
67
81
  const { connection, ...drizzleConfig } = params[0];
68
82
  const { drizzle: drizzle2 } = await import("./d1");
69
83
  const db = drizzle2(connection, drizzleConfig);
70
- db.$client = connection;
71
84
  return db;
72
85
  }
73
86
  case "libsql":
@@ -79,29 +92,25 @@ async function drizzle(client, ...params) {
79
92
  url: params[0]
80
93
  });
81
94
  const db2 = drizzle2(instance2);
82
- db2.$client = instance2;
83
95
  return db2;
84
96
  }
85
97
  const { connection, ...drizzleConfig } = params[0];
86
98
  const instance = typeof connection === "string" ? createClient({ url: connection }) : createClient(connection);
87
99
  const db = drizzle2(instance, drizzleConfig);
88
- db.$client = instance;
89
100
  return db;
90
101
  }
91
102
  case "mysql2": {
92
- const { createPool } = await import("mysql2/promise").catch(() => importError("mysql2/promise"));
103
+ const { createPool } = await import("mysql2/promise").catch(() => importError("mysql2"));
93
104
  const { drizzle: drizzle2 } = await import("./mysql2");
94
105
  if (typeof params[0] === "object") {
95
106
  const { connection, ...drizzleConfig } = params[0];
96
107
  const instance2 = createPool(connection);
97
108
  const db2 = drizzle2(instance2, drizzleConfig);
98
- db2.$client = instance2;
99
109
  return db2;
100
110
  }
101
111
  const connectionString = params[0];
102
112
  const instance = createPool(connectionString);
103
113
  const db = drizzle2(instance);
104
- db.$client = instance;
105
114
  return db;
106
115
  }
107
116
  case "neon-http": {
@@ -110,23 +119,20 @@ async function drizzle(client, ...params) {
110
119
  if (typeof params[0] === "object") {
111
120
  const { connection, ...drizzleConfig } = params[0];
112
121
  if (typeof connection === "object") {
113
- const { connectionString, options } = connection;
122
+ const { connectionString, ...options } = connection;
114
123
  const instance3 = neon(connectionString, options);
115
124
  const db3 = drizzle2(instance3, drizzleConfig);
116
- db3.$client = instance3;
117
125
  return db3;
118
126
  }
119
127
  const instance2 = neon(connection);
120
128
  const db2 = drizzle2(instance2, drizzleConfig);
121
- db2.$client = instance2;
122
129
  return db2;
123
130
  }
124
131
  const instance = neon(params[0]);
125
132
  const db = drizzle2(instance);
126
- db.$client = instance;
127
133
  return db;
128
134
  }
129
- case "neon-serverless": {
135
+ case "neon-websocket": {
130
136
  const { Pool, neonConfig } = await import("@neondatabase/serverless").catch(
131
137
  () => importError("@neondatabase/serverless")
132
138
  );
@@ -136,7 +142,6 @@ async function drizzle(client, ...params) {
136
142
  connectionString: params[0]
137
143
  });
138
144
  const db2 = drizzle2(instance2);
139
- db2.$client = instance2;
140
145
  return db2;
141
146
  }
142
147
  if (typeof params[0] === "object") {
@@ -148,12 +153,10 @@ async function drizzle(client, ...params) {
148
153
  connectionString: connection
149
154
  }) : new Pool(connection);
150
155
  const db2 = drizzle2(instance2, drizzleConfig);
151
- db2.$client = instance2;
152
156
  return db2;
153
157
  }
154
158
  const instance = new Pool();
155
159
  const db = drizzle2(instance);
156
- db.$client = instance;
157
160
  return db;
158
161
  }
159
162
  case "planetscale": {
@@ -167,14 +170,12 @@ async function drizzle(client, ...params) {
167
170
  connection
168
171
  );
169
172
  const db2 = drizzle2(instance2, drizzleConfig);
170
- db2.$client = instance2;
171
173
  return db2;
172
174
  }
173
175
  const instance = new Client({
174
176
  url: params[0]
175
177
  });
176
178
  const db = drizzle2(instance);
177
- db.$client = instance;
178
179
  return db;
179
180
  }
180
181
  case "postgres-js": {
@@ -182,14 +183,18 @@ async function drizzle(client, ...params) {
182
183
  const { drizzle: drizzle2 } = await import("./postgres-js");
183
184
  if (typeof params[0] === "object") {
184
185
  const { connection, ...drizzleConfig } = params[0];
186
+ if (typeof connection === "object" && connection.url !== void 0) {
187
+ const { url, ...config } = connection;
188
+ const instance3 = client2(url, config);
189
+ const db3 = drizzle2(instance3, drizzleConfig);
190
+ return db3;
191
+ }
185
192
  const instance2 = client2(connection);
186
193
  const db2 = drizzle2(instance2, drizzleConfig);
187
- db2.$client = instance2;
188
194
  return db2;
189
195
  }
190
196
  const instance = client2(params[0]);
191
197
  const db = drizzle2(instance);
192
- db.$client = instance;
193
198
  return db;
194
199
  }
195
200
  case "tidb-serverless": {
@@ -200,7 +205,6 @@ async function drizzle(client, ...params) {
200
205
  url: params[0]
201
206
  });
202
207
  const db2 = drizzle2(instance2);
203
- db2.$client = instance2;
204
208
  return db2;
205
209
  }
206
210
  const { connection, ...drizzleConfig } = params[0];
@@ -208,7 +212,6 @@ async function drizzle(client, ...params) {
208
212
  url: connection
209
213
  }) : connect(connection);
210
214
  const db = drizzle2(instance, drizzleConfig);
211
- db.$client = instance;
212
215
  return db;
213
216
  }
214
217
  case "vercel-postgres": {
@@ -216,7 +219,6 @@ async function drizzle(client, ...params) {
216
219
  const { sql } = await import("@vercel/postgres").catch(() => importError("@vercel/postgres"));
217
220
  const { drizzle: drizzle2 } = await import("./vercel-postgres");
218
221
  const db = drizzle2(sql, drizzleConfig);
219
- db.$client = sql;
220
222
  return db;
221
223
  }
222
224
  }