drop.ts
1.77 KB
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
53
54
55
56
57
58
59
60
import type { Db } from '../db';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import type { Callback } from '../utils';
import { CommandOperation, CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';
/** @public */
export type DropCollectionOptions = CommandOperationOptions;
/** @internal */
export class DropCollectionOperation extends CommandOperation<boolean> {
override options: DropCollectionOptions;
name: string;
constructor(db: Db, name: string, options: DropCollectionOptions) {
super(db, options);
this.options = options;
this.name = name;
}
override execute(
server: Server,
session: ClientSession | undefined,
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> {
override options: DropDatabaseOptions;
constructor(db: Db, options: DropDatabaseOptions) {
super(db, options);
this.options = options;
}
override execute(
server: Server,
session: ClientSession | undefined,
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]);