- Update .gitignore to exclude database files, extensions, and .cursor directory - Enhance chat streaming API with safe enqueue and close functions to prevent errors - Integrate ConversationSidebar component into ClientHome for better UI - Add dependencies like better-sqlite3 and esbuild packages for database functionality This commit introduces database persistence for conversations, improves error handling in streaming responses, and adds a sidebar for managing chats, enhancing overall app robustness and user experience.
35 lines
798 B
TypeScript
35 lines
798 B
TypeScript
import Database from "better-sqlite3";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
|
|
let db: Database.Database | null = null;
|
|
|
|
export function getDatabase(): Database.Database {
|
|
if (!db) {
|
|
const dbPath = path.join(process.cwd(), "database", "ollahub.db");
|
|
|
|
// Garantir que o diretório existe
|
|
const dbDir = path.dirname(dbPath);
|
|
if (!fs.existsSync(dbDir)) {
|
|
fs.mkdirSync(dbDir, { recursive: true });
|
|
}
|
|
|
|
db = new Database(dbPath);
|
|
|
|
// Configurações de performance
|
|
db.pragma("journal_mode = WAL");
|
|
db.pragma("synchronous = NORMAL");
|
|
db.pragma("foreign_keys = ON");
|
|
db.pragma("cache_size = 10000");
|
|
db.pragma("temp_store = memory");
|
|
}
|
|
return db;
|
|
}
|
|
|
|
export function closeDatabase(): void {
|
|
if (db) {
|
|
db.close();
|
|
db = null;
|
|
}
|
|
}
|