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

Idea: add async-await in a (preliminary) simple way #1398

Closed
SinanGabel opened this issue Nov 14, 2020 · 3 comments
Closed

Idea: add async-await in a (preliminary) simple way #1398

SinanGabel opened this issue Nov 14, 2020 · 3 comments

Comments

@SinanGabel
Copy link

function sqlAll(sql_statement) {
    return new Promise((resolve, reject) => { 
        DB.all(sql_statement, (err, rows) => { return (err) ? reject(err) : resolve(rows); });
    });
}

async myFunction(...) {

  // possibly some .js code

  try {
      const rows = await sqlAll('select * from mytable;');
  catch (err) {
     console.error(err);
  }

  // possibly more .js code
}
@SinanGabel
Copy link
Author

SinanGabel commented Nov 21, 2020

// Parallel execution:
const all_results = await Promise.all([ sqlAll(stmt1), sqlAll(stmt2), sqlAll(stmt3) ]);

// Serial execution:
const result1 = await sqlAll(stmt1); 
const result2 = await sqlAll(stmt2); 
const result3 = await sqlAll(stmt3); 

@wmertens
Copy link
Contributor

See also https://github.com/StratoKit/strato-db/blob/master/src/DB/SQLite.js which provides a Promise API for node-sqlite3

@daniellockyer
Copy link
Member

Closing in favor of #834

@daniellockyer daniellockyer closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants