mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #45356 [@types/mongoose]: add Connection.useDb options by @borfig
* [@types/mongoose]: add Connection.useDb options * [@types/mongoose]: test Connection.useDb options
This commit is contained in:
parent
3c7530474e
commit
8d6b195647
9
types/mongoose/index.d.ts
vendored
9
types/mongoose/index.d.ts
vendored
@ -542,6 +542,12 @@ declare module "mongoose" {
|
||||
getIndexes(): any;
|
||||
}
|
||||
|
||||
interface ConnectionUseDbOptions {
|
||||
/**
|
||||
* If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object.
|
||||
*/
|
||||
useCache?: boolean;
|
||||
}
|
||||
/*
|
||||
* section drivers/node-mongodb-native/connection.js
|
||||
* http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-connection-js
|
||||
@ -550,9 +556,10 @@ declare module "mongoose" {
|
||||
/**
|
||||
* Switches to a different database using the same connection pool.
|
||||
* @param name The database name
|
||||
* @param options Additional options
|
||||
* @returns New Connection Object
|
||||
*/
|
||||
useDb(name: string): Connection;
|
||||
useDb(name: string, options?: ConnectionUseDbOptions): Connection;
|
||||
|
||||
startSession(options?: mongodb.SessionOptions, cb?: (err: any, session: mongodb.ClientSession) => void): Promise<mongodb.ClientSession>;
|
||||
|
||||
|
||||
@ -174,6 +174,9 @@ conn1.name.toLowerCase()
|
||||
conn1.host.toLowerCase()
|
||||
conn1.port.toFixed()
|
||||
conn1.useDb('myDb').useDb('');
|
||||
conn1.useDb('myDb').useDb('', {});
|
||||
conn1.useDb('myDb').useDb('', {useCache: false});
|
||||
conn1.useDb('myDb').useDb('', {useCache: true});
|
||||
mongoose.Connection.STATES.hasOwnProperty('');
|
||||
mongoose.Connection.STATES.disconnected === 0;
|
||||
mongoose.Connection.STATES.connected === 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user