-
Notifications
You must be signed in to change notification settings - Fork 280
/
drop-schema-builder.ts
63 lines (54 loc) · 1.73 KB
/
drop-schema-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
import { DropSchemaNode } from '../operation-node/drop-schema-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 DropSchemaBuilder implements OperationNodeSource, Compilable {
readonly #props: DropSchemaBuilderProps
constructor(props: DropSchemaBuilderProps) {
this.#props = freeze(props)
}
ifExists(): DropSchemaBuilder {
return new DropSchemaBuilder({
...this.#props,
node: DropSchemaNode.cloneWith(this.#props.node, {
ifExists: true,
}),
})
}
cascade(): DropSchemaBuilder {
return new DropSchemaBuilder({
...this.#props,
node: DropSchemaNode.cloneWith(this.#props.node, {
cascade: true,
}),
})
}
toOperationNode(): DropSchemaNode {
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(
DropSchemaBuilder,
"don't await DropSchemaBuilder instances directly. To execute the query you need to call `execute`"
)
export interface DropSchemaBuilderProps {
readonly queryId: QueryId
readonly executor: QueryExecutor
readonly node: DropSchemaNode
}