All files / server database-utils.ts

100% Statements 8/8
100% Branches 5/5
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                    244x   207x   13x   15x   7x   2x                 2x                 11x  
/**
 * Database Adapter Factory
 * Creates appropriate database adapters based on engine type
 * Provides centralized adapter management and instantiation
 */
 
import type { DatabaseAdapter } from './adapters/base-adapter'
import { PostgresAdapter } from './adapters/postgres-adapter'
import { MySQLAdapter } from './adapters/mysql-adapter'
import { SQLiteAdapter } from './adapters/sqlite-adapter'
import { SingleStoreAdapter } from './adapters/singlestore-adapter'
 
/**
 * Create a database adapter for the specified engine type
 * @param engineType - The database engine type
 * @returns Database adapter instance
 */
export function createDatabaseAdapter(engineType: 'postgres' | 'mysql' | 'sqlite' | 'singlestore'): DatabaseAdapter {
  switch (engineType) {
    case 'postgres':
      return new PostgresAdapter()
    case 'mysql':
      return new MySQLAdapter()
    case 'sqlite':
      return new SQLiteAdapter()
    case 'singlestore':
      return new SingleStoreAdapter()
    default:
      throw new Error(`Unsupported database engine: ${engineType}`)
  }
}
 
/**
 * Get available database adapters
 * @returns Array of supported engine types
 */
export function getSupportedEngines(): ('postgres' | 'mysql' | 'sqlite' | 'singlestore')[] {
  return ['postgres', 'mysql', 'sqlite', 'singlestore']
}
 
/**
 * Check if an engine type is supported
 * @param engineType - Engine type to check
 * @returns True if supported, false otherwise
 */
export function isEngineSupported(engineType: string): engineType is 'postgres' | 'mysql' | 'sqlite' | 'singlestore' {
  return ['postgres', 'mysql', 'sqlite', 'singlestore'].includes(engineType)
}