First off, thanks for the great work. I'm loving the library. My issue is that I have a db.js file in the root of my project, and a /data/ folder where I want to generate my sqlite databases.
If I run the following, the file gets created and opened just fine.
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('dev.sqlite');
If I run this though, the file is not created, and an error is logged. If I already have the file in data/dev.sqlite then it works as expected. The file is opened.
It seems like it should be creating the new database, even if a different directory is specified. It does not.
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./data/dev.sqlite');
Error:
events.js:85
throw er; // Unhandled 'error' event
^
Error: SQLITE_CANTOPEN: unable to open database file
at Error (native)
Is there a separate method I'm missing to create a new database? Thanks!
Hmmm, now it's working. Sorry about that. I have no idea what I changed (considering it's only two line).
Ah. The folder must exist! If I delete the data/ folder, the call fails (unable to create/open db). If I create an empty data/ folder, the sqlite file is created and opened.
Hopefully this helps someone in the future!
Yes, Thanks.
OMG Thank you! that was the issue
I'm still getting error with creating sqlite file in different directory using
var db = new sqlite3.Database('../data/database.sqlite', yourCallback);
To fix it, I used these tips :
var db = new sqlite3.Database('C:/Users/You/Desktop/project/src/data/database.sqlite', yourCallback);
Most helpful comment
Ah. The folder must exist! If I delete the
data/folder, the call fails (unable to create/open db). If I create an emptydata/folder, the sqlite file is created and opened.Hopefully this helps someone in the future!