Feature: Integrate Discover component with improved capabilities - Added category filters and personalization features - Implemented support for multiple languages and search engines - Added preferences saving - Fixed Chinese language search issue

This commit is contained in:
haddadrm
2025-04-01 16:19:05 +04:00
parent 1e87175b1b
commit 51381827d0
9 changed files with 2075 additions and 101 deletions

View File

@@ -3,9 +3,42 @@ import Database from 'better-sqlite3';
import * as schema from './schema';
import path from 'path';
// Create SQLite connection
const sqlite = new Database(path.join(process.cwd(), 'data/db.sqlite'));
const db = drizzle(sqlite, {
schema: schema,
});
// Initialize database schema
(function initializeDatabase() {
console.log('[DB] Checking database schema...');
try {
// Check if userPreferences table exists
const tableExists = sqlite.prepare(`
SELECT name FROM sqlite_master
WHERE type='table' AND name=?;
`).all('userPreferences').length > 0;
if (!tableExists) {
console.log('[DB] Creating userPreferences table...');
sqlite.prepare(`
CREATE TABLE userPreferences (
id INTEGER PRIMARY KEY,
userId TEXT NOT NULL UNIQUE,
categories TEXT DEFAULT '[]' NOT NULL,
languages TEXT DEFAULT '[]' NOT NULL,
createdAt TEXT NOT NULL,
updatedAt TEXT NOT NULL
);
`).run();
console.log('[DB] userPreferences table created successfully.');
} else {
console.log('[DB] userPreferences table already exists.');
}
} catch (error) {
console.error('[DB] Error during database initialization:', error);
}
})();
export default db;