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

fetchAll 🆕

Fetch documents filtered by statement

Throws `errorNoCriteriaProvided` if props are empty.

Signature

fetchAll(session: MySQLSession, sort?: Sort, filter?: {
        props: Partial<IDocument<S>>;
        join: 'OR' | 'AND';
    }, filterCriteria?: FilterCriteria): Promise<Array<IDocument<S>>>;
fetchAll(session: MySQLXSession, sort?: Sort, filter?: {
        props: Partial<IDocument<S>>;
        join: 'OR' | 'AND';
    }): Promise<Array<IDocument<S>>>;

Example

// employeeRouter.{ts|js}
import { OffsetPagination, SortBy } from 'crud-node';
import { employeeController } from './employeeController';
import { EmployeeProps } from './schemas/employee';

const transacted = true;

await db.usingSession(async (session) => {
  const sort = SortBy().asc(EmployeeProps.createdAt).toCriteria();
  const data = await employeeController.fetchAll(session, sort, {
    props: {
      [EmployeeProps.fired]: true,
    },
    join: 'AND',
  });
  return data;
}, transacted);
// employeeRouter.{ts|js}
import { OffsetPagination, SortBy } from 'crud-node';
import { employeeController } from './employeeController';
import { EmployeeProps } from './schemas/employee';

const transacted = true;

await db.usingSession(async (session) => {
  const sort = SortBy().asc(EmployeeProps.createdAt).toCriteria();
  const data = await employeeController.fetchAll(session, sort, {
    props: {
      [EmployeeProps.fired]: true,
    },
    join: 'AND',
  });
  return data;
}, transacted);
PreviousfilterDocumentsByIds 🆕NextfindDocument 🆕

Last updated 2 years ago

⭐