tazmaniax
tazmaniax
DTDrizzle Team
Created by tazmaniax on 11/28/2024 in #help
Unable to pass JSON array to PostgreSQL function jsonb[] parameter using execute raw SQL
I've actually just found a solution after much trial and error by defining my own pgArray function that converts an array into the right format but it feels clumsy and should I expect Drizzle to be able to do this under the covers?
async sendBatch(msgs: T[], delay = 0): Promise<string[]> {
const result = await this.db.execute<{ send_batch: number }>(
sql`SELECT * FROM pgmq.send_batch(${this.queueName}, ${this.pgArray(msgs)}::jsonb[], ${delay})`,
)

return result.map((r) => String(r.send_batch))
}

private pgArray(array: unknown[]): SQL {
const items = array.map(item => `'${JSON.stringify(item)}'`).join(', ')
return sql.raw(`ARRAY[${items}]`)
}
async sendBatch(msgs: T[], delay = 0): Promise<string[]> {
const result = await this.db.execute<{ send_batch: number }>(
sql`SELECT * FROM pgmq.send_batch(${this.queueName}, ${this.pgArray(msgs)}::jsonb[], ${delay})`,
)

return result.map((r) => String(r.send_batch))
}

private pgArray(array: unknown[]): SQL {
const items = array.map(item => `'${JSON.stringify(item)}'`).join(', ')
return sql.raw(`ARRAY[${items}]`)
}
2 replies
DTDrizzle Team
Created by tazmaniax on 11/25/2024 in #help
drizzle-kit introspect schemaFilters parameter ignored
2 replies