drizzle-team / drizzle-team/drizzle-orm

[BUG]: "provide your existing driver" breaks postgres.js driver after `drizzle(driver)`

Open
#4,426 3 comments 1 reaction 0 assignees View on GitHub
bug driver/postgresjs priority qb/crud
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.42.0

### What version of `drizzle-kit` are you using?

0.30.6

### Other packages

_No response_

### Describe the Bug

Running on Deno 2.1.4 (via `supabase` `edge-runtime`)

Following [the instructions](https://orm.drizzle.team/docs/get-started-postgresql)

```
import { drizzle } from 'npm:drizzle-orm@0.42.0/postgres-js';
import postgres from 'npm:postgres@3.4.5';
const queryClient = postgres(Deno.env.get("POSTGRES_BACKEND_URL")!);
const db = drizzle({ client: queryClient });
```

Works fine. However, if you try the following after this:

```
await sql`create table toto (id int, bidule jsonb);`;
await sql`insert into toto (1, '{"foo":"bar"}');`;
```

So far, so good. But:

```
const bidule = {bidule: {bar: "foo"}};
await sql`update toto set ${sql(bidule)} where id = 1;`
```

FAILS.

```
[Error] TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Object
at Function.byteLength (ext:deno_node/internal/buffer.mjs:448:11)
at Function.str (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/bytes.js:22:27)
at file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:938:16
at Array.forEach ()
at Bind (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:928:16)
at prepared (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:204:7)
at ParameterDescription (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:607:58)
at handle (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:474:6)
at Socket.data (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/connection.js:315:9)
at Socket.emit (ext:deno_node/_events.mjs:393:28)
at cachedError (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/query.js:170:23)
at new Query (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/query.js:36:24)
at sql (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/postgres/3.4.5/src/index.js:112:11)
at Object.handler (file:///var/tmp/sb-compile-edge-runtime/functions/wtf/index.ts:41:12) {
code: "ERR_INVALID_ARG_TYPE",
name: "TypeError",
toString: [Function (anonymous)]
}
```

If you remove the line `const db = drizzle({ client: queryClient });`, then the line

```
await sql`update toto set ${sql(bidule)} where id = 1;`
```
works as expected. If you create a *new* driver and pass that, obviously everything works as expected.

It therefore follows that the `drizzle` initialisation actually BREAKS the `postgres.js` driver instance you passed it. AT THE VERY LEAST this should be mentioned in the docs - there is no suggestion at all currently in the docs that there are any differences.

Contributor guide

Open the contributing guide

Research direction

Start with the PostgreSQL getting-started documentation and reproduce the Deno example using `drizzle({ client: queryClient })`. Then trace the postgres.js stack locations named in the report, including `src/bytes.js` and `src/connection.js`. Done means the shown update works after initialization, or the documented differences and required usage are explicit, with a regression check for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
deno, postgres, typescript
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.