Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support multi client 1.support multi client, add Singleton `app.mongooseDB` 2.now `app.mongoose` is default Mongoose instance, remove `app.__mongoose` 3.loadModel after loaded * test: misspell & optimize test sub model * docs: multiple connections * feat: add loadModel
- Loading branch information
1 parent
979b931
commit 22d134b
Showing
50 changed files
with
660 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = agent => { | ||
require('./lib/mongoose')(agent); | ||
if (agent.config.mongoose.agent) require('./lib/mongoose')(agent); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
require('./lib/mongoose')(app); | ||
if (app.config.mongoose.app) require('./lib/mongoose')(app); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,7 @@ | |
exports.mongoose = { | ||
url: '', | ||
options: {}, | ||
loadModel: true, | ||
app: true, | ||
agent: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
app.mymongoose = app.mongooseDB.createInstance(app.config.mymongoose); | ||
app.mongoose.loadModel(); | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const mymongoose = app.mymongoose; | ||
const mongoose = app.mongoose; | ||
const BoookSchema = new mongoose.Schema({ | ||
name: { type: String }, | ||
}); | ||
|
||
return mymongoose.model('Book', BoookSchema, null, { cache: false }); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const mymongoose = app.mymongoose; | ||
const mongoose = app.mongoose; | ||
const UserSchema = new mongoose.Schema({ | ||
name: { type: String }, | ||
}); | ||
|
||
return mymongoose.model('User', UserSchema, null, { cache: false }); | ||
}; |
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
test/fixtures/apps/mongoose-loadModel/config/config.default.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
exports.mongoose = { | ||
loadModel: false, | ||
}; | ||
|
||
exports.mymongoose = { | ||
url: 'mongodb://127.0.0.1/test', | ||
options: {}, | ||
}; | ||
|
||
exports.keys = 'aaa'; |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
test/fixtures/apps/mongoose-multi-defaultDB/app/controller/book.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
class BookController extends app.Controller { | ||
* create() { | ||
const book = new this.ctx.model.Book({ | ||
name: this.ctx.request.body.name, | ||
user: this.ctx.request.body.user, | ||
}); | ||
yield book.save(); | ||
this.ctx.body = book; | ||
} | ||
|
||
* show() { | ||
const id = this.ctx.params.id; | ||
const book = yield this.ctx.model.Book.findById(id) | ||
.populate({ | ||
path: 'user', | ||
}) | ||
.exec(); | ||
this.ctx.body = book; | ||
} | ||
} | ||
|
||
return BookController; | ||
|
||
}; |
Oops, something went wrong.