nalgeon / sqlean

The ultimate set of SQLite extensions
MIT License
3.65k stars 115 forks source link

Problems trying to use loadExtension and 'better-sqlite3' #83

Closed stuartambient closed 1 year ago

stuartambient commented 1 year ago

Keep getting 'SqliteError: The specified module could not be found' Using 'better-sql3' v 8.0.1

Trying to load it from the same directory where I declare the database:

import Database from 'better-sqlite3';
const db = new Database(`myapp/src/db/music.db`);
db.pragma('journal_mode = WAL');
db.pragma('synchronous = normal');
db.pragma('page_size = 32768');
db.pragma('mmap_size = 30000000000');
db.pragma('temp_store = memory');
db.loadExtension('./stats');

export default db;

afaik 'loadExtension' is still part of 'better-sqlite3'. I can get the extension recognized with SQLiteStudio no problem, just not here.

Help appreciated!

asg017 commented 1 year ago

Is the stats.dylib / stats.so / stats.dll file in the same directory where you are running your program?

stuartambient commented 1 year ago

yes, sorry, this is Windows, so stats.dll is in the same directory.

asg017 commented 1 year ago

Is the stats.dll file inside myapp/src/db directory next to your music.db file, by any chance? if so you can try:

db.loadExtension('myapp/src/db/stats');

The path to the extension you provide in loadExtension() is relative to the current working directory (import.meta.url), not to the connected database

stuartambient commented 1 year ago

Thank you, that worked!