Create new table using better-sqlite3
Asked Answered
G

1

5

I am trying to create a new table using node.js and better-sqlite3. When I execute the file, it returns the following error:

ReferenceError: createtable is not defined at Object.<anonymous> (...my file's path...)

How can I solve it? Here's my code:

const express = require('express');
var createError = require('http-errors');
const app = express();
const port = 3000;
const sqlitedb = require('better-sqlite3');

const createTable = "CREATE TABLE IF NOT EXISTS users('name' varchar, 'surname' varchar, 'date_of_birth' DATE DEFAULT, 'email' varchar, 'username' varchar PRIMARY KEY, 'password' varchar );"

const dbusers = './databaseUsers.sqlite3';
let db = new sqlitedb(dbusers , sqlitedb.OPEN_READWRITE, (err) => {
    if (err) {
        console.error(err.message);
    }
    verbose: console.log}
);

db.exec(createtable);

Thank you in advance ;)

Goldcrest answered 17/5, 2020 at 19:13 Comment(2)
Typo in verbose: console.log}Spokeshave
Thanks @RokoC.Buljan, I upvoted your commentGoldcrest
R
7

You have a typo in the variable declaration. The variable you declared is createTable instead of createtable (note the capitalized T). So it should be:

db.exec(createTable);
Renege answered 17/5, 2020 at 21:30 Comment(1)
Whoops. Thank you very much! Do you also have any advice about how to continue from that point on?Goldcrest

© 2022 - 2024 — McMap. All rights reserved.