Skip to content

Commit 027921f

Browse files
Fixed types of $client for clients created by drizzle function from credentials (#4742)
* Fixed types of `` for clients created by `drizzle` function from credentials * Add release notes --------- Co-authored-by: Andrii Sherman <andreysherman11@gmail.com>
1 parent e44d9bb commit 027921f

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

changelogs/drizzle-orm/0.44.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- Fixed types of `$client` for clients created by drizzle function
2+
3+
```ts
4+
await db.$client.[...]
5+
```
6+
7+
- Added the `updated_at` column to the `neon_auth.users_sync` table definition.

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.44.2",
3+
"version": "0.44.3",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/gel/driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function construct<
5353
client: TClient,
5454
config: DrizzleConfig<TSchema> = {},
5555
): GelJsDatabase<TSchema> & {
56-
$client: TClient;
56+
$client: GelClient extends TClient ? Client : TClient;
5757
} {
5858
const dialect = new GelDialect({ casing: config.casing });
5959
let logger;
@@ -104,7 +104,7 @@ export function drizzle<
104104
),
105105
]
106106
): GelJsDatabase<TSchema> & {
107-
$client: TClient;
107+
$client: GelClient extends TClient ? Client : TClient;
108108
} {
109109
if (typeof params[0] === 'string') {
110110
const instance = createClient({ dsn: params[0] });

drizzle-orm/src/mysql2/driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function construct<
6464
client: TClient,
6565
config: MySql2DrizzleConfig<TSchema> = {},
6666
): MySql2Database<TSchema> & {
67-
$client: TClient;
67+
$client: AnyMySql2Connection extends TClient ? CallbackPool : TClient;
6868
} {
6969
const dialect = new MySqlDialect({ casing: config.casing });
7070
let logger;
@@ -140,7 +140,7 @@ export function drizzle<
140140
),
141141
]
142142
): MySql2Database<TSchema> & {
143-
$client: TClient;
143+
$client: AnyMySql2Connection extends TClient ? CallbackPool : TClient;
144144
} {
145145
if (typeof params[0] === 'string') {
146146
const connectionString = params[0]!;

drizzle-orm/src/neon-serverless/driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function construct<
5353
client: TClient,
5454
config: DrizzleConfig<TSchema> = {},
5555
): NeonDatabase<TSchema> & {
56-
$client: TClient;
56+
$client: NeonClient extends TClient ? Pool : TClient;
5757
} {
5858
const dialect = new PgDialect({ casing: config.casing });
5959
let logger;
@@ -111,7 +111,7 @@ export function drizzle<
111111
),
112112
]
113113
): NeonDatabase<TSchema> & {
114-
$client: TClient;
114+
$client: NeonClient extends TClient ? Pool : TClient;
115115
} {
116116
if (typeof params[0] === 'string') {
117117
const instance = new Pool({

drizzle-orm/src/node-postgres/driver.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function construct<
5353
client: TClient,
5454
config: DrizzleConfig<TSchema> = {},
5555
): NodePgDatabase<TSchema> & {
56-
$client: TClient;
56+
$client: NodePgClient extends TClient ? Pool : TClient;
5757
} {
5858
const dialect = new PgDialect({ casing: config.casing });
5959
let logger;
@@ -101,17 +101,15 @@ export function drizzle<
101101
DrizzleConfig<TSchema>,
102102
]
103103
| [
104-
(
105-
& DrizzleConfig<TSchema>
106-
& ({
107-
connection: string | PoolConfig;
108-
} | {
109-
client: TClient;
110-
})
111-
),
104+
& DrizzleConfig<TSchema>
105+
& ({
106+
client: TClient;
107+
} | {
108+
connection: string | PoolConfig;
109+
}),
112110
]
113111
): NodePgDatabase<TSchema> & {
114-
$client: TClient;
112+
$client: NodePgClient extends TClient ? Pool : TClient;
115113
} {
116114
if (typeof params[0] === 'string') {
117115
const instance = new pg.Pool({

drizzle-orm/src/singlestore/driver.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function construct<
6565
client: TClient,
6666
config: SingleStoreDriverDrizzleConfig<TSchema> = {},
6767
): SingleStoreDriverDatabase<TSchema> & {
68-
$client: TClient;
68+
$client: AnySingleStoreDriverConnection extends TClient ? CallbackPool : TClient;
6969
} {
7070
const dialect = new SingleStoreDialect({ casing: config.casing });
7171
let logger;
@@ -140,7 +140,7 @@ export function drizzle<
140140
),
141141
]
142142
): SingleStoreDriverDatabase<TSchema> & {
143-
$client: TClient;
143+
$client: AnySingleStoreDriverConnection extends TClient ? CallbackPool : TClient;
144144
} {
145145
if (typeof params[0] === 'string') {
146146
const connectionString = params[0]!;
@@ -160,21 +160,19 @@ export function drizzle<
160160
if (client) return construct(client, drizzleConfig) as any;
161161

162162
let opts: PoolOptions = {};
163-
if (typeof connection === 'string') {
164-
opts = {
163+
opts = typeof connection === 'string'
164+
? {
165165
uri: connection,
166166
supportBigNumbers: true,
167167
connectAttributes: CONNECTION_ATTRS,
168-
};
169-
} else {
170-
opts = {
168+
}
169+
: {
171170
...connection,
172171
connectAttributes: {
173172
...connection!.connectAttributes,
174173
...CONNECTION_ATTRS,
175174
},
176175
};
177-
}
178176

179177
const instance = createPool(opts);
180178
const db = construct(instance, drizzleConfig);

drizzle-orm/src/vercel-postgres/driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function drizzle<
102102
),
103103
]
104104
): VercelPgDatabase<TSchema> & {
105-
$client: TClient;
105+
$client: VercelPgClient extends TClient ? typeof sql : TClient;
106106
} {
107107
if (isConfig(params[0])) {
108108
const { client, ...drizzleConfig } = params[0] as ({ client?: TClient } & DrizzleConfig<TSchema>);

0 commit comments

Comments
 (0)