87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
/**
|
|
* DatabaseProvider - Platform-aware database selection
|
|
*
|
|
* Automatically selects best backend:
|
|
* - Linux/macOS: better-sqlite3 (native, fast)
|
|
* - Windows: sql.js (WASM, universal) when native fails
|
|
* - Fallback: JSON file storage
|
|
*
|
|
* @module v3/memory/database-provider
|
|
*/
|
|
import { IMemoryBackend } from './types.js';
|
|
/**
|
|
* Available database provider types
|
|
*/
|
|
export type DatabaseProvider = 'better-sqlite3' | 'sql.js' | 'json' | 'rvf' | 'auto';
|
|
/**
|
|
* Database creation options
|
|
*/
|
|
export interface DatabaseOptions {
|
|
/** Preferred provider (auto = platform-aware selection) */
|
|
provider?: DatabaseProvider;
|
|
/** Enable verbose logging */
|
|
verbose?: boolean;
|
|
/** Enable WAL mode (better-sqlite3 only) */
|
|
walMode?: boolean;
|
|
/** Enable query optimization */
|
|
optimize?: boolean;
|
|
/** Default namespace */
|
|
defaultNamespace?: string;
|
|
/** Maximum entries before auto-cleanup */
|
|
maxEntries?: number;
|
|
/** Auto-persist interval for sql.js (milliseconds) */
|
|
autoPersistInterval?: number;
|
|
/** Path to sql.js WASM file */
|
|
wasmPath?: string;
|
|
}
|
|
/**
|
|
* Platform detection result
|
|
*/
|
|
interface PlatformInfo {
|
|
os: string;
|
|
isWindows: boolean;
|
|
isMacOS: boolean;
|
|
isLinux: boolean;
|
|
recommendedProvider: DatabaseProvider;
|
|
}
|
|
/**
|
|
* Create a database instance with platform-aware provider selection
|
|
*
|
|
* @param path - Database file path (:memory: for in-memory)
|
|
* @param options - Database configuration options
|
|
* @returns Initialized database backend
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* // Auto-select best provider for platform
|
|
* const db = await createDatabase('./data/memory.db');
|
|
*
|
|
* // Force specific provider
|
|
* const db = await createDatabase('./data/memory.db', {
|
|
* provider: 'sql.js'
|
|
* });
|
|
*
|
|
* // With custom options
|
|
* const db = await createDatabase('./data/memory.db', {
|
|
* verbose: true,
|
|
* optimize: true,
|
|
* autoPersistInterval: 10000
|
|
* });
|
|
* ```
|
|
*/
|
|
export declare function createDatabase(path: string, options?: DatabaseOptions): Promise<IMemoryBackend>;
|
|
/**
|
|
* Get platform information
|
|
*/
|
|
export declare function getPlatformInfo(): PlatformInfo;
|
|
/**
|
|
* Check which providers are available
|
|
*/
|
|
export declare function getAvailableProviders(): Promise<{
|
|
rvf: boolean;
|
|
betterSqlite3: boolean;
|
|
sqlJs: boolean;
|
|
json: boolean;
|
|
}>;
|
|
export {};
|
|
//# sourceMappingURL=database-provider.d.ts.map
|