當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongojs.default函數代碼示例

本文整理匯總了TypeScript中mongojs.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

 beforeEach((next) => {
     var db = mongojs(process.env.MONGO_URI, ["logger"]);
     db["logger"].remove({}, next);
 });
開發者ID:data-avail,項目名稱:da-helpers,代碼行數:4,代碼來源:logger.spec.ts

示例2: createTodoApi

export function createTodoApi() {
  let mongojs = require('mongojs');
  let router = Router();
  let db = mongojs('mongodb://admin:admin123@ds037827.mongolab.com:37827/ng2todoapp', ['todos']);
  /* GET All Todos */
  router.get('/todos', function(req, res, next) {
    db.todos.find(function(err, todos) {
      if (err) {
        res.send(err);
      } else {
        res.json(todos);
      }
    });
  });
  /* GET One Todo with the provided ID */
  router.get('/todo/:id', function(req, res, next) {
    db.todos.findOne({
      _id: mongojs.ObjectId(req.params.id)
    }, function(err, todos) {
      if (err) {
        res.send(err);
      } else {
        res.json(todos);
      }
    });
  });
  /* POST/SAVE a Todo */
  router.post('/todo', function(req, res, next) {
    var todo = req.body;
    if (!todo.text || !(todo.isCompleted + '')) {
      res.status(400);
      res.json({
        "error": "Invalid Data",
        'todo': todo
      });
    } else {
      db.todos.save(todo, function(err, result) {
        if (err) {
          res.send(err);
        } else {
          res.json(result);
        }
      })
    }
  });
  /* PUT/UPDATE a Todo */
  router.put('/todo/:id', function(req, res, next) {
    var todo = req.body;
    var updObj = { 'isCompleted': false, 'text': ''};
    if (todo.isCompleted) {
      updObj.isCompleted = todo.isCompleted;
    }
    if (todo.text) {
      updObj.text = todo.text;
    }
    if (!updObj) {
      res.status(400);
      res.json({
        "error": "Invalid Data"
      });
    } else {
      db.todos.update({
        _id: mongojs.ObjectId(req.params.id)
      }, updObj, {}, function(err, result) {
        if (err) {
          res.send(err);
        } else {
          res.json(result);
        }
      });
    }
  });
  /* DELETE a Todo */
  router.delete('/todo/:id', function(req, res) {
    db.todos.remove({
      _id: mongojs.ObjectId(req.params.id)
    }, '', function(err, result) {
      if (err) {
        res.send(err);
      } else {
        res.json(result);
      }
    });
  });

  return router;
}
開發者ID:Codenator81,項目名稱:ng2do-mean-app,代碼行數:87,代碼來源:api.ts

示例3: handle

/// <reference path="../typings/tsd.d.ts" />
var Promise = require("bluebird");
var mongojs = require("mongojs");

var mongoUrl = process.env.MONGO_PORT_27017_TCP_ADDR ?
    "mongodb://#{process.env.MONGO_PORT_27017_TCP_ADDR}:#{process.env.MONGO_PORT_27017_TCP_PORT}" :
    process.env.MONGO_HANDLER_URI;

var mongoCollection = process.env.MONGO_HANDLER_COLLECTION;

var db = mongojs(mongoUrl, [mongoCollection]);
var coll : any = Promise.promisifyAll(db[mongoCollection]);
var findAsync : <T>(query: any) => Promise<T[]> = Promise.promisify(coll.find, coll)

interface IPosition {
    _id: string
    ticker: string
}

export function handle (portfolio: tn.ITraderNetPortfolio) {
    findAsync<IPosition>({}).then((res) =>
        console.log("handler.ts:24>>>", res)
    );
}

exports.handle = handle;

開發者ID:data-avail,項目名稱:docker-bee-tmpl,代碼行數:26,代碼來源:handler.ts

示例4: constructor

        constructor(opts: ILoggerOpts, mongoOpts : ILoggerMongoOpts) {
            this.tags = [opts.pack.name, opts.pack.ver].concat(opts.tags).filter((f) => !!f);

            this.db = mongojs(mongoOpts.connection, [mongoOpts.collection]);
            this.insertAsync = promise.promisify(this.db[mongoOpts.collection].insert, this.db[mongoOpts.collection]);
        }
開發者ID:data-avail,項目名稱:da-helpers,代碼行數:6,代碼來源:logger-mongo.ts

示例5: get

/// <reference path="../../node.d.ts" />
/// <reference path="../../express.d.ts" />

var mongojs = require("mongojs");

/**
  *
  * config: { collection: 'components', db: 'exampledb' }
  *
 */

var db = mongojs('appchix'),
Component = db.collection('components');

export module rest {

  export function get(req, res) {

  };

  export function post(req, res) {
/*
      var v = request.body; 

      var schema_uri = null;
      var datasource_uri = null;
      var filter = { _id: null };

      var obj =   {
           type: v.path,
           schema: schema_uri, // Schema to validate what is inside config.
開發者ID:psichi,項目名稱:chix-modules,代碼行數:31,代碼來源:module.ts


注:本文中的mongojs.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。