/** * @athenna/database * * (c) João Lenon * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import type { Knex } from 'knex'; import type { ConnectionOptions } from '#src/types'; import type { FakeDriver } from '#src/database/drivers/FakeDriver'; import { QueryBuilder } from '#src/database/builders/QueryBuilder'; import { Macroable } from '@athenna/common'; import type { MongoDriver } from '#src/database/drivers/MongoDriver'; import type { MySqlDriver } from '#src/database/drivers/MySqlDriver'; import type { SqliteDriver } from '#src/database/drivers/SqliteDriver'; import type { Driver as DriverImpl } from '#src/database/drivers/Driver'; import type { Transaction } from '#src/database/transactions/Transaction'; import type { PostgresDriver } from '#src/database/drivers/PostgresDriver'; export declare class DatabaseImpl extends Macroable { /** * The connection name used for this instance. */ connectionName: string; /** * The drivers responsible for handling database operations. */ driver: Driver; /** * Creates a new instance of DatabaseImpl. */ constructor(athennaDbOpts?: ConnectionOptions); connection(con: 'mongo', options?: ConnectionOptions): DatabaseImpl; connection(con: 'mysql', options?: ConnectionOptions): DatabaseImpl; connection(con: 'sqlite', options?: ConnectionOptions): DatabaseImpl; connection(con: 'postgres', options?: ConnectionOptions): DatabaseImpl; connection(con: 'fake', options?: ConnectionOptions): DatabaseImpl; connection(con: 'mongo' | 'mysql' | 'sqlite' | 'postgres' | 'fake' | string, options?: ConnectionOptions): DatabaseImpl | DatabaseImpl | DatabaseImpl | DatabaseImpl | DatabaseImpl; /** * Verify if database is already connected. */ isConnected(): boolean; /** * Connect to database. */ connect(options?: ConnectionOptions): DatabaseImpl; /** * Close the connection with database in this instance. */ close(): Promise; /** * Close all the connections with all databases. */ closeAll(): Promise; /** * Return the client of driver. */ getClient(): any; /** * Return the query builder of driver. */ getQueryBuilder(): any; /** * Create a new transaction. */ startTransaction(): Promise>; /** * Run database seeders. */ runSeeders(options?: { task?: any; path?: string; classes?: string[]; }): Promise; /** * Run database migrations. */ runMigrations(): Promise; /** * Revert database migrations. */ revertMigrations(): Promise; /** * List all databases available. */ getDatabases(): Promise; /** * Get the current database name. */ getCurrentDatabase(): Promise; /** * Verify if database exists. */ hasDatabase(database: string): Promise; /** * Create a new database. */ createDatabase(database: string): Promise; /** * Drop some database. */ dropDatabase(database: string): Promise; /** * List all tables available. */ getTables(): Promise; /** * Verify if table exists. */ hasTable(table: string): Promise; /** * Create a new table in database. */ createTable(table: string, closure: (builder: Knex.TableBuilder) => void | Promise): Promise; /** * Alter a table in database. */ alterTable(table: string, closure: (builder: Knex.TableBuilder) => void | Promise): Promise; /** * Drop a table in database. */ dropTable(table: string): Promise; /** * Remove all data inside some database table * and restart the identity of the table. */ truncate(table: string): Promise; /** * Make a raw query in database. */ raw(sql: string, bindings?: any): Knex.Raw; /** * Creates a new instance of QueryBuilder for this table. */ table(table: string | any): QueryBuilder; }