@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
96 lines (95 loc) • 2.54 kB
TypeScript
/**
* @athenna/database
*
* (c) João Lenon <lenon@athenna.io>
*
* 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 { Macroable } from '@athenna/common';
import type { Driver } from '#src/database/drivers/Driver';
import { QueryBuilder } from '#src/database/builders/QueryBuilder';
export declare class Transaction<Client = any, QB = any> extends Macroable {
/**
* The drivers responsible for handling database operations.
*/
driver: Driver<Client, QB>;
/**
* Creates a new instance of transaction.
*/
constructor(driver: Driver);
/**
* Return the client of driver.
*/
getClient(): Client;
/**
* Return the query builder of driver.
*/
getQueryBuilder(): QB;
/**
* Commit the transaction.
*/
commitTransaction(): Promise<void>;
/**
* Rollback the transaction.
*/
rollbackTransaction(): Promise<void>;
/**
* Run database migrations.
*/
runMigrations(): Promise<void>;
/**
* Revert database migrations.
*/
revertMigrations(): Promise<void>;
/**
* List all databases available.
*/
getDatabases(): Promise<string[]>;
/**
* Get the current database name.
*/
getCurrentDatabase(): Promise<string | undefined>;
/**
* Verify if database exists.
*/
hasDatabase(database: string): Promise<boolean>;
/**
* Create a new database.
*/
createDatabase(database: string): Promise<void>;
/**
* Drop some database.
*/
dropDatabase(database: string): Promise<void>;
/**
* List all tables available.
*/
getTables(): Promise<string[]>;
/**
* Verify if table exists.
*/
hasTable(table: string): Promise<boolean>;
/**
* Create a new table in database.
*/
createTable(table: string, closure?: (builder: Knex.TableBuilder) => void | Promise<void>): Promise<void>;
/**
* Drop a table in database.
*/
dropTable(table: string): Promise<void>;
/**
* Remove all data inside some database table
* and restart the identity of the table.
*/
truncate(table: string): Promise<void>;
/**
* Make a raw query in database.
*/
raw<T = any>(sql: string, bindings?: any): Knex.Raw<T>;
/**
* Creates a new instance of QueryBuilder for this table.
*/
table(table: string | any): QueryBuilder;
}