drizzle-team / drizzle-team/drizzle-orm

[BUG]: custom type `bytea` undefined error

Open
#3,902 8 comments 4 reactions 0 assignees View on GitHub
bug db/postgres 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.38.3

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

0.30.1

### Other packages

@neondatabase/serverless@0.10.4

### Describe the Bug

Using postgres with neondb adapter:

```ts
import { env } from "@/data/env/server"
import { Pool } from "@neondatabase/serverless"
import { drizzle } from "drizzle-orm/neon-serverless"
import * as schema from "./schema"

const pool = new Pool({ connectionString: env.DATABASE_URL })
export const db = drizzle(pool, { schema })
```

when defining a custom bytea type like this:

```ts
import { customType } from "drizzle-orm/pg-core"

export const bytea = customType<{ data: Buffer }>({
dataType() {
return "bytea"
},
toDriver(value: Buffer) {
return value
},
fromDriver(value: unknown) {
return value as Buffer
},
})
```

and making using this type in a table like this:

```ts
export const totpCredentialTable = pgTable("totp_credential", {
id: text("id").primaryKey().notNull(),
userId: text("user_id")
.notNull()
.references(() => userTable.id, { onDelete: "cascade" }),
key: bytea().notNull(),
})
```

when querying it like this:

```ts
const result = await db.select().from(totpCredentialTable).where(eq(totpCredentialTable.userId, userId)).limit(1)
```

I am getting the following error:

```
node_modules/.pnpm/@neondatabase+serverless@0.10.4/node_modules/@neondatabase/serverless/index.mjs (1345:62) @ eval
⨯ TypeError: Cannot read properties of undefined (reading '0')
at async getUserTOTPKey (./src/features/auth/lib/server/totp.ts:24:20)
at async verify2FAAction (./src/features/auth/2fa/totp/actions/verify-2fa-action.ts:59:21)
digest: "3947734796"
1343 | on client which has already been released to the pool.")}a(Cc,"throwOnDoubleRele\
1344 | ase");function Tt(r,e){if(e)return{callback:e,result:void 0};let t,n,i=a(function(o,u){
> 1345 | o?t(o):n(u)},"cb"),s=new r(function(o,u){n=o,t=u}).catch(o=>{throw Error.captureStackTrace(
| ^
1346 | o),o});return{callback:i,result:s}}a(Tt,"promisify");function Tc(r,e){return a(function t(n){
1347 | n.client=e,e.removeListener("error",t),e.on("error",()=>{r.log("additional clien\
1348 | t error after disconnection due to error",n)}),r._remove(e),r.emit("error",n,e)},
```

So I cannot access this table in any way anymore

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.