0.0.19 • Published 9 years ago

zero-model v0.0.19

Weekly downloads
73
License
-
Repository
-
Last release
9 years ago

zero-model

This module use waterline to create database connection for relier module.

Usage

  1. Add dependency to your module package.json file like:
{
	"name" : "YOUR_MODULE_NAME",
	"zero" : {
		"dependencies" : {
			"model" : "^0.0.1"
		}
	}
}
  1. Declare models in module.exports like:
module.exports = {
	models : [{
		identity : "user",
		attributes : {
			name : "string",
			age : "int"
		}
	}]
}

See more details about model definition in waterline doc.

  1. Model module listen events of create, update, destroy, find and findOne for every defined model. You can use it as below:
bus.fire('user.findOne',{id:1}).then(function( findResult ){
	// Because there may be other listeners on 'user.findOne', so we have to retrieve result with key "model.findOne.user"
	var foundUser = findResult['model.findOne.user']
})

If you want to use waterline's native method, you can use it through your module's magic attribute dep like:

module.exports = {
	someAction : function(){
		this.dep.model.findOne('user',{id:1}).then(function(user){
			//notice the difference from using `bus.fire`
			var foundUser = user
		})
	}
}
0.0.19

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.1

10 years ago