drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.82k stars 659 forks source link

[BUG]: Logger doesn't print iterator queries #2414

Open geovanisouza92 opened 6 months ago

geovanisouza92 commented 6 months ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

When I'm using an .iterator(params) on a prepared statement (cloneClients), I don't see any Query: select ... logs, but I noticed that .execute(params) (cloneEdgesServices) works fine.

Code samples ```ts // connection.ts import { drizzle } from "drizzle-orm/mysql2"; import { createConnection } from "mysql2"; import { config } from "../config"; export const connection = createConnection(config.DATABASE_URL); export const db = drizzle(connection, { logger: true, }); export type DB = typeof db; ``` ```ts // queries.ts const selectClients = db .select() .from(clients) .where(inArray(clients.serviceId, sql`(${sql.placeholder('sourceServiceIds')})`)) .prepare(); export async function cloneClients(sourceServiceIds: number[], targetServiceId: number) { const inserts = []; for await (const client of selectClients.iterator({ sourceServiceIds })) { const newClient: typeof clients.$inferInsert = { ...client, // omitted }; inserts.push(db.insert(clients).values(newClient)); } await Promise.all(inserts); } const selectEdgesServices = db .select({ edgeId: edgesServices.edgeId, active: edgesServices.active, }) .from(edgesServices) .where(inArray(edgesServices.serviceId, sql`(${sql.placeholder('sourceServiceIds')})`)) .prepare(); export async function cloneEdgesServices(sourceServiceIds: number[], targetServiceId: number) { const rows = await selectEdgesServices.execute({ sourceServiceIds }); const values = rows.map((edgeService): typeof edgesServices.$inferInsert => ({ ...edgeService, // omitted })); await db.insert(edgesServices).values(values); } ```

Expected behavior

See Query: select... logs from .iterator(params) just like .execute(params) calls.

Environment & setup

rogerhlg commented 1 week ago

same problem here ps: using mysql 8.0 and drizzle-orm 0.36.2