sqlite db initialisation

This commit is contained in:
mahlatseclayton
2026-07-29 21:48:35 +02:00
parent 7915ff5f55
commit 88616446e9
3 changed files with 33 additions and 0 deletions

21
src/lib/db.ts Normal file
View File

@@ -0,0 +1,21 @@
import Database from 'better-sqlite3';
import path from 'path';
const dbPath = path.join(process.cwd(), 'todo.db');
const db = new Database(dbPath);
// initialise the database schema ..
db.exec(
`
CREATE TABLE IF NOT EXISTS tasks(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
due_date TEXT NOT NULL,
topic TEXT NOT NULL,
status TEXT CHECK(status IN ('To-Do','In-Progress','Completed')) NOT NULL DEFAULT 'to-do',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_Archived BOOLEAN NOT NULL DEFAULT 0
)
`
);
export default db;