ngyv / re-modelr

A simple-to-use pure javascript object-relational mapping to manage data.
MIT License
0 stars 0 forks source link

[FEATURE] Model attribute descriptors #16

Closed ngyv closed 6 years ago

ngyv commented 6 years ago

New usage

class User extends BaseModel {
  _attributes() {
    return {
      id: type('number', { required: true}), // see notes below
      name: type('string', { default: 'Siti'}),
    }
  }
}

Side effect

_validateAttributes in base model would always validate regardless of required option passed because type returns an object

The logic for type checking, parsing, and fallback to default value is still not implemented

codecov[bot] commented 6 years ago

Codecov Report

Merging #16 into master will increase coverage by 0.4%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #16     +/-   ##
=========================================
+ Coverage   92.14%   92.55%   +0.4%     
=========================================
  Files           4        5      +1     
  Lines         420      443     +23     
=========================================
+ Hits          387      410     +23     
  Misses         33       33
Impacted Files Coverage Δ
lib/model-descriptors.js 100% <100%> (ø)
lib/index.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3c334e4...1df6534. Read the comment docs.