• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ptariche/koa-waterline: Deprecated: A middleware for your hose

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ptariche/koa-waterline

开源软件地址:

https://github.com/ptariche/koa-waterline

开源编程语言:

JavaScript 100.0%

开源软件介绍:

koa-waterline

Middleware for your hose

Build Status

NPM

npm install koa-waterline

Usage

//see example.js
  function* (){
    let ctx            = this;
    let message        = 'This is an example';
    let commentCreated = yield ctx._waterline.collections.comments.create({message: message});
    // You can yield to the CRUD waterline functions because they are written as promises.
    console.log(commentCreated);
  }
// OR
  function* () {
    let waterline      = yield Waterline.init(injection);
    let message        = 'This is an example';
    let commentCreated = yield waterline.collections.comments.create({message: message});
  }
  • The model attributes of connection and adp must match the connection and adapter naming conventions when setting up your environment to inject into the middleware.

Example

  let connections = {
    couch: {
      adapter: "couch",
      host: '127.0.0.1',
      port: '5984',
      username: '',
      password: ''
    },
    mongo: {
      adapter: "mongo",
      host: 'localhost',
      port: '27017',
      user: '',
      password: '',
      database: 'waterline'
    },
    cassandra: {
      adapter: "cassandra",
      host: '',
      password: '',
      contactPoints: ['127.0.0.1'],
      keyspace: 'dev'
    }
  };

  let adapters = {
    couch:     require('sails-couchdb-orm'),
    mongo:     require('sails-mongo'),
    cassandra: require('sails-cassandra')
  };

  let models = {
      "comments": {
        "model": true,
        "adp": "couch",
        "connection": "couch",
        "properties": {
          "archived": {
              "type": "boolean",
              "defaultValue": false
          },
          "message": {
              "type": "string"
          }
        }
      },
      "history": {
        "model" : true,
        "adp": "mongo",
        "connection": "mongo",
        "properties": {
          "year": {
            "type": "string"
          }
        }
      },
      "tweet": {
        "adp": "cassandra",
        "connection": "cassandra",
        "index": ['tweet_body'],
        "properties": {
          "tweet_body": {
            "type": "string"
          }
        }
      },
      "error": {
        "model": false,
        "properties": {
          "erro": {
            "type": "string"
          }
        }
      }
    };

  let injection               = {};
  injection.methods           = false;
  injection.models            = models;
  injection.adapters          = adapters;
  injection.connections       = connections;

  app.use(waterline(injection));

##Attributes Models - Required

- Models must have an adp, connection, and the properties attributes with the same design pattern in the example above. There is an optional model flag that can be added inside the model that should be set to true or false; this allows you to not instiatiate specific models in waterline.

Adapters - Required

- The adapters refer to the connection adapters; this is required and while seeming redundant it is required to run waterline

Connections - Required

- The connection attributes are the setting parameters for the data models to create the waterline.

Methods - Optional

 - The methods attribute allows the injection of functions for virtual methods inside the model. An example of such an injection would something like this:

Methods Example:

 let methods = {
     history: function(){
     //virtual methods specific to the history model
     },
     comments: function(){
     //virtual methods specific to the comments model
     }
};

Notes

- Sails Cassandra fails the next time it's initialized because it attempts to over-ride; restart the service again until the actual sails-cassandra has been fixed

Debug

- DEBUG=koa-waterline node --harmony example.js

Authors

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
fondadam/wechat-koa2: Developed Wechat by using Koa2 !发布时间:2022-07-09
下一篇:
stevehorn/jquery-koans发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap