You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to automatically generate the CREATE TABLE IF NOT EXISTS SQL string directly from the pgTable schema definition in Drizzle ORM. This would allow me to pass the generated SQL to an in-memory database for testing purposes.
Currently, I'm manually constructing the SQL string like this:
awaitinMemoryDbClient.exec(` CREATE TABLE IF NOT EXISTS "email_submission" ( "id" serial PRIMARY KEY NOT NULL, "name" text NOT NULL, "email" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "email_submission_email_unique" UNIQUE("email") );`);
However, I'd like to automate this process directly from the pgTable schema, which looks like this:
I am using diffTestSchemas to generate the SQL manually, but this is not convenient for testing, as I need to execute the SQL string dynamically in my in-memory database.
constto={emailSubmissionTable};const{ sqlStatements, statements }=awaitdiffTestSchemas({},to,[]);console.log(sqlStatements);/* Output:[ 'CREATE TABLE "emailSubmission" (\n' + '\t"id" serial PRIMARY KEY NOT NULL,\n' + '\t"name" text NOT NULL,\n' + '\t"email" text NOT NULL,\n' + '\t"createdAt" timestamp DEFAULT now() NOT NULL,\n' + '\tCONSTRAINT "emailSubmission_email_unique" UNIQUE("email")\n' + ');\n', 'CREATE UNIQUE INDEX "emailUniqueIndex" ON "emailSubmission" USING btree ("email");']*/
What I Need:
It would be great if Drizzle ORM provided a built-in helper function to generate the CREATE TABLE IF NOT EXISTS SQL string directly from the pgTable schema definition, like this:
import{generateCreateTablesSQL}from'drizzle-orm/utils';// Hypothetical helper functionconstinMemoryDbClient=newPGlite();// Generate the SQL string from the pgTable schemaconstsql=generateCreateTablesSQL(emailSubmissionTable);// Execute the generated SQL in the in-memory databaseawaitinMemoryDbClient.exec(sql);
This would save time and simplify the process of testing queries against an in-memory database.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to automatically generate the
CREATE TABLE IF NOT EXISTS
SQL string directly from thepgTable
schema definition in Drizzle ORM. This would allow me to pass the generated SQL to an in-memory database for testing purposes.Currently, I'm manually constructing the SQL string like this:
However, I'd like to automate this process directly from the
pgTable
schema, which looks like this:I am using diffTestSchemas to generate the SQL manually, but this is not convenient for testing, as I need to execute the SQL string dynamically in my in-memory database.
What I Need:
It would be great if Drizzle ORM provided a built-in helper function to generate the
CREATE TABLE IF NOT EXISTS
SQL string directly from thepgTable
schema definition, like this:This would save time and simplify the process of testing queries against an in-memory database.
Beta Was this translation helpful? Give feedback.
All reactions