From 223877e4653fb4a1cdc6836f239c87f3bbe1dd8e Mon Sep 17 00:00:00 2001 From: Peter Vaiciulis Date: Mon, 16 Sep 2024 13:06:52 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20utils=20to=20detect=20Po?= =?UTF-8?q?stgres=20datasource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/index.ts | 2 ++ .../utils/model-datasource-strategy-utils.ts | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/amplify-graphql-transformer-core/src/index.ts b/packages/amplify-graphql-transformer-core/src/index.ts index c01aa322ea..e7284aca32 100644 --- a/packages/amplify-graphql-transformer-core/src/index.ts +++ b/packages/amplify-graphql-transformer-core/src/index.ts @@ -61,6 +61,8 @@ export { isDefaultDynamoDbModelDataSourceStrategy, isDynamoDbModel, isDynamoDbType, + isPostgresModel, + isPostgresDbType, isModelType, isMutationNode, isObjectTypeDefinitionNode, diff --git a/packages/amplify-graphql-transformer-core/src/utils/model-datasource-strategy-utils.ts b/packages/amplify-graphql-transformer-core/src/utils/model-datasource-strategy-utils.ts index 5e460a0b7d..6c8a53f033 100644 --- a/packages/amplify-graphql-transformer-core/src/utils/model-datasource-strategy-utils.ts +++ b/packages/amplify-graphql-transformer-core/src/utils/model-datasource-strategy-utils.ts @@ -141,6 +141,27 @@ export const isSqlModel = (ctx: DataSourceStrategiesProvider, typename: string): return isSqlDbType(modelDataSourceType.dbType); }; +/** + * Checks if the given model is a SQL model + * @param ctx Transformer Context + * @param typename Model name + * @returns boolean + */ +export const isPostgresModel = (ctx: DataSourceStrategiesProvider, typename: string): boolean => { + if (isBuiltInGraphqlType(typename)) { + return false; + } + const modelDataSourceType = getModelDataSourceStrategy(ctx, typename); + return isPostgresDbType(modelDataSourceType.dbType); +}; + +/** + * Type predicate that returns true if `dbType` is a supported SQL database type + */ +export const isPostgresDbType = (dbType: ModelDataSourceStrategyDbType): dbType is ModelDataSourceStrategySqlDbType => { + return dbType === POSTGRES_DB_TYPE; +}; + /** * Type predicate that returns true if `obj` is a SQLLambdaModelDataSourceStrategy */