@venncity/base-dao
TypeScript icon, indicating that this package has built-in type declarations

2.5.4 • Public • Published

Base DAO

Coverage

Base DAO exports a createEntityDAO function which creates a DAO with the following capabilities:

  • a set of CRUD operations, implemented using sequelize
  • authorization capabilities, using a daoAuth interface implemented by the consumer of the package
  • CRUD mutations notifications (e.g. can be used for auditing)
  • declarative cascade-delete mechanism
  • hooks mechanism, e.g. preSave, preDelete, postFetch, etc.

Quick start

Generate DAO classes using the following command:

$ generate-dao-schema --dataModelPath PATH_TO_YOUR_DATA_MODEL --generatedFolderPath PATH_TO_YOUR_GENERATED_FOLDER
  • dataModelPath is not required and the default value is src/schema/datamodel.graphql
  • generatedFolderPath is not required and the default value is src/schema/generated

Add the following scripts to your package.json:

"scripts": {
  "prebuild: "yarn generate-dao-schema",
  "prestart": "yarn generate-dao-schema",
  "generate-dao-schema": "generate-dao-schema"
}

Example of usage (assume that Survey entity exists)

import { SurveyDAO } from '../../generated';

const surveyDAO = new SurveyDAO({
    hooks,
    daoAuth, 
    publishCrudEvent
});
...
const createdSurvey = await surveyDAO.createSurvey(...);

Readme

Keywords

none

Package Sidebar

Install

npm i @venncity/base-dao

Weekly Downloads

172

Version

2.5.4

License

none

Unpacked Size

584 kB

Total Files

77

Last publish

Collaborators

  • venncity-admin