@athenna/database
Version:
The Athenna database handler for SQL/NoSQL.
100 lines (99 loc) • 3.3 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 { Operations } from '#src/types';
import { BaseKnexDriver } from '#src/database/drivers/BaseKnexDriver';
import type { ConnectionOptions } from '#src/types/ConnectionOptions';
import { CheckViolationException } from '#src/exceptions/CheckViolationException';
import { UniqueViolationException } from '#src/exceptions/UniqueViolationException';
import { NotNullViolationException } from '#src/exceptions/NotNullViolationException';
import { ForeignKeyViolationException } from '#src/exceptions/ForeignKeyViolationException';
export declare class SqliteDriver extends BaseKnexDriver {
/**
* Connect to database.
*/
connect(options?: ConnectionOptions): void;
/**
* List all databases available.
*/
getDatabases(): Promise<string[]>;
/**
* Create a new database.
*/
createDatabase(database: string): Promise<void>;
/**
* Drop some database.
*/
dropDatabase(database: string): Promise<void>;
/**
* List all tables available.
*/
getTables(): Promise<string[]>;
/**
* Remove all data inside some database table
* and restart the identity of the table.
*/
truncate(table: string): Promise<void>;
/**
* Create many values in database.
*/
createMany<T = any>(data?: Partial<T>[]): Promise<T[]>;
/**
* Find a value in database.
*/
find<T = any>(): Promise<T>;
/**
* Find many values in database.
*/
findMany<T = any>(): Promise<T[]>;
whereJson(column: string, value: any): this;
whereJson(column: string, operation: Operations, value: any): this;
orWhereJson(column: string, value: any): this;
orWhereJson(column: string, operation: Operations, value: any): this;
/**
* Convert a json selector path to sqlite json path.
*/
private parseJsonSelectorToSqlitePath;
/**
* Split a json selector around the wildcard.
*/
private parseJsonSelectorToWildcardParts;
/**
* Convert path parts to a valid json path.
*/
private toJsonPath;
/**
* Normalize operator/value pairs from the whereJson overloads.
*/
private normalizeJsonOperation;
/**
* Normalize json strings returned by sqlite into arrays/objects.
*/
private normalizeRow;
/**
* Parse stringified json objects/arrays returned by sqlite.
*/
private normalizeJsonValue;
/**
* Set a where ILike statement in your query.
*/
whereILike(column: string, value: any): this;
/**
* Set a where ILike statement in your query.
*/
orWhereILike(column: string, value: any): this;
/**
* Translate a SQLite error into a normalized Athenna constraint violation
* exception. SQLite exposes extended result codes (e.g.
* `SQLITE_CONSTRAINT_UNIQUE`) and a message like
* `UNIQUE constraint failed: table.column`.
*
* @see https://www.sqlite.org/rescode.html
*/
parseError(error: any): UniqueViolationException | CheckViolationException | NotNullViolationException | ForeignKeyViolationException;
}