main: vibe coded app to feel like paper
Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import { Database } from 'bun:sqlite';
|
||||
import path from 'path';
|
||||
import { albums as initialAlbums } from './data';
|
||||
import { Album, Purchase } from './types';
|
||||
@@ -7,9 +7,9 @@ import { Album, Purchase } from './types';
|
||||
const dbPath = path.join(process.cwd(), 'data', 'parsa.db');
|
||||
|
||||
// Initialize database
|
||||
let db: Database.Database;
|
||||
let db: Database;
|
||||
|
||||
export function getDatabase(): Database.Database {
|
||||
export function getDatabase(): Database {
|
||||
if (!db) {
|
||||
// Create data directory if it doesn't exist
|
||||
const fs = require('fs');
|
||||
@@ -18,8 +18,8 @@ export function getDatabase(): Database.Database {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
}
|
||||
|
||||
db = new Database(dbPath);
|
||||
db.pragma('journal_mode = WAL');
|
||||
db = new Database(dbPath, { create: true });
|
||||
db.exec('PRAGMA journal_mode = WAL');
|
||||
initializeDatabase();
|
||||
}
|
||||
return db;
|
||||
@@ -36,6 +36,9 @@ function initializeDatabase() {
|
||||
genre TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
price REAL NOT NULL,
|
||||
tag TEXT NOT NULL DEFAULT 'Album',
|
||||
format TEXT NOT NULL DEFAULT 'mp3',
|
||||
bitrate TEXT NOT NULL DEFAULT '320kbps',
|
||||
songs TEXT NOT NULL,
|
||||
createdAt INTEGER DEFAULT (strftime('%s', 'now')),
|
||||
updatedAt INTEGER DEFAULT (strftime('%s', 'now'))
|
||||
@@ -73,8 +76,8 @@ function initializeDatabase() {
|
||||
|
||||
function seedInitialData() {
|
||||
const insert = db.prepare(`
|
||||
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO albums (id, title, coverImage, year, genre, description, price, tag, format, bitrate, songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
|
||||
const insertMany = db.transaction((albums: Album[]) => {
|
||||
@@ -87,6 +90,9 @@ function seedInitialData() {
|
||||
album.genre,
|
||||
album.description,
|
||||
album.price,
|
||||
album.tag,
|
||||
album.format,
|
||||
album.bitrate,
|
||||
JSON.stringify(album.songs)
|
||||
);
|
||||
}
|
||||
@@ -119,8 +125,8 @@ export const albumDb = {
|
||||
create(album: Album): void {
|
||||
const db = getDatabase();
|
||||
db.prepare(`
|
||||
INSERT INTO albums (id, title, coverImage, year, genre, description, price, songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO albums (id, title, coverImage, year, genre, description, price, tag, format, bitrate, songs)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
album.id,
|
||||
album.title,
|
||||
@@ -129,6 +135,9 @@ export const albumDb = {
|
||||
album.genre,
|
||||
album.description,
|
||||
album.price,
|
||||
album.tag,
|
||||
album.format,
|
||||
album.bitrate,
|
||||
JSON.stringify(album.songs)
|
||||
);
|
||||
},
|
||||
@@ -137,7 +146,7 @@ export const albumDb = {
|
||||
const db = getDatabase();
|
||||
db.prepare(`
|
||||
UPDATE albums
|
||||
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, songs = ?, updatedAt = strftime('%s', 'now')
|
||||
SET title = ?, coverImage = ?, year = ?, genre = ?, description = ?, price = ?, tag = ?, format = ?, bitrate = ?, songs = ?, updatedAt = strftime('%s', 'now')
|
||||
WHERE id = ?
|
||||
`).run(
|
||||
album.title,
|
||||
@@ -146,6 +155,9 @@ export const albumDb = {
|
||||
album.genre,
|
||||
album.description,
|
||||
album.price,
|
||||
album.tag,
|
||||
album.format,
|
||||
album.bitrate,
|
||||
JSON.stringify(album.songs),
|
||||
id
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user