The Magical pixi db server
For api doc direct to here
npm install
git submodule init
git submodule update
git submodule foreach git pull origin master
or
cd <module dir>
git pull origin master
for debug:
npm start
for test:
npm run test
for production (forever)
npm run production
add model file at /lib/models/schame>/<name>.js
and add code
var name = 'game'
var props = {
name: String,
desc: String,
icon: String,
auth: Boolean,
scoreType: Number,
js: String
}
var relations = [
{
key: 'users',
ref: 'user'
}
]
module.exports = {
props, relations, name
}
- Add one to many && many to many auto bind
- Delete redundant code
- Optional copy _id to id
- Use custom model key
- Add custom key for query
- Change
npm qiniu
custom to use promise to upload muti files - Add optional mapping relate properties
the db server api doc
http://db.magicalpixi.com/
is for product
http://test.db.magicalpixi.com/
is for test
Get value for key:
path: '/redis/:key' or '/redis'
method: 'get'
params: req.params.key or req.query.key
Set value for key:
path: '/redis/:key' or '/redis'
method: 'post'
params: req.params.key or req.query.key
body: {value: <value>}
Tips:
if not want to display some fields, can use 'dismissFields' as a query key to send a request and the value is string of properties (split by ','), and if only want to display some fields, can use 'dispalyFields' as a query key to send a request and the value is string of properties (split by ',').
Example:
Request GET /pixi/users?dismissFields=id,password,_id,__v
response [
{"username": "aaa",
"email":"aaa@magicpixi.com"},
{"username": "bbb",
"email":"bbb@magicpixi.com"}
]
Get model value with id
/**
* @schame current existed [pixi, api]. pixi is for magicalpixi and api is for common
* @model the model name for example user, game, sprite
*/
path: '/<schame>/<model>/:id'
method: 'get'
params: req.params.id
Get model value with query
/**
* @schame current existed [pixi, api]. pixi is for magicalpixi and api is for common
* @model the model name for example user, game, sprite
* @query must be the model property
*/
path: '/<schame>/<model>'
method: 'get'
query: key=value
Get model all values
/**
* @schame current existed [pixi, api]. pixi is for magicalpixi and api is for common
* @models for example users, games, sprites
* @query must be the model property
*/
path: '/<schame>/<models>'
method: 'get'
query: key=value
Update or save value
path: '/<schame>/<model>'
method: 'post'
body: the model object //if the object has id property, the server will make update operation
Update value with query
/**
* @schame current existed [pixi, api]. pixi is for magicalpixi and api is for common
* @model the model name for example user, game, sprite
* @query must be the model property
*/
path: '/<schame>/<model>'
method: 'post'
query: key=value
body: the model object //if the object has id property, the server will make update operation
Upload single file with muti-part request, example
path: '/upload'
method: 'post'
query: name=<name>
body: muti-part data body with file stream
Upload file content
path: '/upload/content'
method: 'post'
query: name=<name>
body: {content: "<content>"}