| 451 | } |
| 452 | |
| 453 | export class PostgresConnection implements AbstractSqlConnection { |
| 454 | public client: Client |
| 455 | public readonly dialect: PostgresSqlDialect |
| 456 | public connected: boolean = false |
| 457 | |
| 458 | constructor( |
| 459 | public readonly host: string, |
| 460 | public readonly port: number, |
| 461 | public readonly username: string, |
| 462 | public readonly password: string, |
| 463 | public readonly database: string |
| 464 | ) { |
| 465 | this.dialect = new PostgresSqlDialect() |
| 466 | } |
| 467 | |
| 468 | getDialect(): AbstractSqlDialect { |
| 469 | return this.dialect |
| 470 | } |
| 471 | |
| 472 | execute(query: ExecutableSqlQuery): Promise<SqlQueryExecuteResult> { |
| 473 | return this.client.query( |
| 474 | query[0], |
| 475 | query.slice(1) |
| 476 | ) |
| 477 | } |
| 478 | |
| 479 | async isConnected(): Promise<boolean> { |
| 480 | return this.connected |
| 481 | } |
| 482 | |
| 483 | connect(): Promise<void> { |
| 484 | this.client = new PgClient({ |
| 485 | host: this.host, |
| 486 | port: this.port, |
| 487 | user: this.username, |
| 488 | password: this.password, |
| 489 | database: this.database, |
| 490 | }) |
| 491 | return this.client.connect().then(() => { |
| 492 | this.connected = true |
| 493 | }) |
| 494 | } |
| 495 | |
| 496 | close(): Promise<void> { |
| 497 | return this.client.end().then(() => { |
| 498 | this.connected = false |
| 499 | }) |
| 500 | } |
| 501 | } |
nothing calls this directly
no outgoing calls
no test coverage detected