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.
68 lines
1.8 KiB
68 lines
1.8 KiB
import {ErrorWithContext} from '../../util'
|
|
import {QueryResult} from '../types'
|
|
import {SQLDialect} from '../dialect/SQLDialect'
|
|
import {AppClass} from '../../lifecycle/AppClass'
|
|
|
|
/**
|
|
* Error thrown when a connection is used before it is ready.
|
|
* @extends Error
|
|
*/
|
|
export class ConnectionNotReadyError extends ErrorWithContext {
|
|
constructor(name = '', context: {[key: string]: any} = {}) {
|
|
super(`The connection ${name} is not ready and cannot execute queries.`)
|
|
this.context = context
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Abstract base class for database connections.
|
|
* @abstract
|
|
*/
|
|
export abstract class Connection extends AppClass {
|
|
|
|
constructor(
|
|
/**
|
|
* The name of this connection
|
|
* @type string
|
|
*/
|
|
public readonly name: string,
|
|
/**
|
|
* This connection's config object
|
|
*/
|
|
public readonly config: any = {},
|
|
) {
|
|
super()
|
|
}
|
|
|
|
public abstract dialect(): SQLDialect
|
|
|
|
/**
|
|
* Open the connection.
|
|
* @return Promise<void>
|
|
*/
|
|
public abstract init(): Promise<void>
|
|
|
|
/**
|
|
* Execute an SQL query and get the result.
|
|
* @param {string} query
|
|
* @return Promise<QueryResult>
|
|
*/
|
|
public abstract query(query: string): Promise<QueryResult>
|
|
|
|
/**
|
|
* Close the connection.
|
|
* @return Promise<void>
|
|
*/
|
|
public abstract close(): Promise<void>
|
|
|
|
// public abstract databases(): Promise<Collection<Database>>
|
|
|
|
// public abstract database(name: string): Promise<Database | undefined>
|
|
|
|
// public abstract database_as_schema(name: string): Promise<Database>
|
|
|
|
// public abstract tables(database_name: string): Promise<Collection<Table>>
|
|
|
|
// public abstract table(database_name: string, table_name: string): Promise<Table | undefined>
|
|
}
|