Get raw query from toSQL

I trying to figure out if drizzle has a function or helper built in that builds the raw query returned from toSQL right now toSQL returns params and sql as an object, i would like to get the raw sql query this is what im doing now to achieve this, any alternatives or is there a something drizzle provides i missed thanks
buildQuery(query: string, params: unknown[]) {
let index = 1;

return query.replace(/\$\d+/g, () => {
const value = params[index - 1];
index++;

return `'${value}'`;
});
}
buildQuery(query: string, params: unknown[]) {
let index = 1;

return query.replace(/\$\d+/g, () => {
const value = params[index - 1];
index++;

return `'${value}'`;
});
}
5 Replies
Angelelz
Angelelz13mo ago
I believe .getSql() is what you're looking for Also, you might want to take a look at the dialect classes that Drizzle has
Fleuv
Fleuv8mo ago
@Angelelz it seems like the section you refer to got removed. Any idea where to find it now? Or is this still even possible?
Angelelz
Angelelz8mo ago
What was removed?
Fleuv
Fleuv8mo ago
Ooh nvm, I got confused because for some reason the page scrolled all the way down when I clicked on your link. If it might get removed. Then here it is now.
import { PgDialect } from 'drizzle-orm/pg-core';

const pgDialect = new PgDialect();
pgDialect.sqlToQuery(sql`select * from ${usersTable} where ${usersTable.id} = ${12}`);
import { PgDialect } from 'drizzle-orm/pg-core';

const pgDialect = new PgDialect();
pgDialect.sqlToQuery(sql`select * from ${usersTable} where ${usersTable.id} = ${12}`);
Want results from more Discord servers?
Add your server