ChemPal Documentation - v1.6.0
    Preparing search index...

    Function getSearchResultsRecord

    • Reads the persisted search_results row as a whole, returning both the product data and the query that produced it. Use this (instead of getSearchResults) when the caller also needs the originating query — e.g. to rehydrate the results header label so it stays in sync with the persisted results.

      Returns Promise<{ data: Product[]; query?: string }>

      The persisted results and query. data is [] and query is undefined when no row exists (or the row predates the query field).

      await getSearchResultsRecord(); // { data: [{ id: "A", ... }], query: "acetone" }
      
      export async function getSearchResultsRecord(): Promise<{ data: Product[]; query?: string }> {
      try {
      const db = await getDB();
      const record = await db.get(IDB_STORE.SEARCH_RESULTS, 'current');
      return { data: record?.data ?? [], query: record?.query };
      } catch (error) {
      logger.error('Failed to get search results record from IndexedDB', { error });
      return { data: [] };
      }
      }