UNPKG

@athenna/database

Version:

The Athenna database handler for SQL/NoSQL.

133 lines (132 loc) 3.1 kB
/** * @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 { Macroable } from '@athenna/common'; import { QueryBuilder } from '#src/database/builders/QueryBuilder'; export class Transaction extends Macroable { /** * Creates a new instance of transaction. */ constructor(driver) { super(); /** * The drivers responsible for handling database operations. */ this.driver = null; this.driver = driver; } /** * Return the client of driver. */ getClient() { return this.driver.getClient(); } /** * Return the query builder of driver. */ getQueryBuilder() { return this.driver.getQueryBuilder(); } /** * Commit the transaction. */ async commitTransaction() { return this.driver.commitTransaction(); } /** * Rollback the transaction. */ async rollbackTransaction() { return this.driver.rollbackTransaction(); } /** * Run database migrations. */ async runMigrations() { await this.driver.runMigrations(); } /** * Revert database migrations. */ async revertMigrations() { await this.driver.revertMigrations(); } /** * List all databases available. */ async getDatabases() { return this.driver.getDatabases(); } /** * Get the current database name. */ async getCurrentDatabase() { return this.driver.getCurrentDatabase(); } /** * Verify if database exists. */ async hasDatabase(database) { return this.driver.hasDatabase(database); } /** * Create a new database. */ async createDatabase(database) { return this.driver.createDatabase(database); } /** * Drop some database. */ async dropDatabase(database) { return this.driver.dropDatabase(database); } /** * List all tables available. */ async getTables() { return this.driver.getTables(); } /** * Verify if table exists. */ async hasTable(table) { return this.driver.hasTable(table); } /** * Create a new table in database. */ async createTable(table, closure) { return this.driver.createTable(table, closure); } /** * Drop a table in database. */ async dropTable(table) { return this.driver.dropTable(table); } /** * Remove all data inside some database table * and restart the identity of the table. */ async truncate(table) { return this.driver.truncate(table); } /** * Make a raw query in database. */ raw(sql, bindings) { return this.driver.raw(sql, bindings); } /** * Creates a new instance of QueryBuilder for this table. */ table(table) { return new QueryBuilder(this.driver, table); } }