Hi everyone, need some help! I have to sync produc...
# orm-help
g
Hi everyone, need some help! I have to sync product info updates with algolia for which I am trying to write a cron job. This function gets IDs of all products which are not synced that is, freshly created or updated in DB but not in Algolia. CODE:
Copy code
// 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;
};