-
Notifications
You must be signed in to change notification settings - Fork 280
/
drop-table-builder.ts
55 lines (47 loc) · 1.57 KB
/
drop-table-builder.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
53
54
55
import { DropTableNode } from '../operation-node/drop-table-node.js'
import { OperationNodeSource } from '../operation-node/operation-node-source.js'
import { CompiledQuery } from '../query-compiler/compiled-query.js'
import { Compilable } from '../util/compilable.js'
import { preventAwait } from '../util/prevent-await.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
import { QueryId } from '../util/query-id.js'
import { freeze } from '../util/object-utils.js'
export class DropTableBuilder implements OperationNodeSource, Compilable {
readonly #props: DropTableBuilderProps
constructor(props: DropTableBuilderProps) {
this.#props = freeze(props)
}
ifExists(): DropTableBuilder {
return new DropTableBuilder({
...this.#props,
dropTableNode: DropTableNode.cloneWithModifier(
this.#props.dropTableNode,
'IfExists'
),
})
}
toOperationNode(): DropTableNode {
return this.#props.executor.transformQuery(
this.#props.dropTableNode,
this.#props.queryId
)
}
compile(): CompiledQuery {
return this.#props.executor.compileQuery(
this.toOperationNode(),
this.#props.queryId
)
}
async execute(): Promise<void> {
await this.#props.executor.executeQuery(this.compile(), this.#props.queryId)
}
}
preventAwait(
DropTableBuilder,
"don't await DropTableBuilder instances directly. To execute the query you need to call `execute`"
)
export interface DropTableBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly dropTableNode: DropTableNode
}