I can't for the life of me get Prisma to create a ...
# orm-help
b
I can't for the life of me get Prisma to create a DB, using
Copy code
await prismaClient.$executeRaw(
  Prisma.sql`CREATE DATABASE ${databaseId} TEMPLATE ${templateName};`
);
on postgres, getting
STATEMENT:  CREATE DATABASE $1 TEMPLATE $2;
through on the DB side
t
I don't think those commands support paramaterized values, I think you have to perform it unsafe
n
@ben đŸ‘‹ You can create Database using the following query
Copy code
const databaseName = "testingdb";
const templateName = "template0";

const result = await prisma.$executeRawUnsafe(`CREATE DATABASE ${databaseName} TEMPLATE ${templateName};`);

console.log(result);
Here is a reference to executeRawUnsafe. Please note that you should sanitise your variables before passing them in a query to avoid potential risk of SQL Injection.
b
Yeah, that's what I was doing, but I don't think you can use
executeRawUnsafe
in a transaction
n
Yes, that’s a postgres limitation of not being able to create database in transaction. You can read about it here