Gaurav
04/26/2019, 12:48 PM// To sync with algolia, get products which are newly created or updated in DB only
const getProductIDsToSync = async (): Promise<string[]> => {
// DB call
/**
* [Execute raw SQL query from Prisma to compare columns from same row](<https://github.com/prisma/prisma/issues/3300#issuecomment-440801291>)
* Format: `SELECT * FROM "app-name$app-stage"."Table"`
*/
const query = `
SELECT id FROM "my-service$dev"."Product" WHERE algoliaSyncAt IS NULL OR updatedAt > algoliaSyncAt
`
.replace(/"/g, '\\"')
.replace(/\n/g, " ")
.replace(/\s+/g, " ");
// [Prisma graphql requests](<https://www.prisma.io/docs/prisma-client/basic-data-access/reading-data-TYPESCRIPT-rsc3/#graphql-requests>)
const response = await Prisma.$graphql(`
mutation {
executeRaw(query: "${query}")
}
`);
const productIDs: string[] = response.executeRaw.map(res => res.id);
return productIDs;
};