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

Knex.raw() throws an error when returned to a promise #5393

Open
brianlawasdf123 opened this issue Nov 24, 2022 · 0 comments
Open

Knex.raw() throws an error when returned to a promise #5393

brianlawasdf123 opened this issue Nov 24, 2022 · 0 comments

Comments

@brianlawasdf123
Copy link

Environment

Knex version: 2.3.0
Database + version: sqlite3
OS: macos 12.6
Node: v16

Select applicable template from below.

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do

An exception is thrown when calling knex.raw() is returned to a promise. My use case is to fetch data in an async function then use that data to construct a statement for knex.raw(...).

  1. Error message
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: foo - SQLITE_ERROR: near "foo": syntax error] {
  errno: 1,
  code: 'SQLITE_ERROR'
}
  1. Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
    database connection to MySQL or PostgreSQL, then single file example which initializes
    needed data and demonstrates the problem.
const knex = require('knex')({
    client: 'sqlite3',
    connection: {
        filename: "./mydb.sqlite"
    }
});

(async function() {
    await new Promise(resolve => {
        setTimeout(() => {
            resolve(knex.raw('foo'));
        }, 100);
    });

    // or
    await knex.raw('foo');
})();
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