@growsari/models

1.0.2 • Public • Published

Models

Models class. Extends from @growsari/dbal.

Usage

Extend class

const {createModelClass} = require('@growsari/models')

module.exports = {
  Model: createModelClass('Model', {properties: {fieldName: { ... }}}
  )
}

Create record

const {Model} = require('../models')
await Model.create(...)
model = new Model(...)
await model.save()

Find and Update record

model = await Model.find('some-uuid-value-for-id')
model.fieldName = 'newFieldValue'
await model.save()
model = await Model.findBy('some-uuid-value-for-id')
model.fieldName = 'newFieldValue'
await model.save()

Note that findBy field name must use a field configured as unique in order to work, i.e.

{properties: { uniqueField: { unique: true }}}

Delete record

model = await Model.find('some-uuid-value-for-id')
await model.destroy()

Errors

Code Message
MODELS-001 Record not found for 'Entity' model
MODELS-002 Validation error
MODELS-003 Not supported
MODELS-004 Model not validated
MODELS-005 Schema not set

Readme

Keywords

none

Package Sidebar

Install

npm i @growsari/models

Weekly Downloads

308

Version

1.0.2

License

ISC

Unpacked Size

14 kB

Total Files

6

Last publish

Collaborators

  • gs.dwight.badua
  • leland.growsari
  • melyo
  • prasad.riktam
  • ddimaano.gs
  • madhugogineni