32 lines
792 B
JavaScript
32 lines
792 B
JavaScript
const Database = require('better-sqlite3');
|
|
const db = new Database('counter.db', { 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
|
|
};
|