crud-node
  • ⚡Overview
  • ✨Installation
  • 🧰Schema (soon)
  • ☄️Quick Start
  • Guides
    • 🪄Guides (soon)
  • Adapters
    • 💫Adapters
      • Availability 🆕
      • MySQL
      • MySQLX
      • Mongo (soon)
      • Postgres (soon)
      • Cassandra (soon)
      • Oracle (soon)
      • SqlLite (soon)
      • Couchdb (soon)
  • Reference
    • ⭐API Reference
      • Availability 🆕
      • init
      • toString
      • createDocument
      • createDocumentIfNotExists 🆕
      • deleteDocument
      • deleteAll 🆕
      • updateDocument
      • getDocument
      • getDocuments
      • getDocumentByCriteria 🆕
      • searchDocumentsByCriteria 🆕
      • searchDocuments 🆕
      • groupByDocuments 🆕
      • filterDocumentsByCriteria 🆕
      • filterDocuments 🆕
      • filterDocumentsByIds 🆕
      • fetchAll 🆕
      • findDocument 🆕
      • existsDocument
      • getCount
      • getTotal
      • callStoredProcedure 🆕
  • 📃Changelog
  • 📋Roadmap
Powered by GitBook
On this page
  1. Reference
  2. API Reference

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>>>;
searchDocumentsByCriteria(session: MySQLXSession, 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);
// 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);
PreviousgetDocumentByCriteria 🆕NextsearchDocuments 🆕

Last updated 2 years ago

⭐