/**
 * Database connection for SQLite
 */
import Database from 'better-sqlite3';
let db = null;
/**
 * Initialize database connection
 */
export function initializeDatabase(config) {
    if (db) {
        return db;
    }
    db = new Database(config.databasePath, {
        readonly: true, // MCP server only reads data
        fileMustExist: true,
    });
    // Note: Cannot set WAL mode on readonly database
    // WAL mode should be set by the backend (writer)
    return db;
}
/**
 * Get database instance
 */
export function getDatabase() {
    if (!db) {
        throw new Error('Database not initialized. Call initializeDatabase first.');
    }
    return db;
}
/**
 * Close database connection
 */
export function closeDatabase() {
    if (db) {
        db.close();
        db = null;
    }
}
/**
 * Test database connection
 */
export function testConnection() {
    try {
        const result = getDatabase().prepare('SELECT 1').get();
        return true;
    }
    catch (error) {
        console.error('Database connection test failed:', error);
        return false;
    }
}
//# sourceMappingURL=connection.js.map