Skip to content

Latest commit

 

History

History
19 lines (12 loc) · 937 Bytes

readme.md

File metadata and controls

19 lines (12 loc) · 937 Bytes

Models for Node

Build Status

A lightweight base model object. This is currently storage-agnostic (and may remain that way). It is meant to provide a simple facility for binding a hash-input (as you might receive from an http request) to an object, and providing validation features.

Usage

model = require('node-model')

class User extends model.Model
      @attr 'name', model.types.string
      @attr 'age',  model.types.integer
      @validateLength 'name', {required: true, min: 2, max: 20}, 'please enter a name'
      @validatePresence 'age', 'please enter an age'

You can now create a User directly from a hash input: user = new User(req.query).

You can also call user.validate() which will return true or false. When false is returned, you can access user.errors for a list of errors