All files / src/database index.js

0% Statements 0/51
0% Branches 0/1
0% Functions 0/1
0% Lines 0/51

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67                                                                                                                                     
/**
 * Database Integration Layer for Coherent.js
 * 
 * @fileoverview Provides database connectivity, query building, and ORM functionality
 * with support for multiple database engines (PostgreSQL, MySQL, SQLite, MongoDB).
 * 
 * @author Coherent.js Team
 * @version 1.0.0
 */
 
export { DatabaseManager } from './connection-manager.js';
export { createQuery, executeQuery, QueryBuilder } from './query-builder.js';
export { createModel, Model } from './model.js';
export { createMigration, Migration } from './migration.js';
export { withDatabase, withTransaction, withModel, withPagination } from './middleware.js';
 
// Database adapters
export { createPostgreSQLAdapter as PostgreSQLAdapter } from './adapters/postgresql.js';
export { createMySQLAdapter as MySQLAdapter } from './adapters/mysql.js';
export { createSQLiteAdapter as SQLiteAdapter } from './adapters/sqlite.js';
export { createMongoDBAdapter as MongoDBAdapter } from './adapters/mongodb.js';
 
// Utilities
export { createConnection, runMigrations } from './utils.js';
 
/**
 * Default database configuration
 */
export const DEFAULT_DB_CONFIG = {
  type: 'sqlite',
  database: ':memory:',
  synchronize: true,
  logging: false,
  entities: [],
  migrations: [],
  subscribers: []
};
 
/**
 * Quick setup function for common database configurations
 * 
 * @param {Object} config - Database configuration
 * @returns {DatabaseManager} Configured database manager
 * 
 * @example
 * import { setupDatabase } from '@coherent/database';
 * 
 * const db = setupDatabase({
 *   type: 'postgresql',
 *   host: 'localhost',
 *   database: 'myapp',
 *   username: 'user',
 *   password: 'pass'
 * });
 */
export function setupDatabase(config = {}) {
  const mergedConfig = { ...DEFAULT_DB_CONFIG, ...config };
  const dbManager = new DatabaseManager(mergedConfig);
  
  // Auto-connect if autoConnect is not explicitly set to false
  if (mergedConfig.autoConnect !== false) {
    dbManager.connect().catch(console.error);
  }
  
  return dbManager;
}