libsql / libsql-node-sqlite3

node-sqlite3 compatible API for libSQL
MIT License
12 stars 1 forks source link

SQLITE_MISUSE when attempting to use with Knex #6

Closed penberg closed 1 year ago

penberg commented 1 year ago

I have the following index.js:

const Knex = require("knex");
const Client_SQLite3 = require("knex/lib/dialects/sqlite3");

class Client_Libsql extends Client_SQLite3 {
    _driver() {
        return require("@libsql/sqlite3");
    }
}

const knex = Knex({
    client: Client_Libsql,
    connection: {
        filename: "file:hello.db",
    },
});

knex.table('users').first().then((data) => {
    console.log(data);
});

and the following package.json:

{
  "name": "knex-testing",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@libsql/sqlite3": "^0.2.1",
    "knex": "^2.4.2",
    "sqlite3": "^5.1.6"
  }
}

fails as follows:

penberg@vonneumann knex-testing % node index.js
sqlite does not support inserting default values. Set the `useNullAsDefault` flag to hide this warning. (see docs https://knexjs.org/guide/query-builder.html#insert).
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: SQLITE_MISUSE: bad parameter or other API misuse] {
  errno: 21,
  code:
glommer commented 1 year ago

We're calling Database() with mode = 0.

Knex is passing 0, which it obviously doesn't for main SQLite. So no idea why

Flagging @honzasp

honzasp commented 1 year ago

Fixed: https://github.com/libsql/libsql-node-sqlite3/commit/baceb05220f219711e5e0d5bb55c8ce130075386 I used for in instead of for of when exporting named constants from the package :(