/** * @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 PaginatedResponse, type PaginationOptions } from '@athenna/common'; import { Driver } from '#src/database/drivers/Driver'; import { ModelSchema } from '#src/models/schemas/ModelSchema'; import { Transaction } from '#src/database/transactions/Transaction'; import type { Connection, Collection, ClientSession } from 'mongoose'; import type { ConnectionOptions, Direction, Operations } from '#src/types'; import { UniqueViolationException } from '#src/exceptions/UniqueViolationException'; export declare class MongoDriver extends Driver { primaryKey: string; session: ClientSession; /** * The where clause used in update queries. */ private _where; /** * The or where clause used in update queries. */ private _orWhere; /** * The aggregate pipeline to make mongo queries. */ private pipeline; /** * Set the mongo session that should be used by the driver. */ setSession(session: ClientSession): this; /** * Connect to database. */ connect(options?: ConnectionOptions): void; /** * Close the connection with database in this instance. */ close(): Promise; /** * Creates a new instance of query builder. */ query(): Collection; /** * Sync a model schema with database. */ sync(schema: ModelSchema): Promise; /** * Create a new transaction. */ startTransaction(): Promise>; /** * Commit the transaction. */ commitTransaction(): Promise; /** * Rollback the transaction. */ rollbackTransaction(): 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(): 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(): Promise; /** * Alter a table in database. */ alterTable(): 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(): T; /** * Calculate the average of a given column. */ avg(column: string): Promise; /** * Calculate the average of a given column using distinct. */ avgDistinct(column: string): Promise; /** * Get the max number of a given column. */ max(column: string): Promise; /** * Get the min number of a given column. */ min(column: string): Promise; /** * Sum all numbers of a given column. */ sum(column: string): Promise; /** * Sum all numbers of a given column in distinct mode. */ sumDistinct(column: string): Promise; /** * Increment a value of a given column. */ increment(column: string): Promise; /** * Decrement a value of a given column. */ decrement(column: string): Promise; /** * Calculate the average of a given column using distinct. */ count(column?: string): Promise; /** * Calculate the average of a given column using distinct. */ countDistinct(column: string): Promise; /** * Find a value in database. */ find(): Promise; /** * Find many values in database. */ findMany(): Promise; /** * Find many values in database and return as paginated response. */ paginate(page?: PaginationOptions | number, limit?: number, resourceUrl?: string): Promise>; /** * Create a value in database. */ create(data?: Partial): Promise; /** * Create many values in database. */ createMany(data?: Partial[]): Promise; /** * Create data or update if already exists. */ createOrUpdate(data?: Partial): Promise; /** * Create a value, doing nothing if a matching document already exists. * Returns the created value, or `null` when it already existed. */ createOrIgnore(data?: Partial): Promise; /** * Find the first document matching the current query or create it. */ createOrFirst(data?: Partial): Promise; /** * Translate a MongoDB duplicate-key error (code 11000) into a normalized * Athenna unique violation exception. */ parseError(error: any): UniqueViolationException; /** * Update a value in database. */ update(data: Partial): Promise; /** * Delete one value in database. */ delete(): Promise; /** * Set the table that this query will be executed. */ table(table: string): this; /** * Log in console the actual query built. */ dump(): this; /** * Set the columns that should be selected on query. */ select(...columns: string[]): this; /** * Set the columns that should be selected on query raw. */ selectRaw(): this; /** * Set the table that should be used on query. * Different from `table()` method, this method * doesn't change the driver table. */ from(): this; /** * Set the table that should be used on query raw. * Different from `table()` method, this method * doesn't change the driver table. */ fromRaw(): this; /** * Set a join statement in your query. */ join(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a left join statement in your query. */ leftJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a right join statement in your query. */ rightJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a cross join statement in your query. */ crossJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a full outer join statement in your query. */ fullOuterJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a left outer join statement in your query. */ leftOuterJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a right outer join statement in your query. */ rightOuterJoin(table: any, column1?: any, operation?: any | Operations, column2?: any): this; /** * Set a join raw statement in your query. */ joinRaw(): this; /** * Set a group by statement in your query. */ groupBy(...columns: string[]): this; /** * Set a group by raw statement in your query. */ groupByRaw(): this; having(column: string): this; having(column: string, value: any): this; having(column: string, operation: Operations, value: any): this; /** * Set a having raw statement in your query. */ havingRaw(): this; /** * Set a having in statement in your query. */ havingIn(column: string, values: any[]): this; /** * Set a having not in statement in your query. */ havingNotIn(column: string, values: any[]): this; /** * Set a having between statement in your query. */ havingBetween(column: string, values: [any, any]): this; /** * Set a having not between statement in your query. */ havingNotBetween(column: string, values: [any, any]): this; /** * Set a having null statement in your query. */ havingNull(column: string): this; /** * Set a having not null statement in your query. */ havingNotNull(column: string): this; orHaving(column: string): this; orHaving(column: string, value: any): this; orHaving(column: string, operation: Operations, value: any): this; /** * Set an or having raw statement in your query. */ orHavingRaw(): this; /** * Set an or having not in statement in your query. */ orHavingNotIn(column: string, values: any[]): this; /** * Set an or having between statement in your query. */ orHavingBetween(column: string, values: [any, any]): this; /** * Set an or having not between statement in your query. */ orHavingNotBetween(column: string, values: [any, any]): this; /** * Set an or having null statement in your query. */ orHavingNull(column: string): this; /** * Set an or having not null statement in your query. */ orHavingNotNull(column: string): this; where(statement: Record): this; where(key: string, value: any): this; where(key: string, operation: Operations, value: any): this; whereNot(statement: Record): this; whereNot(key: string, value: any): this; /** * Set a where raw statement in your query. */ whereRaw(): this; /** * Set a where exists statement in your query. */ whereExists(): this; /** * Set a where not exists statement in your query. */ whereNotExists(): this; /** * Set a where like statement in your query. */ whereLike(column: string, value: any): this; /** * Set a where ILike statement in your query. */ whereILike(column: string, value: any): this; /** * Set a where in statement in your query. */ whereIn(column: string, values: any[]): this; /** * Set a where not in statement in your query. */ whereNotIn(column: string, values: any[]): this; /** * Set a where between statement in your query. */ whereBetween(column: string, values: [any, any]): this; /** * Set a where not between statement in your query. */ whereNotBetween(column: string, values: [any, any]): this; /** * Set a where null statement in your query. */ whereNull(column: string): this; /** * Set a where not null statement in your query. */ whereNotNull(column: string): this; whereJson(column: string, value: any): this; whereJson(column: string, operation: Operations, value: any): this; orWhere(statement: Record): this; orWhere(key: string, value: any): this; orWhere(key: string, operation: Operations, value: any): this; orWhereNot(statement: Record): this; orWhereNot(key: string, value: any): this; orWhereJson(column: string, value: any): this; orWhereJson(column: string, operation: Operations, value: any): this; /** * Set a or where raw statement in your query. */ orWhereRaw(): this; /** * Set an or where exists statement in your query. */ orWhereExists(): this; /** * Set an or where not exists statement in your query. */ orWhereNotExists(): this; /** * Set an or where like statement in your query. */ orWhereLike(column: string, value: any): this; /** * Set an or where ILike statement in your query. */ orWhereILike(column: string, value: any): this; /** * Set an or where in statement in your query. */ orWhereIn(column: string, values: any[]): this; /** * Set an or where not in statement in your query. */ orWhereNotIn(column: string, values: any[]): this; /** * Set an or where between statement in your query. */ orWhereBetween(column: string, values: [any, any]): this; /** * Set an or where not between statement in your query. */ orWhereNotBetween(column: string, values: [any, any]): this; /** * Set an or where null statement in your query. */ orWhereNull(column: string): this; /** * Set an or where not null statement in your query. */ orWhereNotNull(column: string): this; /** * Set an order by statement in your query. */ orderBy(column: string, direction?: Direction): this; /** * Set an order by raw statement in your query. */ orderByRaw(): this; /** * Order the results easily by the latest date. By default, the result will * be ordered by the table's "createdAt" column. */ latest(column?: string): this; /** * Order the results easily by the oldest date. By default, the result will * be ordered by the table's "createdAt" column. */ oldest(column?: string): this; /** * Set the skip number in your query. */ offset(number: number): this; /** * Set the limit number in your query. */ limit(number: number): this; /** * Set the mongo operation in value. */ private setOperator; /** * Convert a json selector path to mongo dot notation. */ private jsonSelectorToDotPath; /** * Creates the where clause with where and orWhere. */ private createWhere; /** * Creates the aggregation pipeline. */ private createPipeline; }