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

Loop of transactions or transactions + promise pool #2113

Open
jackHedaya opened this issue Aug 17, 2021 · 0 comments
Open

Loop of transactions or transactions + promise pool #2113

jackHedaya opened this issue Aug 17, 2021 · 0 comments

Comments

@jackHedaya
Copy link

jackHedaya commented Aug 17, 2021

Introduction

I'm trying to bulk insert to my database that's more complex than a standard query but am having issues with looping through transactions.

Attached SO here

Issue Description

I'm currently looping through all the records I want to insert and generating a transaction for each one. My code looks something like this. The records length is around 30k.

const promises = []

for (const r of json) {
    const p = bookshelf
      .transaction(async (t) => {
        if (r.error && !r.name) throw r.error
        if (r.warning) throw r.warning
       
       <transaction logic that includes fetches and saves>

        customLogger.info(`Saved ${r.name}`)
      })
      .catch((x) => {
        customLogger.error(x)
        throw x
      })

    promises.push(p)
}

Expected behaviour

All the records to save properly and the database pool to properly utilized.

Actual behaviour

The script hangs and I believe throws an error asking if I used transacting right.

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