dbcube
Version:
120 lines (115 loc) • 3.29 kB
text/typescript
import { Table } from '@dbcube/query-builder';
export { Database, Table } from '@dbcube/query-builder';
/**
* Dbcube ORM - Main class for database management
*
* A lightweight, flexible ORM that supports multiple database engines including
* MySQL, PostgreSQL, SQLite, and MongoDB with a fluent query builder interface.
*
* @example
* ```typescript
* import { Dbcube } from 'dbcube';
*
* const dbcube = new Dbcube();
* await dbcube.init();
*
* // Get a database connection
* const db = dbcube.database('myDatabase');
*
* // Use query builder
* const users = await db.table('users').select().where('active', true).get();
* ```
*
* @class
* @author Albert Araya
* @license MIT
*/
declare class Dbcube {
private static instance;
private configPath;
private config;
private databases;
/**
* Creates a new Dbcube instance (Singleton pattern)
*
* @constructor
* @example
* ```typescript
* const dbcube = new Dbcube();
* ```
*/
constructor();
/**
* Loads configuration from dbcube.config.js file
*
* @private
* @returns {Promise<void>}
* @throws {Error} If config file doesn't exist
*/
loadConfig(): Promise<void>;
/**
* Initializes the Dbcube ORM with database configurations
*
* @param {Object} configCreate - Optional configuration for creating new database
* @param {string} [configCreate.databaseName] - Name of the database to create
* @param {string} [configCreate.motor] - Database engine (mysql, postgres, sqlite, mongodb)
* @param {any} [configCreate.configAnswers] - Additional configuration answers
* @returns {Promise<void>}
*
* @example
* ```typescript
* // Initialize with existing config
* await dbcube.init();
*
* // Initialize with new database creation
* await dbcube.init({
* databaseName: 'myapp',
* motor: 'mysql'
* });
* ```
*/
init(configCreate?: {
databaseName?: string;
motor?: string;
configAnswers?: any;
}): void;
/**
* Gets a database connection instance for query building
*
* @param {string} databaseName - Name of the database configuration
* @returns {Database} Database instance with query builder capabilities
*
* @example
* ```typescript
* // Get database connection
* const db = dbcube.database('myapp');
*
* // Use query builder methods
* const users = await db.table('users')
* .select(['id', 'name', 'email'])
* .where('status', 'active')
* .orderBy('created_at', 'desc')
* .limit(10)
* .get();
*
* // Insert data
* await db.table('users').insert({
* name: 'John Doe',
* email: 'john@example.com'
* });
*
* // Update data
* await db.table('users')
* .where('id', 1)
* .update({ status: 'inactive' });
*
* // Delete data
* await db.table('users').where('id', 1).delete();
* ```
*/
database(databaseName: string): any;
}
declare const dbcube: Dbcube;
type DatabaseRecord = Record<string, any>;
type WhereCallback = (query: Table) => void;
export { type DatabaseRecord, type WhereCallback, dbcube };