Skip to content
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

Postgres transaction are broken #342

Open
ninjinskii opened this issue May 11, 2022 · 2 comments
Open

Postgres transaction are broken #342

ninjinskii opened this issue May 11, 2022 · 2 comments

Comments

@ninjinskii
Copy link

ninjinskii commented May 11, 2022

Hello !

Postgres transaction are bugged, i cant use them, i think i know why.

In the postgres docs, we see that after opening a transaction, we have to use the object returned by transaction() to make queries, not the base client
Deno postgres docs

But DenoDB doesn't give us a chance to work with this transaction object, neither use it to make the queries, thus systematically showing the error "This connection is currently locked by the "transaction" transaction"

This is where the code is broken:
https://github.com/eveningkid/denodb/blob/master/lib/connectors/postgres-connector.ts#L89

@ninjinskii
Copy link
Author

ninjinskii commented May 11, 2022

I've submit a PR that should fix the problem
#343

@ninjinskii
Copy link
Author

As a temporary quick and dirty solution, for anyone else stuck on this problematic, you can use this code to fix the transactions without waiting for the fix to be done:

async doInTransaction(block: () => Promise<void>): Promise<void> {
    // deno-lint-ignore no-explicit-any
    const client = this.db["_connector"]["_client"] as PostgresClient;
    const transaction = client.createTransaction("transaction");
    
    // deno-lint-ignore no-explicit-any
    this.db["_connector"]["_client"] = transaction;
    
    await transaction.begin();
    await block()
    await transaction.commit();

    // deno-lint-ignore no-explicit-any
    this.db["_connector"]["_client"] = client;

    // Waiting for a fix of DenoDB
    //return this.client.transaction(block) as Promise<void>;
  }

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

1 participant