question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sqlite with protocol in connection string fails

See original GitHub issue

I’m using knex@0.12.9.

I’m using sqlite:///:memory: as a connection string, and that’s the only config I’m passing in.

I expect this to work, but I get the following error:

TypeError: Argument 0 must be a string
    at TypeError (native)
    at /home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/dialects/sqlite3/index.js:99:16
    at Promise._execute (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/promise.js:79:10)
    at Client_SQLite3.acquireRawConnection (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/dialects/sqlite3/index.js:98:12)
    at Object.create (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/client.js:239:16)
    at Pool._createResource (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/generic-pool/lib/generic-pool.js:354:17)
    at Pool.dispense [as _dispense] (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/generic-pool/lib/generic-pool.js:314:10)
    at Pool.acquire (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/generic-pool/lib/generic-pool.js:436:8)
    at /home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/client.js:289:19
    at Promise._execute (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/bluebird/js/release/promise.js:79:10)
    at Client_SQLite3.acquireConnection (/home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/client.js:280:12)
    at /home/dev/source/suchsoftware/event-sourcing-experiments/button-clicks/node_modules/knex/lib/runner.js:208:30

At line 99 of /knex/lib/dialects/sqlite3/index.js (in the transpiled version) it’s trying to use _this.connectionSettings.filename, but having submitted just a connection string for the config, knex/lib/util/parse-connection.js doesn’t set the filename property, so that will be undefined at the time it gets to the dialect. I did a quick, cruddy fix where I just tacked on the filename property, and that resolved the issue. I don’t think that’s the right fix though.

I’m happy to submit a PR for this one, assuming that this is a valid issue.

Edit: Updated the connection string to start the path correctly after discovering that was the problem with #2039. This issue is still there though, even with that fix.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
juanpacocommented, May 3, 2017

yw. Thanks for the work maintaining the library. 😃

I’m happy to make a PR to fix this. I don’t relish long if-else lists, but it seems like an addition to capture sqlite around https://github.com/tgriesser/knex/blob/master/src/util/parse-connection.js#L36 would do the trick?

Are you open to getting a PR on it, and does that seem like an okay approach to the fix?

0reactions
elhigucommented, Jan 7, 2021

I think we should have separate native connection string which is just passed to driver directly and separate knex connection string that is parsed as well as knex can understand it and then parsed data would be passed to driver… I think there is actually some PR / FR about this somewhere… (edit: found it https://github.com/knex/knex/issues/2354)

If current connection: string is already parsed, I think we could just ignore the sqlite:// part.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLite connection strings - ConnectionStrings.com
Normally, GUIDs are stored in a binary format. Use this connection string to store GUIDs as text. Data Source=c:\mydb. db;Version=3;BinaryGUID=False;
Read more >
database protocol 'sqlite' not supported - Failed to initialize ...
I am getting following exception : Failed to start connection pool - database protocol 'sqlite' not supported.
Read more >
SQLite Over a Network, Caveats and Considerations
When the File I/O channel includes a network connection, ... The channel fails only when the system loses power (excepting meteorites, etc.).
Read more >
sqlite3 — DB-API 2.0 interface for SQLite databases — Python ...
Call sqlite3.connect() to to create a connection to the database ... Always use placeholders instead of string formatting to bind Python values to...
Read more >
Understanding connection URI strings in PostgreSQL - Prisma
The item in a connection URI is usually the protocol specification or application type. Since the URI will be used to connect and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found