0.1.31 • Published 11 years ago

mannequin v0.1.31

Weekly downloads
2
License
BSD
Repository
github
Last release
11 years ago

mannequin.js

model / schema library for javascript

var mannequin = require("mannequin"),
dictionary = mannequin.dictionary();


dictionary.on("modelBuilder", function(modelBuilder) {
  modelBuilder.pre(["save", "remove"], function(next) {
    this.validate(next);
  });

  modelBuilder.pre("save", function(next) {
    if(this.isNew) {
      //insert
    } else {
      //update
    }
  });

  modelBuilder.pre("remove", function(next) {
    //remove it
    next();
  });

}).virtual("name").get(function() {
  return this.get("name.first") + " " + this.get("name.last");
}).set(function(value) {
  var nameParts = value.split(" ");
  this.set("name.first", nameParts[0]);
  this.set("name.last", nameParts[1]);
})

var LocationModel = dictionary.register("location", {
  name: "string",
  state: "string",
  zip: { $type: "string", $is: /\d{5}/ }
}).getClass();

var PersonModel = dictionary.register("person", {
  name: {
    first: "string",
    last: "string"
  },
  email: { 
    $type: "email",
    $required: true
  },
  location: "location",
  createdAt: {
    $type: "date",
    $default: Date.now
  }
}).getClass();
0.1.31

11 years ago

0.1.30

11 years ago

0.1.28

11 years ago

0.1.27

11 years ago

0.1.26

11 years ago

0.1.25

11 years ago

0.1.24

11 years ago

0.1.23

11 years ago

0.1.22

11 years ago

0.1.21

11 years ago

0.1.20

11 years ago

0.1.19

11 years ago

0.1.18

11 years ago

0.1.17

11 years ago

0.1.16

11 years ago

0.1.15

11 years ago

0.1.14

11 years ago

0.1.13

11 years ago

0.1.12

11 years ago

0.1.11

11 years ago

0.1.10

11 years ago

0.1.8

11 years ago

0.1.7

11 years ago

0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago