mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-09-18 15:21:33 +00:00
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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user