discordjs / Commando

Official command framework for discord.js
Apache License 2.0
496 stars 242 forks source link

Update sqlite dependency and first steps doc to v4 (Error: sqlite: filename is not defined) #302

Closed thomasthebro1 closed 3 years ago

thomasthebro1 commented 4 years ago

Hi there, I am using Node Version 13.12.0. When trying to setup a SQLite Provider using client.setProvider() I get the following error: Error: sqlite: filename is not defined

I believe this might be because of an update which sqlite has done to their module. Any help will be greatly appreciated as this is currently greatly affecting my bot settings.

My code is:


client.setProvider(
    sqlite.open(path.join(__dirname, 'settings.sqlite3')).then(db => new SQLiteProvider(db))
).catch(console.error);
duncannah commented 4 years ago

Temporary fix is to downgrade sqlite:

yarn install sqlite@^3.0.0
thomasthebro1 commented 4 years ago

Temporary fix is to downgrade sqlite:

yarn install sqlite@^3.0.0

Already done this for now, thanks for the advice though!

Worreh commented 4 years ago

The following works for me with sqlite@^4.0.5

client.setProvider(
    sqlite.open( { filename: path.join(__dirname, "settings.sqlite3") } ).then( db => new Commando.SQLiteProvider(db) )
).catch(console.error);

Seems like newer SQLite versions no longer accepts plain string paths and now requires the usage of a config object even if only thing you'd define is the filename/path.

thomasthebro1 commented 4 years ago

Ok thats great. I will give it a go later.

Jiralite commented 4 years ago

Seems like newer SQLite versions no longer accepts plain string paths and now requires the usage of a config object even if only thing you'd define is the filename/path.

Yes, it does appear so. In their change log for version 4, there is a breaking change:

Opening a new database has changed. See README.md for example.

In the README.md, the parameters passed to .open() are an object as opposed to the reproducible code provided.

When you update to a new major version, it's advised to read through their change log before updating as there may be breaking changes.

kingmaj0r commented 4 years ago

can i plz have help i keep getting Error: sqlite: filename is not defined

Gawdl3y commented 4 years ago

Commando only lists sqlite v3 as a dependency, so if you are installing v4, that's technically incorrect. It does work with v4, you just need to pass the correct parameters to sqlite due to that breaking change.

BenWithJamInn commented 4 years ago

If the above isn't working for you (it may not be working for me due to my version of Linux) try the solution below using better-sqlite

Firstly install better-sqlite3 using npm npm i better-sqlite3 (this may take one or two minutes to install) Then simply copy and paste this code into your project (index.js):

const database = require('better-sqlite3')
const db = new database('settings.db')

client.setProvider(
    new commando.SyncSQLiteProvider(db)
)

In the documentation, if you go to SyncSqliteProvider it doesn't say it specifically but it is for better-sqlite3 as that executes synchronously or something like that. i should request that the documentation is a bit clearer as I was getting pretty confused.