-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
drop.ts
52 lines (44 loc) · 1.68 KB
/
drop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Aspect, defineAspects } from './operation';
import { CommandOperation, CommandOperationOptions } from './command';
import type { Callback } from '../utils';
import type { Server } from '../sdam/server';
import type { Db } from '../db';
import type { ClientSession } from '../sessions';
/** @public */
export type DropCollectionOptions = CommandOperationOptions;
/** @internal */
export class DropCollectionOperation extends CommandOperation<boolean> {
options: DropCollectionOptions;
name: string;
constructor(db: Db, name: string, options: DropCollectionOptions) {
super(db, options);
this.options = options;
this.name = name;
}
execute(server: Server, session: ClientSession, callback: Callback<boolean>): void {
super.executeCommand(server, session, { drop: this.name }, (err, result) => {
if (err) return callback(err);
if (result.ok) return callback(undefined, true);
callback(undefined, false);
});
}
}
/** @public */
export type DropDatabaseOptions = CommandOperationOptions;
/** @internal */
export class DropDatabaseOperation extends CommandOperation<boolean> {
options: DropDatabaseOptions;
constructor(db: Db, options: DropDatabaseOptions) {
super(db, options);
this.options = options;
}
execute(server: Server, session: ClientSession, callback: Callback<boolean>): void {
super.executeCommand(server, session, { dropDatabase: 1 }, (err, result) => {
if (err) return callback(err);
if (result.ok) return callback(undefined, true);
callback(undefined, false);
});
}
}
defineAspects(DropCollectionOperation, [Aspect.WRITE_OPERATION]);
defineAspects(DropDatabaseOperation, [Aspect.WRITE_OPERATION]);