0

I just want to start off by saying that I have found out Stack questions that are similar if not the same, but the answers there don't work.

I am just wanting to make a smallish database so I can query all of my items in storage. I thought I would try out SQLite because people say that it is easy to use and lightweight.

Here is the question/answer that doesn't work: sqlite3 create database with callback using node and here is the reference from sqlitetutorial.net

Here is my code and the errors I am getting. I don't understand why it is not just creating a new database.

'use strict'

// Open the database in memory
const sqlite3 = require('sqlite3').verbose();

let db = new sqlite3.Database('/db/storage.db', (err) => {
    if (err) {
        console.error(err.message);
    } else {
        console.log('Connected to the in memory SQlite database.')
    }
});


// Close the database
db.close((err) => {
    if (err) {
      return console.error(err.message);
    }
    console.log('Close the database connection.');
});

Then the error message is

SQLITE_CANTOPEN: unable to open database file
Segmentation fault (core dumped)

Or then if I use the sqlite3.OPEN_CREATE parameter, I get this error.

SQLITE_MISUSE: bad parameter or other API misuse
Segmentation fault (core dumped) code here

So I don't entirely know what's wrong here, as it's just my first hour messing around with it but it seems many others have had this issue.

1
  • I'd also like to know why OPEN_CREATE causes an error. Wish this library had more resources to develop it. Commented Aug 16, 2024 at 3:59

1 Answer 1

0

I figured out the issue and it is a really simple one. It was just me not paying attention to directory locations. When declaring the database the dot NEEDS to be there.

let db = new sqlite3.Database('./db/storage.db', (err) => {
    if (err) {
        console.error(err.message);
    } else {
        // do stuff
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.