import * as promise from "bluebird" ; import { IDatabase , IMain , IOptions } from "pg-promise" ; import pgPromise = require ( "pg-promise" ) ; import { DATABASE_URL } from "./util/secrets" ; import LedgerHeadersRepo from "./repo/ledger_headers" ; import StoreStateRepo from "./repo/store_state" ; import TransactionsRepo from "./repo/transactions" ; interface IExtensions { ledgerHeaders : LedgerHeadersRepo ; transactions : TransactionsRepo ; storeState : StoreStateRepo ; } const initOptions = { promiseLib : promise , extend ( obj ) { obj . ledgerHeaders = new LedgerHeadersRepo ( obj ) ; obj . transactions = new TransactionsRepo ( obj ) ; obj . storeState = new StoreStateRepo ( obj ) ; } } ; const pgp = pgPromise ( initOptions ) ; const db = pgp ( DATABASE_URL ) as IDatabase < IExtensions > & IExtensions & IMain ; import diagnostics = require ( "./util/db/diagnostics" ) ; diagnostics . init ( initOptions ) ; export { db } ;