Files
Mo-Misinformation-Counter/database.js
2026-01-11 00:22:34 +00:00

36 lines
917 B
JavaScript

const Database = require('better-sqlite3');
const path = require('path');
// Use DB_PATH env var or default to counter.db
const dbPath = process.env.DB_PATH || 'counter.db';
const db = new Database(dbPath, { verbose: console.log });
// Initialize database
function init() {
// Table to hold the single global count
db.exec(`
CREATE TABLE IF NOT EXISTS global_count (
id INTEGER PRIMARY KEY CHECK (id = 1),
count INTEGER DEFAULT 0
)
`);
// Ensure the initial row exists
db.exec(`INSERT OR IGNORE INTO global_count (id, count) VALUES (1, 0)`);
// Table to log every click
db.exec(`
CREATE TABLE IF NOT EXISTS logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
quote TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
}
module.exports = {
db,
init
};