@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
486 lines (485 loc) • 14.8 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 { Collection, type PaginatedResponse } from '@athenna/common';
import type { ConnectionOptions, Operations } from '#src/types';
import { Transaction } from '#src/database/transactions/Transaction';
export declare class FakeDriver {
constructor(connection?: string, client?: any);
static primaryKey: string;
static tables: string[];
static databases: string[];
static isConnected: boolean;
static isSavedOnFactory: boolean;
static tableName: string;
static connection: string;
static client: any;
static qb: any;
static useSetQB: boolean;
static joinByType(): typeof FakeDriver;
static getKnex(): void;
static getMongoose(): void;
static clone(): typeof FakeDriver;
static setPrimaryKey(primaryKey: string): typeof FakeDriver;
static getClient(): any;
static setClient(client: any): typeof FakeDriver;
static getQueryBuilder(): any;
static setQueryBuilder(client: any): typeof FakeDriver;
/**
* Connect to database.
*/
static connect(options?: ConnectionOptions): void;
/**
* Close the connection with database in this instance.
*/
static close(): Promise<void>;
/**
* Creates a new instance of query builder.
*/
static query(): {};
/**
* Sync a model schema with database.
*/
static sync(): Promise<void>;
/**
* Create a new transaction.
*/
static startTransaction(): Promise<Transaction>;
/**
* Commit the transaction.
*/
static commitTransaction(): Promise<void>;
/**
* Rollback the transaction.
*/
static rollbackTransaction(): Promise<void>;
/**
* Run database migrations.
*/
static runMigrations(): Promise<void>;
/**
* Revert database migrations.
*/
static revertMigrations(): Promise<void>;
/**
* List all databases available.
*/
static getDatabases(): Promise<string[]>;
/**
* Get the current database name.
*/
static getCurrentDatabase(): Promise<string | undefined>;
/**
* Verify if database exists.
*/
static hasDatabase(database: string): Promise<boolean>;
/**
* Create a new database.
*/
static createDatabase(database: string): Promise<void>;
/**
* Drop some database.
*/
static dropDatabase(database: string): Promise<void>;
/**
* List all tables available.
*/
static getTables(): Promise<string[]>;
/**
* Verify if table exists.
*/
static hasTable(table: string): Promise<boolean>;
/**
* Create a new table in database.
*/
static createTable(table: string): Promise<void>;
/**
* Alter a table in database.
*/
static alterTable(): Promise<void>;
/**
* Drop a table in database.
*/
static dropTable(table: string): Promise<void>;
/**
* Remove all data inside some database table
* and restart the identity of the table.
*/
static truncate(table: string): Promise<void>;
/**
* Make a raw query in database.
*/
static raw(): any;
/**
* Calculate the average of a given column.
*/
static avg(): Promise<number>;
/**
* Calculate the average of a given column using distinct.
*/
static avgDistinct(): Promise<number>;
/**
* Get the max number of a given column.
*/
static max(): Promise<number>;
/**
* Get the min number of a given column.
*/
static min(): Promise<number>;
/**
* Sum all numbers of a given column.
*/
static sum(): Promise<number>;
/**
* Sum all numbers of a given column in distinct mode.
*/
static sumDistinct(): Promise<number>;
/**
* Increment a value of a given column.
*/
static increment(): Promise<void>;
/**
* Decrement a value of a given column.
*/
static decrement(): Promise<void>;
/**
* Calculate the average of a given column using distinct.
*/
static count(): Promise<number>;
/**
* Calculate the average of a given column using distinct.
*/
static countDistinct(): Promise<number>;
/**
* Find value in database but returns only the value of
* selected column directly.
*/
static pluck(): Promise<any>;
/**
* Find many values in database but returns only the
* values of selected column directly.
*/
static pluckMany(): Promise<any>;
/**
* Find a value in database.
*/
static find(): Promise<any>;
/**
* Find a value in database and return as boolean.
*/
static exists(): Promise<boolean>;
/**
* Find a value in database or fail.
*/
static findOrFail(): Promise<any>;
/**
* Find a value in database or create a new one if it doesn't exist.
*/
static findOrCreate(data: Partial<any>): Promise<any>;
/**
* Find a value in database or execute closure.
*/
static findOr(): Promise<any>;
/**
* Executes the given closure when the first argument is true.
*/
static when(criteria: any, closure: (query: typeof FakeDriver, criteriaValue?: any) => void): typeof FakeDriver;
/**
* Find many values in database.
*/
static findMany(): Promise<any[]>;
/**
* Find many values in database and return as a Collection.
*/
static collection(): Promise<Collection<any>>;
/**
* Find many values in database and return as paginated response.
*/
static paginate<T = any>(page?: {
page: number;
limit: number;
resourceUrl: string;
}, limit?: number, resourceUrl?: string): Promise<PaginatedResponse<T>>;
/**
* Create a value in database.
*/
static create<T = any>(data?: Partial<T>): Promise<T>;
/**
* Create many values in database.
*/
static createMany<T = any>(data?: Partial<T>[]): Promise<T[]>;
/**
* Create data or update if already exists.
*/
static createOrUpdate<T = any>(data?: Partial<T>): Promise<T>;
/**
* Update a value in database.
*/
static update<T = any>(data: Partial<T>): Promise<T | T[]>;
/**
* Delete one value in database.
*/
static delete(): Promise<void>;
/**
* Set the table that this query will be executed.
*/
static table(table: string): typeof FakeDriver;
/**
* Log in console the actual query built.
*/
static dump(): typeof FakeDriver;
/**
* Set the columns that should be selected on query.
*/
static select(...columns: string[]): typeof FakeDriver;
/**
* Set the columns that should be selected on query raw.
*/
static selectRaw(): typeof FakeDriver;
/**
* Set the table that should be used on query.
* Different from `table()` method, this method
* doesn't change the driver table.
*/
static from(): typeof FakeDriver;
/**
* Set the table that should be used on query raw.
* Different from `table()` method, this method
* doesn't change the driver table.
*/
static fromRaw(): typeof FakeDriver;
/**
* Set a join statement in your query.
*/
static join(): typeof FakeDriver;
/**
* Set a left join statement in your query.
*/
static leftJoin(): typeof FakeDriver;
/**
* Set a right join statement in your query.
*/
static rightJoin(): typeof FakeDriver;
/**
* Set a cross join statement in your query.
*/
static crossJoin(): typeof FakeDriver;
/**
* Set a full outer join statement in your query.
*/
static fullOuterJoin(): typeof FakeDriver;
/**
* Set a left outer join statement in your query.
*/
static leftOuterJoin(): typeof FakeDriver;
/**
* Set a right outer join statement in your query.
*/
static rightOuterJoin(): typeof FakeDriver;
/**
* Set a join raw statement in your query.
*/
static joinRaw(): typeof FakeDriver;
/**
* Set a group by statement in your query.
*/
static groupBy(): typeof FakeDriver;
/**
* Set a group by raw statement in your query.
*/
static groupByRaw(): typeof FakeDriver;
static having(column: string): typeof FakeDriver;
static having(column: string, value: any): typeof FakeDriver;
static having(column: string, operation: Operations, value: any): typeof FakeDriver;
/**
* Set a having raw statement in your query.
*/
static havingRaw(): typeof FakeDriver;
/**
* Set a having in statement in your query.
*/
static havingIn(): typeof FakeDriver;
/**
* Set a having not in statement in your query.
*/
static havingNotIn(): typeof FakeDriver;
/**
* Set a having between statement in your query.
*/
static havingBetween(): typeof FakeDriver;
/**
* Set a having not between statement in your query.
*/
static havingNotBetween(): typeof FakeDriver;
/**
* Set a having null statement in your query.
*/
static havingNull(): typeof FakeDriver;
/**
* Set a having not null statement in your query.
*/
static havingNotNull(): typeof FakeDriver;
static orHaving(column: string): typeof FakeDriver;
static orHaving(column: string, value: any): typeof FakeDriver;
static orHaving(column: string, operation: Operations, value: any): typeof FakeDriver;
/**
* Set an or having raw statement in your query.
*/
static orHavingRaw(): typeof FakeDriver;
/**
* Set an or having not in statement in your query.
*/
static orHavingNotIn(): typeof FakeDriver;
/**
* Set an or having between statement in your query.
*/
static orHavingBetween(): typeof FakeDriver;
/**
* Set an or having not between statement in your query.
*/
static orHavingNotBetween(): typeof FakeDriver;
/**
* Set an or having null statement in your query.
*/
static orHavingNull(): typeof FakeDriver;
/**
* Set an or having not null statement in your query.
*/
static orHavingNotNull(): typeof FakeDriver;
static where(statement: Record<string, any>): typeof FakeDriver;
static where(key: string, value: any): typeof FakeDriver;
static where(key: string, operation: Operations, value: any): typeof FakeDriver;
static whereNot(statement: Record<string, any>): any;
static whereNot(key: string, value: any): any;
/**
* Set a where raw statement in your query.
*/
static whereRaw(): typeof FakeDriver;
/**
* Set a where exists statement in your query.
*/
static whereExists(): typeof FakeDriver;
/**
* Set a where not exists statement in your query.
*/
static whereNotExists(): typeof FakeDriver;
/**
* Set a where like statement in your query.
*/
static whereLike(): typeof FakeDriver;
/**
* Set a where ILike statement in your query.
*/
static whereILike(): typeof FakeDriver;
/**
* Set a where in statement in your query.
*/
static whereIn(): typeof FakeDriver;
/**
* Set a where not in statement in your query.
*/
static whereNotIn(): typeof FakeDriver;
/**
* Set a where between statement in your query.
*/
static whereBetween(): typeof FakeDriver;
/**
* Set a where not between statement in your query.
*/
static whereNotBetween(): typeof FakeDriver;
/**
* Set a where null statement in your query.
*/
static whereNull(): typeof FakeDriver;
/**
* Set a where not null statement in your query.
*/
static whereNotNull(): typeof FakeDriver;
static whereJson(column: string, value: any): typeof FakeDriver;
static whereJson(column: string, operation: Operations, value: any): typeof FakeDriver;
static orWhere(statement: Record<string, any>): typeof FakeDriver;
static orWhere(key: string, value: any): typeof FakeDriver;
static orWhere(key: string, operation: Operations, value: any): typeof FakeDriver;
static orWhereNot(statement: Record<string, any>): typeof FakeDriver;
static orWhereNot(key: string, value: any): typeof FakeDriver;
/**
* Set a or where raw statement in your query.
*/
static orWhereRaw(): typeof FakeDriver;
/**
* Set an or where exists statement in your query.
*/
static orWhereExists(): typeof FakeDriver;
/**
* Set an or where not exists statement in your query.
*/
static orWhereNotExists(): typeof FakeDriver;
/**
* Set an or where like statement in your query.
*/
static orWhereLike(): typeof FakeDriver;
/**
* Set an or where ILike statement in your query.
*/
static orWhereILike(): typeof FakeDriver;
/**
* Set an or where in statement in your query.
*/
static orWhereIn(): typeof FakeDriver;
/**
* Set an or where not in statement in your query.
*/
static orWhereNotIn(): typeof FakeDriver;
/**
* Set an or where between statement in your query.
*/
static orWhereBetween(): typeof FakeDriver;
/**
* Set an or where not between statement in your query.
*/
static orWhereNotBetween(): typeof FakeDriver;
/**
* Set an or where null statement in your query.
*/
static orWhereNull(): typeof FakeDriver;
/**
* Set an or where not null statement in your query.
*/
static orWhereNotNull(): typeof FakeDriver;
static orWhereJson(column: string, value: any): typeof FakeDriver;
static orWhereJson(column: string, operation: Operations, value: any): typeof FakeDriver;
/**
* Set an order by statement in your query.
*/
static orderBy(): typeof FakeDriver;
/**
* Set an order by raw statement in your query.
*/
static orderByRaw(): typeof FakeDriver;
/**
* Order the results easily by the latest date. By default, the result will
* be ordered by the table's "createdAt" column.
*/
static latest(): typeof FakeDriver;
/**
* Order the results easily by the oldest date. By default, the result will
* be ordered by the table's "createdAt" column.
*/
static oldest(): typeof FakeDriver;
/**
* Set the skip number in your query.
*/
static offset(): typeof FakeDriver;
/**
* Set the limit number in your query.
*/
static limit(): typeof FakeDriver;
static isUsingJsonSelector(): boolean;
static parseJsonSelector(): any;
static parseJsonSelectorToPath(path: string): string;
}