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

findDocument 🆕

Find documents by props. Case Insensitive. Returns undefined, if document was not found.

Throws `errorNoCriteriaProvided` if props are empty.

Signature

findDocument(session: MySQLSession, props: Partial<IDocument<S>>): Promise<IDocument<S> | undefined>;
findDocument(session: MySQLXSession, props: Partial<IDocument<S>>): Promise<IDocument<S> | undefined>;

Example

// employeeRouter.{ts|js}
import { employeeController } from './employeeController';

const transacted = true;

await db.usingSession(async (session) => {
  const employeeId = '<id>';
  const data = await employeeController.findDocument(session, { employeeId });
  return data;
}, transacted);
// employeeRouter.{ts|js}
import { employeeController } from './employeeController';

const transacted = true;

await db.usingSession(async (session) => {
  const employeeId = '<id>';
  const data = await employeeController.findDocument(session, { employeeId });
  return data;
}, transacted);
PreviousfetchAll 🆕NextexistsDocument

Last updated 2 years ago

⭐