Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {Collection, ErrorWithContext} from "../../util";
|
||||
import {QueryResult} from "../types";
|
||||
import {SQLDialect} from "../dialect/SQLDialect";
|
||||
import {AppClass} from "../../lifecycle/AppClass";
|
||||
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.
|
||||
@@ -30,7 +30,9 @@ export abstract class Connection extends AppClass {
|
||||
* This connection's config object
|
||||
*/
|
||||
public readonly config: any = {},
|
||||
) { super() }
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
||||
public abstract dialect(): SQLDialect
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {Connection, ConnectionNotReadyError} from "./Connection";
|
||||
import {Client} from "pg";
|
||||
import {Inject} from "../../di";
|
||||
import {QueryResult} from "../types";
|
||||
import {collect} from "../../util";
|
||||
import {SQLDialect} from "../dialect/SQLDialect";
|
||||
import {PostgreSQLDialect} from "../dialect/PostgreSQLDialect";
|
||||
import {Logging} from "../../service/Logging";
|
||||
import {Connection, ConnectionNotReadyError} from './Connection'
|
||||
import {Client} from 'pg'
|
||||
import {Inject} from '../../di'
|
||||
import {QueryResult} from '../types'
|
||||
import {collect} from '../../util'
|
||||
import {SQLDialect} from '../dialect/SQLDialect'
|
||||
import {PostgreSQLDialect} from '../dialect/PostgreSQLDialect'
|
||||
import {Logging} from '../../service/Logging'
|
||||
|
||||
/**
|
||||
* Type interface representing the config for a PostgreSQL connection.
|
||||
@@ -32,13 +32,13 @@ export class PostgresConnection extends Connection {
|
||||
return <PostgreSQLDialect> this.app().make(PostgreSQLDialect)
|
||||
}
|
||||
|
||||
public async init() {
|
||||
public async init(): Promise<void> {
|
||||
this.logging.debug(`Initializing PostgreSQL connection ${this.name}...`)
|
||||
this.client = new Client(this.config)
|
||||
await this.client.connect()
|
||||
}
|
||||
|
||||
public async close() {
|
||||
public async close(): Promise<void> {
|
||||
this.logging.debug(`Closing PostgreSQL connection ${this.name}...`)
|
||||
if ( this.client ) {
|
||||
await this.client.end()
|
||||
@@ -46,8 +46,11 @@ export class PostgresConnection extends Connection {
|
||||
}
|
||||
|
||||
public async query(query: string): Promise<QueryResult> {
|
||||
if ( !this.client ) throw new ConnectionNotReadyError(this.name, { config: JSON.stringify(this.config) })
|
||||
this.logging.verbose(`Executing query in connection ${this.name}: \n${query.split('\n').map(x => ' ' + x).join('\n')}`)
|
||||
if ( !this.client ) {
|
||||
throw new ConnectionNotReadyError(this.name, { config: JSON.stringify(this.config) })
|
||||
}
|
||||
this.logging.verbose(`Executing query in connection ${this.name}: \n${query.split('\n').map(x => ' ' + x)
|
||||
.join('\n')}`)
|
||||
|
||||
try {
|
||||
const result = await this.client.query(query)
|
||||
|
||||
Reference in New Issue
Block a user