Skip to content

Commit

Permalink
feat: 🎸 utils to detect Postgres datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
p5quared committed Sep 17, 2024
1 parent 73912bc commit 223877e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/amplify-graphql-transformer-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export {
isDefaultDynamoDbModelDataSourceStrategy,
isDynamoDbModel,
isDynamoDbType,
isPostgresModel,
isPostgresDbType,
isModelType,
isMutationNode,
isObjectTypeDefinitionNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 223877e

Please sign in to comment.