UNPKG

@knorm/knorm

Version:

A JavaScript ORM written using ES6 classes

56 lines (55 loc) 1.98 kB
/** * Defines how to connect to the database and run queries e.g. via plugins. */ export class Connection { /** * Called by {@link Query#connect} and {@link Transaction#connect} to connect * to the database (or acquire clients from a connection pool). * * @throws {ConnectionError} If the method is not implemented. */ create(): void; /** * Called by {@link Query#execute}, {@link Transaction#_begin}, * {@link Transaction#_commit} and {@link Transaction#_rollback} to execute a * query with the connection created by {@link Connection#create}. * * @param {string|object} sql The SQL to query. * @param {string} sql.text The parameterized SQL string (with placeholders), * when `sql` is passed as an object. * @param {array} sql.values The values for the parameterized SQL string, when * `sql` is passed as an object. * * @throws {ConnectionError} If the method is not implemented. */ query(): void; /** * Called by {@link Query#disconnect} and {@link Transaction#disconnect} to * close the connection created by {@link Connection#create}. * * @param {QueryError} [error] If {@link Query#disconnect} was called with an * error, that error is passed as this param. That error will have usually * originated from {@link Query#query}. * * @throws {ConnectionError} If the method is not implemented. */ close(): void; /** * A reference to the {@link Knorm} instance. * * ::: tip * This is the same instance assigned to the {@link Connection.knorm} static * property, just added as a convenience for use in instance methods. * ::: */ knorm: any; } export namespace Connection { export { ConnectionError }; export const knorm: any; } declare class ConnectionError extends KnormError { constructor(...args: any[]); } import { KnormError } from "./KnormError"; export {};