searchDocumentsByCriteria 🆕

Search documents by SQL `WHERE` statement. Case Insensitive. Makes text search by document. Uses default collation of the database.

Throws `errorNoCriteriaProvided` if props are empty.

Signature

searchDocumentsByCriteria(session: MySQLSession, criteria: string, props: {
        [key: string]: unknown;
    }, pagination?: IOffsetPagination, sort?: Sort): Promise<IPaginatedSet<IDocument<S>>>;

Example

// officeRouter.{ts|js}
import { officeController } from './officeController';
import { OfficeProps } from './schemas/office';

const transacted = true;
const officeId = '<_id>';

await db.usingSession(async (session) => {
  const data = await officeController.searchDocumentsByCriteria(
    session,
    `${officeController.getSearchCriteria(OfficeProps.name, 'keyword1')}
        OR ${officeController.getSearchCriteria(OfficeProps.name, 'keyword2')}
        OR ${officeController.getSearchCriteria(OfficeProps.name, 'keyword3')}`,
    {
      keyword1: '%coworking%',
      keyword2: '%flexible workspace%',
      keyword3: '%serviced office space%',
    },
  );
  return data;
}, transacted);

Last updated