Skip to content

sql.simple() for DB initialization and typescript support #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mukulgupta21 opened this issue Oct 28, 2023 · 1 comment
Closed

sql.simple() for DB initialization and typescript support #714

mukulgupta21 opened this issue Oct 28, 2023 · 1 comment

Comments

@mukulgupta21
Copy link

mukulgupta21 commented Oct 28, 2023

Problem

I have a use-case where I have a DDL script to initialise the database. Something similar to below:

CREATE DATABASE dbName with owner dbuser ;

CREATE TABLE IF NOT EXISTS table (
  col1 VARCHAR(255) NOT NULL,
  col2 VARCHAR(255) NOT NULL,
);

I'm trying to use it as below:

await (sql`${sql.unsafe(sqlScript)}` as any).simple();

which results in the following error:

Error creating database PostgresError: CREATE DATABASE cannot run inside a transaction block

EDIT: I realize this is not possible to do in postgresql since one cannot switch a database without re-initializing the connection (aka backend).

Questions:

  • What is the recommended way to do this? I'd like to maintain the multiple statement SQL script independently.
  • Can we get typescript support for simple method?
iby added a commit to iby/postgres that referenced this issue Jan 6, 2024
@iby
Copy link
Contributor

iby commented Jan 6, 2024

Have a look at https://github.com/porsager/postgres/issues/198 – looks like a similar case 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants