Generate SQL statements with Drizzle

I wanna generate statements using Drizzle utilities - for example I have this sql`DROP TRIGGER IF EXISTS ${sql.identifier(triggerName)}` But how do I get the final SQL string from this? db.run(...).getQuery() works but feels counter-intuitive - is that the best way to do that? In case that's important - what I wanna do is create some utils to automate trigger creation a bit - so I could generate trigger statements with Drizzle and then insert those into my migration files
3 Replies
Huge Letters
Huge LettersOP8mo ago
Drizzle ORM - Magic sql`` operator
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Huge Letters
Huge LettersOP8mo ago
!resolve
Huge Letters
Huge LettersOP8mo ago
In case anyone would stumble upon this and find that useful - here's a gist with results you can use that to create triggers with drizzle and run a script to generate a new migration file with those triggers https://gist.github.com/HugeLetters/7cce16a0f57b612507c7e17a9b4e688e
Gist
Drizzle ORM SQLite Trigger migrations
Drizzle ORM SQLite Trigger migrations. GitHub Gist: instantly share code, notes, and snippets.
Want results from more Discord servers?
Add your server