admin管理员组

文章数量:1352184

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 ;)

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 ;)

Share Improve this question edited Aug 23, 2021 at 7:28 hellomynameisA asked May 17, 2020 at 19:13 hellomynameisAhellomynameisA 6344 gold badges12 silver badges35 bronze badges 2
  • 1 Typo in verbose: console.log} – Roko C. Buljan Commented Mar 9, 2022 at 11:01
  • Thanks @RokoC.Buljan, I upvoted your ment – hellomynameisA Commented Mar 10, 2022 at 11:14
Add a ment  | 

1 Answer 1

Reset to default 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);

本文标签: javascriptCreate new table using bettersqlite3Stack Overflow