nanoid
所属分类:GPT/ChatGPT
开发工具:JavaScript
文件大小:0KB
下载次数:0
上传日期:2014-01-23 05:27:16
上 传 者:
sh-1993
说明: 基于nano的couchdb小型对象文档映射器
(A mini object document mapper for couchdb based on nano)
文件列表:
.travis.yml (65, 2014-01-22)
LICENSE (1078, 2014-01-22)
Makefile (421, 2014-01-22)
docs/ (0, 2014-01-22)
docs/crud.md (1968, 2014-01-22)
docs/define.md (2802, 2014-01-22)
docs/embedded.md (1019, 2014-01-22)
docs/installation.md (1575, 2014-01-22)
docs/validations.md (807, 2014-01-22)
docs/viewqueries.md (2543, 2014-01-22)
examples/ (0, 2014-01-22)
examples/blog.js (862, 2014-01-22)
examples/user.js (674, 2014-01-22)
lib/ (0, 2014-01-22)
lib/base.js (2123, 2014-01-22)
lib/chainview.js (1314, 2014-01-22)
lib/connection.js (732, 2014-01-22)
lib/document.js (1539, 2014-01-22)
lib/index.js (171, 2014-01-22)
lib/logger.js (391, 2014-01-22)
lib/model.js (6061, 2014-01-22)
lib/query.js (2248, 2014-01-22)
lib/validate.js (894, 2014-01-22)
package.json (690, 2014-01-22)
specs/ (0, 2014-01-22)
specs/chainable_views_spec.js (2179, 2014-01-22)
specs/create_callback_spec.js (1705, 2014-01-22)
specs/custom_functions_spec.js (1536, 2014-01-22)
specs/custom_views_spec.js (1590, 2014-01-22)
specs/find_all_spec.js (1172, 2014-01-22)
specs/find_by_id_spec.js (1384, 2014-01-22)
specs/find_by_property_spec.js (2675, 2014-01-22)
specs/load_referenced_docs_spec.js (932, 2014-01-22)
specs/modeling_spec.js (3557, 2014-01-22)
specs/multiple_docs_emdedded_spec.js (2394, 2014-01-22)
specs/remove_spec.js (2206, 2014-01-22)
specs/save_callbacks_spec.js (1376, 2014-01-22)
specs/save_item_spec.js (2660, 2014-01-22)
... ...
Nanoid Object Modeller
=======================
## Don't panic!
Nanoid makes it easier to build applications with Couchdb. It removes the repeatable cruft and makes working with Couchdb as fun as it should be.
# 4 easy steps to installation
1) Download
npm install nanoid
2) Connect to database
var Model = require('nanoid')
Model.create_connection("my_database");
3) Define a model
Model.define('User', {
name: String
surname: {type: String, default: "Rambo"}
})
## Defining a model
var Model = require('nanoid');
Model.define('User', {
name: String
surname: {type: String, default: "Rambo"}
})
## Creating and saving a model
var user = Model.create('User', {name: "John", surname: "Rambo"});
user.save(function (err, saved_user) {
// .. do some other stuff here
})
## Finding a model
### Finding by Id
var user_id = "123456";
var User = Model('User');
User.find(user_id, function (err, user) {
// .. do something with the user
})
### Find all or by criteria
var User = Model('User');
User.all(function (err, users) {
// .. do something with the user
})
var User = Model('User');
User.where("name","Ben", function (err, users) {
// .. do something with the users
})
### Find first by criteria
var User = Model('User');
User.findFirst('name', 'Ben', function (err, user){
// .. do something with the user
})
## Custom View
var Band = Model.define("Band",{rank: Number, name: String});
Band.addView('ByRankAndName',{
map: function (doc) {
if (doc.model_type === 'Band') {
emit([doc.rank, doc.name],1);
}
}
});
Band.view('ByRankAndName')
.startkey([2, "Incubus"])
.endkey([3, {}])
.limit(10)
.skip(3, function (err, bands) {
// will only execute the chain when a function has a callback passed to it
});
## Logging
Logging has been disabled for now.
#What needs doing?
* Define model_type field stored in db
* Multiple db support
* Improved logging
#Changelog
* 25 Aug 2013 - Add First Implementation based on LazyBoy created by [Garren Smith](https://github.com/garrensmith/LazyBoy)
#Contributors
Tcha-Tcho
Bruno Agutoli
近期下载者:
相关文件:
收藏者: