32 lines
772 B
JavaScript
32 lines
772 B
JavaScript
// lib/db.js
|
|
import Database from 'better-sqlite3';
|
|
import path from 'path';
|
|
|
|
const db = new Database(path.join(process.cwd(), 'devbin.db'));
|
|
|
|
// This "Schema" block ensures new users get the database they need automatically
|
|
db.exec(`
|
|
CREATE TABLE IF NOT EXISTS pastes (
|
|
id TEXT PRIMARY KEY,
|
|
content TEXT,
|
|
language TEXT,
|
|
filename TEXT,
|
|
created_at TEXT,
|
|
expires_at TEXT,
|
|
expiry_type TEXT,
|
|
view_count INTEGER DEFAULT 0,
|
|
allow_discussions INTEGER DEFAULT 0,
|
|
delete_token TEXT
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS comments (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
paste_id TEXT,
|
|
author TEXT,
|
|
content TEXT,
|
|
created_at TEXT,
|
|
FOREIGN KEY(paste_id) REFERENCES pastes(id) ON DELETE CASCADE
|
|
);
|
|
`);
|
|
|
|
export default db; |