diff --git a/modules/database/src/adapters/DatabaseAdapter.ts b/modules/database/src/adapters/DatabaseAdapter.ts index 3af884831..384788e0a 100644 --- a/modules/database/src/adapters/DatabaseAdapter.ts +++ b/modules/database/src/adapters/DatabaseAdapter.ts @@ -134,6 +134,8 @@ export abstract class DatabaseAdapter { getSchema(schemaName: string): ConduitSchema { if (this.models && this.models[schemaName]) { return this.models[schemaName].originalSchema; + } else if (this.views && this.views[schemaName]) { + return this.views[schemaName].originalSchema; } throw new GrpcError(status.NOT_FOUND, `Schema ${schemaName} not defined yet`); } diff --git a/modules/database/src/adapters/mongoose-adapter/index.ts b/modules/database/src/adapters/mongoose-adapter/index.ts index dbd0c469b..3c17b8e4d 100644 --- a/modules/database/src/adapters/mongoose-adapter/index.ts +++ b/modules/database/src/adapters/mongoose-adapter/index.ts @@ -201,6 +201,8 @@ export class MongooseAdapter extends DatabaseAdapter { getSchemaModel(schemaName: string): { model: MongooseSchema } { if (this.models && this.models[schemaName]) { return { model: this.models[schemaName] }; + } else if (this.views && this.views[schemaName]) { + return { model: this.views[schemaName] }; } throw new GrpcError(status.NOT_FOUND, `Schema ${schemaName} not defined yet`); } @@ -321,7 +323,10 @@ export class MongooseAdapter extends DatabaseAdapter { } async execRawQuery(schemaName: string, rawQuery: RawMongoQuery) { - const collection = this.models[schemaName].model.collection; + let collection = this.models[schemaName]?.model.collection; + if (!collection) { + collection = this.views[schemaName]?.model.collection; + } let result; try { const queryOperation = Object.keys(rawQuery).filter(v => { diff --git a/modules/database/src/adapters/sequelize-adapter/index.ts b/modules/database/src/adapters/sequelize-adapter/index.ts index afe729250..4973b19fb 100644 --- a/modules/database/src/adapters/sequelize-adapter/index.ts +++ b/modules/database/src/adapters/sequelize-adapter/index.ts @@ -96,6 +96,7 @@ export abstract class SequelizeAdapter extends DatabaseAdapter }); } } + async guaranteeView(viewName: string) { const view = await this.models['Views'].findOne({ name: viewName, @@ -320,6 +321,8 @@ export abstract class SequelizeAdapter extends DatabaseAdapter getSchemaModel(schemaName: string): { model: SequelizeSchema } { if (this.models && this.models[schemaName]) { return { model: this.models[schemaName] }; + } else if (this.views && this.views[schemaName]) { + return { model: this.views[schemaName] }; } throw new GrpcError(status.NOT_FOUND, `Schema ${schemaName} not defined yet`); }