microlinkhq / keyvhq

Simple key-value storage with support for multiple backends.

Home Page:https://keyvhq.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation for KeyvSqlite shows invalid constructor arguments

pricecomstock opened this issue · comments

The README on this page shows that you can instantiate KeyvSqlite like this:

const KeyvSqlite = require('@keyvhq/sqlite')
const Keyv = require('@keyvhq/core')

const keyv = new Keyv({ 
  store: new KeyvSqlite('sqlite://path/to/database.sqlite', {
    table: 'cache',
    busyTimeout: 10000
  })
})

I was not getting persistence doing this. After digging, I realized it was silently failing and using an in memory database, because the constructor looks like this:

class KeyvSqlite extends KeyvSql {
  constructor (options) {
    options = Object.assign(
      {
        dialect: 'sqlite',
        uri: 'sqlite://:memory:'
      },
      options
    )
    options.db = options.uri.replace(/^sqlite:\/\//, '')

// more stuff here that I cut out
}

The constructor only takes the options object, so you actually need to instantiate it like this:

new Keyv({
  store: new KeyvSqlite({
    uri: "sqlite://data.db"
  })
})

ops, sorry for that. Can you make a PR to clarify how to use it? 🙂

@Kikobeats yeah I could do a PR.

Would you rather have
A. the documentation updated to show the correct way to do this
B. (breaking) changes to the sqlite constructor to make it consistent with the others?

edit: looked at some of the other plugins and sqlite isn't the only odd one out, so I'm leaning documentation update probably.

e.g. Redis is instantiated with (uri, options) and Postgres is instantiated with (options)