-
Notifications
You must be signed in to change notification settings - Fork 280
/
drop-view-builder.ts
72 lines (62 loc) · 1.89 KB
/
drop-view-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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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'
import { DropViewNode } from '../operation-node/drop-view-node.js'
export class DropViewBuilder implements OperationNodeSource, Compilable {
readonly #props: DropViewBuilderProps
constructor(props: DropViewBuilderProps) {
this.#props = freeze(props)
}
materialized(): DropViewBuilder {
return new DropViewBuilder({
...this.#props,
node: DropViewNode.cloneWith(this.#props.node, {
materialized: true,
}),
})
}
ifExists(): DropViewBuilder {
return new DropViewBuilder({
...this.#props,
node: DropViewNode.cloneWith(this.#props.node, {
ifExists: true,
}),
})
}
cascade(): DropViewBuilder {
return new DropViewBuilder({
...this.#props,
node: DropViewNode.cloneWith(this.#props.node, {
cascade: true,
}),
})
}
toOperationNode(): DropViewNode {
return this.#props.executor.transformQuery(
this.#props.node,
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(
DropViewBuilder,
"don't await DropViewBuilder instances directly. To execute the query you need to call `execute`"
)
export interface DropViewBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly node: DropViewNode
}