diff options
| author | pack <pack@packgekko.xyz> | 2026-08-12 17:06:50 +0000 |
|---|---|---|
| committer | pack <pack@packgekko.xyz> | 2026-08-12 17:06:50 +0000 |
| commit | 5611527e313c4add16c432e5cf9d55a987558c02 (patch) | |
| tree | 59ad054325096b6305277b94982bbe7f7f585f59 /db.js | |
| parent | d3adc16a08d95d6e331de55d7d3bf05a66a874a8 (diff) | |
| download | crud-5611527e313c4add16c432e5cf9d55a987558c02.tar.gz | |
final commit
Diffstat (limited to '')
| -rw-r--r-- | db.js | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -1,9 +1,21 @@ -const sqlite3 = require('sqlite3').verbose(); -const db = new sqlite3.Database('./app.db'); -db.serialize(() => { - db.run(`CREATE TABLE IF NOT EXISTS users ( - id INTEGER PRIMARY KEY, username TEXT UNIQUE, password TEXT)`); - db.run(`CREATE TABLE IF NOT EXISTS items ( - id INTEGER PRIMARY KEY, user_id INTEGER, title TEXT, content TEXT)`); -}); +const Database = require('better-sqlite3'); +const db = new Database('./crud.db'); + +db.exec(` + CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE NOT NULL, + password TEXT NOT NULL + ); + + CREATE TABLE IF NOT EXISTS tasks ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + title TEXT NOT NULL, + description TEXT, + done INTEGER DEFAULT 0, + FOREIGN KEY (user_id) REFERENCES users(id) + ) +`); + module.exports = db; |