mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-18 14:26:56 +00:00
update mongodb
This commit is contained in:
parent
cdadcc472c
commit
37f3491b17
@ -71,6 +71,15 @@ export default class {
|
||||
this.lastInsertId = result.insertedIds;
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* select data
|
||||
* @param {Object} options []
|
||||
* @return {Promise} []
|
||||
*/
|
||||
async select(options){
|
||||
let collection = await this.collection(options.table);
|
||||
return collection.find({name: "welefen"}, {name: false}).limit(2).toArray();
|
||||
}
|
||||
/**
|
||||
* close socket
|
||||
* @return {} []
|
||||
|
||||
@ -60,7 +60,7 @@ export default class extends think.adapter.socket {
|
||||
this.connection = connection;
|
||||
return connection;
|
||||
})
|
||||
let err = new Error(`mongodb://${auth}${config.host}:${config.port}`);
|
||||
let err = new Error(str);
|
||||
return think.error(promise, err);
|
||||
});
|
||||
}
|
||||
|
||||
@ -120,7 +120,17 @@ export default class extends Base {
|
||||
* select data
|
||||
* @return {Promise} []
|
||||
*/
|
||||
select(options){
|
||||
|
||||
async select(options){
|
||||
options = await this.parseOptions(options);
|
||||
let data = await this.db().select(options);
|
||||
return this._afterSelect(data, options);
|
||||
}
|
||||
/**
|
||||
* select one row data
|
||||
* @param {Object} options []
|
||||
* @return {Promise} []
|
||||
*/
|
||||
find(options){
|
||||
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ describe('adapter/socket/mongo', function(){
|
||||
}
|
||||
});
|
||||
instance.getConnection().catch(function(err){
|
||||
assert.equal(err.message, 'Address not available, mongodb://welefen:suredy@127.0.0.1:27017. http://www.thinkjs.org/doc/error.html#EADDRNOTAVAIL')
|
||||
assert.equal(err.message, 'Address not available, mongodb://welefen:suredy@127.0.0.1:27017/test?slaveOk=true. http://www.thinkjs.org/doc/error.html#EADDRNOTAVAIL')
|
||||
think.npm = npm;
|
||||
think.reject = reject;
|
||||
done();
|
||||
|
||||
@ -196,84 +196,110 @@ describe('controller/base.js', function(){
|
||||
})
|
||||
})
|
||||
it('send time', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.sendTime();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('error', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.error();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('fail', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.fail();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('success', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.success();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('type', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.type();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('end', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.end();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('echo', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.echo();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('deny', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.deny();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('deny 404', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance({
|
||||
status: function(status){
|
||||
assert.equal(status, 404);
|
||||
}
|
||||
}).then(function(instance){
|
||||
var data = instance.deny(404);
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('status', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.status();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('json', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.json();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('jsonp', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.jsonp();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
it('redirect', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance().then(function(instance){
|
||||
var data = instance.redirect();
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
@ -340,11 +366,13 @@ describe('controller/base.js', function(){
|
||||
})
|
||||
})
|
||||
it('display', function(done){
|
||||
muk(think, 'log', function(){})
|
||||
getInstance({
|
||||
}).then(function(instance){
|
||||
return instance.display(__filename)
|
||||
}).catch(function(err){
|
||||
assert.equal(think.isPrevent(err), true);
|
||||
muk.restore();
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user