I'd like to open a database (*.db) creating an other script designed for opening databases, import this file in the route script file as a module and exec.
(db/connection.js):
import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
async function dataBase() {
return open({
filename: './db/test.db',
driver: sqlite3.Database
});
};
export { dataBase };
(routes/example.js):
// database connection
import dataBase from './db/connection.js';
What am I supposed to do? If I try to do such thing like the following way, an error is being thrown:
dataBase.exec("SELECT * FROM test");