deleteDocument
Delete a document.
Throws errorNothingWasDeleted
if document with specified id was not deleted, because document does not exist.
Signature
deleteDocument(session: Knex, id: string): Promise<string>;
deleteDocument(session: mysqlx.Session, id: string): Promise<string>;
Example
// employeeRouter.{ts|js}
import { employeeController } from './employeeController';
import { CRUDMySQL } from 'crud-node';
import { employeeSchema } from './schemas/employee';
// Executes operations in a single transaction
const transacted = true;
const employeeController = new CRUDMySQL(db, employeeSchema);
await db.usingSession(async (session) => {
const employeeId = '<_id>';
const data = await employeeController.deleteDocument(session, employeeId);
return data;
}, transacted);
// employeeRouter.{ts|js}
import { employeeController } from './employeeController';
import { CRUDMySQLX } from 'crud-node';
import { employeeSchema } from './schemas/employee';
// Executes operations in a single transaction
const transacted = true;
const employeeController = new CRUDMySQLX(db, employeeSchema);
await db.usingSession(async (session) => {
const employeeId = '<_id>';
const data = await employeeController.deleteDocument(session, employeeId);
return data;
}, transacted);
Last updated