Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Bun sql returns malformed arrays #4021

Open
1 task done
Scooter1337 opened this issue Jan 28, 2025 · 2 comments
Open
1 task done

[BUG]: Bun sql returns malformed arrays #4021

Scooter1337 opened this issue Jan 28, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@Scooter1337
Copy link

Scooter1337 commented Jan 28, 2025

Report hasn't been filed before.

  • 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.39.0

What version of drizzle-kit are you using?

0.30.3

Other packages

No response

Describe the Bug

I went from

import { drizzle, PostgresJsQueryResultHKT } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as defaultSchema from "./schema/default.schema";
import * as organizationSchema from "./schema/organization.schema";
import * as authSchema from "./schema/auth.schema";

const schema = { ...defaultSchema, ...organizationSchema, ...authSchema };

const client = postgres(process.env.DATABASE_URL as string);
export const Db = drizzle(client, { schema });

export type DB = typeof Db;

to

import { drizzle } from "drizzle-orm/bun-sql";
import * as defaultSchema from "./schema/default.schema";
import * as organizationSchema from "./schema/organization.schema";
import * as authSchema from "./schema/auth.schema";

const schema = { ...defaultSchema, ...organizationSchema, ...authSchema };

export const Db = drizzle(process.env.DATABASE_URL as string, { schema });

export type DB = typeof Db;

Some queries now return:

[object Object]

so a string, instead of e.g.:

[
    {
        "id": "0194a4b3-f6ad-7255-92cc-3ce115b69370",
        ...
    }
]

I tried to anonymize my query as much as possible, but the query in question is the following:

await Db.select({
      id: table.id,
      A: table.A,
      B: table.B,
      C: table.C,
      D: table.D,
      E: table.E,
      F: table.F,
      G: sql<number>`sum(${table2.G})`,
      H: sql<number>`sum(${table2.H})`,
      I: sql<number>`sum(${table2.H} * ${table2.J})`,
      J: table.J,
      K: table.K,
    })
      .from(table)
      .innerJoin(table2, eq(table.id, table2.A))
      .where(
        and(
          eq(table.L, L),
          query.B ? gte(table.B, new Date(query.B)) : undefined,
          query.C ? lte(table.C, new Date(query.C)) : undefined,
          query.A && query.A.length > 0
            ? inArray(table.A, query.A)
            : undefined
        )
      )
      .offset(query.offset || 0)
      .limit(query.limit || 10)
      .orderBy(desc(table.B))
      .groupBy(table.id);
@Scooter1337 Scooter1337 added the bug Something isn't working label Jan 28, 2025
@Scooter1337
Copy link
Author

I've checked docker logs already, both drivers execute the exact same sql

@Scooter1337 Scooter1337 changed the title [BUG]: Bun sql is fast but broken [BUG]: Bun sql is fast but returns '[object Object]' instead of array Jan 28, 2025
@Scooter1337
Copy link
Author

Scooter1337 commented Jan 28, 2025

With bun sql the response that is yet to be serialized is malformed:

response: [
    {
      id: "0194a4b3-f6ad-7255-92cc-3ce115b69370",
      ... truncated
    }, statement: undefined, command: undefined, count: undefined
  ],

compared to with postgresjs:

 response: [
    {
      id: "0194a4b3-f6ad-7255-92cc-3ce115b69370",
      ... truncated
    }
  ],

@Scooter1337 Scooter1337 changed the title [BUG]: Bun sql is fast but returns '[object Object]' instead of array [BUG]: Bun sql returns malformed arrays Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant