You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

import {QueryResult} from './types.ts'
/**
* Error thrown when a connection is used before it is ready.
* @extends Error
*/
export class ConnectionNotReadyError extends Error {
constructor(name = '') {
super(`The connection ${name} is not ready and cannot execute queries.`)
}
}
/**
* Abstract base class for database connections.
* @abstract
*/
export abstract class Connection {
constructor(
/**
* The name of this connection
* @type string
*/
public readonly name: string,
/**
* This connection's config object
*/
public readonly config: any = {},
) {}
/**
* Open the connection.
* @return Promise<void>
*/
public abstract async init(): Promise<void>
/**
* Execute an SQL query and get the result.
* @param {string} query
* @return Promise<QueryResult>
*/
public abstract async query(query: string): Promise<QueryResult> // TODO query result
/**
* Close the connection.
* @return Promise<void>
*/
public abstract async close(): Promise<void>
}