UNPKG

kysely

Version:

Type safe SQL query builder

48 lines (47 loc) 1.36 kB
/// <reference types="./drop-type-builder.d.ts" /> import { DropTypeNode } from '../operation-node/drop-type-node.js'; import { freeze } from '../util/object-utils.js'; export class DropTypeBuilder { #props; constructor(props) { this.#props = freeze(props); } /** * Adds `if exists` to the query. */ ifExists() { return new DropTypeBuilder({ ...this.#props, node: DropTypeNode.cloneWith(this.#props.node, { ifExists: true, }), }); } /** * Adds `cascade` to the query. */ cascade() { return new DropTypeBuilder({ ...this.#props, node: DropTypeNode.cloneWith(this.#props.node, { cascade: true, }), }); } /** * Simply calls the provided function passing `this` as the only argument. `$call` returns * what the provided function returns. */ $call(func) { return func(this); } toOperationNode() { return this.#props.executor.transformQuery(this.#props.node, this.#props.queryId); } compile() { return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId); } async execute(options) { await this.#props.executor.executeQuery(this.compile(), options); } }