UNPKG

@fastmcp-me/mcp-sqlew

Version:

MCP server for efficient context sharing between Claude Code sub-agents with 96% token reduction via action-based tools

135 lines 4.07 kB
/** * Database connection and initialization module * Handles SQLite database setup with configurable path */ import type { Database as DatabaseType } from './types.js'; /** * Initialize database connection * Creates database file and folder if they don't exist * Initializes schema on first run * * @param dbPath - Optional database path (defaults to .sqlew/sqlew.db) * @returns SQLite database instance */ export declare function initializeDatabase(dbPath?: string): DatabaseType; /** * Close database connection */ export declare function closeDatabase(): void; /** * Get current database instance * Throws error if not initialized * * @returns Current database instance */ export declare function getDatabase(): DatabaseType; /** * Get or create agent by name * Uses INSERT OR IGNORE for idempotent operation * * @param db - Database instance * @param name - Agent name * @returns Agent ID */ export declare function getOrCreateAgent(db: DatabaseType, name: string): number; /** * Get or create context key by name * * @param db - Database instance * @param key - Context key name * @returns Context key ID */ export declare function getOrCreateContextKey(db: DatabaseType, key: string): number; /** * Get or create file by path * * @param db - Database instance * @param path - File path * @returns File ID */ export declare function getOrCreateFile(db: DatabaseType, path: string): number; /** * Get or create tag by name * * @param db - Database instance * @param name - Tag name * @returns Tag ID */ export declare function getOrCreateTag(db: DatabaseType, name: string): number; /** * Get or create scope by name * * @param db - Database instance * @param name - Scope name * @returns Scope ID */ export declare function getOrCreateScope(db: DatabaseType, name: string): number; /** * Get layer ID by name * Does not auto-create (layers are predefined) * * @param db - Database instance * @param name - Layer name * @returns Layer ID or null if not found */ export declare function getLayerId(db: DatabaseType, name: string): number | null; /** * Get constraint category ID by name * Does not auto-create (categories are predefined) * * @param db - Database instance * @param name - Category name * @returns Category ID or null if not found */ export declare function getCategoryId(db: DatabaseType, name: string): number | null; /** * Get configuration value from m_config table * * @param db - Database instance * @param key - Config key * @returns Config value as string or null if not found */ export declare function getConfigValue(db: DatabaseType, key: string): string | null; /** * Set configuration value in m_config table * * @param db - Database instance * @param key - Config key * @param value - Config value (will be converted to string) */ export declare function setConfigValue(db: DatabaseType, key: string, value: string | number | boolean): void; /** * Get configuration value as boolean * * @param db - Database instance * @param key - Config key * @param defaultValue - Default value if key not found * @returns Boolean value */ export declare function getConfigBool(db: DatabaseType, key: string, defaultValue?: boolean): boolean; /** * Get configuration value as integer * * @param db - Database instance * @param key - Config key * @param defaultValue - Default value if key not found * @returns Integer value */ export declare function getConfigInt(db: DatabaseType, key: string, defaultValue?: number): number; /** * Get all configuration as an object * * @param db - Database instance * @returns Object with all m_config key-value pairs */ export declare function getAllConfig(db: DatabaseType): Record<string, string>; /** * Execute a function within a transaction * Automatically handles commit/rollback * * @param db - Database instance * @param fn - Function to execute in transaction * @returns Result from function */ export declare function transaction<T>(db: DatabaseType, fn: () => T): T; //# sourceMappingURL=database.d.ts.map