本文整理汇总了TypeScript中mongorito.Database.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Database.use方法的具体用法?TypeScript Database.use怎么用?TypeScript Database.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongorito.Database
的用法示例。
在下文中一共展示了Database.use方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('Database', async () => {
// ----- constructor -----
new Database(URL);
const options: MongoClientOptions = {};
const database = new Database(URL, options);
new Database(URL);
new Database(['other', URL]);
new Database(['other', URL], options);
// ----- connect -----
const connectResultPromise: Promise<Db> = database.connect();
expect(connectResultPromise).toBeInstanceOf(Promise);
const connectResult: Db = await connectResultPromise;
expect(connectResult).toBeInstanceOf(Db);
// ----- connection -----
const connectionResultPromise: Promise<Db> = database.connection();
expect(connectionResultPromise).toBeInstanceOf(Promise);
const connectionResult: Db = await connectionResultPromise;
expect(connectionResult).toBeInstanceOf(Db);
// ----- disconnect -----
const disconnectResultPromise: Promise<void> = database.disconnect();
expect(disconnectResultPromise).toBeInstanceOf(Promise);
// expect(await disconnectResultPromise).toBeUndefined();
await disconnectResultPromise; // $ExpectType void
// ----- register -----
class RegisteredModel extends Model {
constructor(fields?: object) {
super(fields);
}
}
class RegisteredModelA extends Model {
constructor(fields?: object) {
super(fields);
}
}
class RegisteredModelB extends Model {
constructor(fields?: object) {
super(fields);
}
}
// expect(database.register(RegisteredModel)).toBeUndefined();
database.register(RegisteredModel); // $ExpectType void
// expect(database.register([RegisteredModelA, RegisteredModelB])).toBeUndefined();
database.register([RegisteredModelA, RegisteredModelB]); // $ExpectType void
// ----- use -----
// expect(database.use(plugin1)).toBeUndefined();
database.use(plugin1); // $ExpectType void
// expect(database.use([plugin2, plugin3])).toBeUndefined();
database.use([plugin2, plugin3]); // $ExpectType void
});