您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 跨数据库的ORM框架JugglingDB.zip
  所属分类: 其它
  开发工具:
  文件大小: 116kb
  下载次数: 0
  上传时间: 2019-07-18
  提 供 者: weixin_********
 详细说明: JugglingDB 是一个跨数据库的 ORM 框架,提供了访问大多数数据库的通用接口,支持包括:mysql, mongodb, redis, neo4j and js-memory-storage. 你可扩展其他数据库的适配器,支持回调和钩子。 示例代码: var Schema = require(./jugglingdb).Schema; var schema = new Schema(redis, {port: 6379}); //port number depends on your configuration // define models var Post = schema.define(� 39;Post, { title: { type: String, length: 255 }, content: { type: Schema.Text }, date: { type: Date, default: Date.now }, published: { type: Boolean, default: false } }); // simplier way to describe model var User = schema.define(User, { name: String, bio: Schema.Text, approved: Boolean, joinedAt: Date, age: Number }); // setup relationships User.hasMany(Post, {as: posts, foreignKey: userId}); // creates instance methods: // user.posts(conds) // user.posts.build(data) // like new Post({userId: user.id}); // user.posts.create(data) // build and save Post.belongsTo(User, {as: author, foreignKey: userId}); // creates instance methods: // post.author(callback) -- getter when called with function // post.author() -- sync getter when called without params // post.author(user) -- setter when called with object schema.automigrate(); // required only for mysql NOTE: it will drop User and Post tables // work with models: var user = new User; user.save(function (err) { var post = user.posts.build({title: Hello world}); post.save(console.log); }); // or just call it as function (with the same result): var user = User(); user.save(...); // Common API methods // just instantiate model new Post // save model (of course async) Post.create(cb); // all posts Post.all(cb) // all posts by user Post.all({where: {userId: user.id}, order: id, limit: 10, skip: 20}); // the same as prev user.posts(cb) // same as new Post({userId: user.id}); user.posts.build // save as Post.create({userId: user.id}, cb); user.posts.create(cb) // find instance by id User.find(1, cb) // count instances User.count([conditions, ]cb) // destroy instance user.destroy(cb); // destroy all instances User.destroyAll(cb); // Setup validations User.validatesPresenceOf(name, email) User.validatesLengthOf(password, {min: 5, message: {min: Password is too short}}); User.validatesInclusionOf(gender, {in: [male, female]}); User.validatesExclusionOf(domain, {in: [www, billing, admin]}); User.validatesNumericalityOf(age, {int: true}); User.validatesUniquenessOf(email, {message: email is not unique}); user.isValid(function (valid) { if (!valid) { user.errors // hash of errors {attr: [errmessage, errmessage, ...], attr: ...} } }) 标签:JugglingDB
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索:
 输入关键字,在本站1000多万海量源码库中尽情搜索: