feat: initial features

This commit is contained in:
2024-04-13 16:04:32 +07:00
commit e27b047f65
19 changed files with 557 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { Database } from "bun:sqlite";
const dbPath = process.cwd() + "/storage/database.sqlite";
const db = new Database(dbPath);
export const initDb = () => {
db.exec(
`CREATE TABLE IF NOT EXISTS links (
id INTEGER PRIMARY KEY AUTOINCREMENT,
alias TEXT NOT NULL UNIQUE,
url TEXT NOT NULL,
clicks INTEGER DEFAULT 0,
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP
)`
);
};
export default db;
+5
View File
@@ -0,0 +1,5 @@
import crypto from "node:crypto";
export const randomChars = (length = 8) => {
return crypto.randomBytes(length / 2).toString("hex");
};