本文整理汇总了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);
});
示例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;
}
示例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;
示例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]);
}
示例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.