Fixed and changes
This commit is contained in:
39
lib/db.ts
Normal file
39
lib/db.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { open, Database } from 'sqlite';
|
||||
|
||||
let db: Database | null = null;
|
||||
|
||||
export async function getDb() {
|
||||
if (db) return db;
|
||||
|
||||
// Enable verbose mode for debugging
|
||||
sqlite3.verbose();
|
||||
|
||||
db = await open({
|
||||
filename: './dashboard.db',
|
||||
driver: sqlite3.Database
|
||||
});
|
||||
|
||||
await db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS uptime_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
service_name TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
latency INTEGER,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS visitors (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ip_hash TEXT,
|
||||
city TEXT,
|
||||
country TEXT,
|
||||
lat REAL,
|
||||
lon REAL,
|
||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`);
|
||||
|
||||
return db;
|
||||
}
|
||||
Reference in New Issue
Block a user