mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 08:54:05 +00:00
Avoid creating a separate base db instance for graph database (#221)
* Avoid creating a separate base db instance for graph database * Fix failing test file build * Use getter method to get base database
This commit is contained in:
@@ -9,7 +9,7 @@ import path from 'path';
|
||||
import assert from 'assert';
|
||||
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
|
||||
import _ from 'lodash';
|
||||
import { getConfig as getWatcherConfig, wait } from '@cerc-io/util';
|
||||
import { getConfig as getWatcherConfig, wait, Database as BaseDatabase } from '@cerc-io/util';
|
||||
import { GraphQLClient } from '@cerc-io/ipld-eth-client';
|
||||
|
||||
import {
|
||||
@@ -123,7 +123,11 @@ export const main = async (): Promise<void> => {
|
||||
const watcherConfigPath = path.resolve(path.dirname(configFile), config.watcher.configPath);
|
||||
const entitiesDir = path.resolve(path.dirname(configFile), config.watcher.entitiesDir);
|
||||
const watcherConfig = await getWatcherConfig(watcherConfigPath);
|
||||
db = new Database(watcherConfig.database, entitiesDir);
|
||||
|
||||
const baseDatabase = new BaseDatabase({ ...watcherConfig.database, entities: [entitiesDir] });
|
||||
await baseDatabase.init();
|
||||
|
||||
db = new Database(baseDatabase);
|
||||
await db.init();
|
||||
|
||||
if (config.watcher.verifyState) {
|
||||
|
||||
@@ -61,7 +61,6 @@ interface CachedEntities {
|
||||
}
|
||||
|
||||
export class Database {
|
||||
_config: ConnectionOptions
|
||||
_conn!: Connection
|
||||
_baseDatabase: BaseDatabase
|
||||
_entityQueryTypeMap: Map<new() => any, ENTITY_QUERY_TYPE>
|
||||
@@ -71,16 +70,8 @@ export class Database {
|
||||
latestPrunedEntities: new Map()
|
||||
}
|
||||
|
||||
constructor (config: ConnectionOptions, entitiesPath: string, entityQueryTypeMap: Map<new() => any, ENTITY_QUERY_TYPE> = new Map()) {
|
||||
assert(config);
|
||||
|
||||
this._config = {
|
||||
name: 'subgraph',
|
||||
...config,
|
||||
entities: [entitiesPath]
|
||||
};
|
||||
|
||||
this._baseDatabase = new BaseDatabase(this._config);
|
||||
constructor (baseDatabase: BaseDatabase, entityQueryTypeMap: Map<new() => any, ENTITY_QUERY_TYPE> = new Map()) {
|
||||
this._baseDatabase = baseDatabase;
|
||||
this._entityQueryTypeMap = entityQueryTypeMap;
|
||||
}
|
||||
|
||||
@@ -89,7 +80,8 @@ export class Database {
|
||||
}
|
||||
|
||||
async init (): Promise<void> {
|
||||
this._conn = await this._baseDatabase.init();
|
||||
this._conn = this._baseDatabase.conn;
|
||||
assert(this._conn);
|
||||
}
|
||||
|
||||
async close (): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user