getCount

Count documents filtered by criteria.

Signature

getCount(session: MySQLSession, props: Partial<IDocument<S>>, join?: 'OR' | 'AND'): Promise<number>;

Example

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

// Executes operations in a single transaction
const transacted = false;
const employeeController = new CRUDMySQL(db, employeeSchema);

await db.usingSession(async (session) => {
  const officeId = '<_id>';

  const data = await this.employeeController.getCount(session, {
    [EmployeeProps.officeId]: officeId,
  });
  return data;
}, transacted);

Last updated