existsDocument
Checks if exists a document with provided unique props values.
Throws errorNoCriteriaProvided
if props are empty.
Throws errorDuplicatedDocument
if document with provided props already exists.
Signature
existsDocument(session: Knex, props: Partial<IDocument<S>>): Promise<void>;
existsDocument(session: mysqlx.Session, props: Partial<IDocument<S>>): Promise<void>;
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 employeeId = '<_id>';
const data = await employeeController.existsDocument(session, { employeeId });
return data;
}, transacted);
// employeeRouter.{ts|js}
import { CRUDMySQLX, SortBy, OffsetPagination } from 'crud-node';
import { employeeSchema, EmployeeProps } from './schemas/employee';
// Executes operations in a single transaction
const transacted = false;
const employeeController = new CRUDMySQLX(db, employeeSchema);
await db.usingSession(async (session) => {
const employeeId = '<_id>';
const data = await employeeController.existsDocument(session, { employeeId });
return data;
}, transacted);
Last updated