Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 131x 131x 387x 609x 91x 74x 460x 92x 1x | import {
FunctionDdl,
type CreateFunctionOptions,
type DropFunctionOptions,
type FunctionName,
type FunctionParam,
} from '../ddl/function-ddl.ts';
import type { TableName } from '../ddl/sql-literal.ts';
import {
TriggerDdl,
type CreateTriggerOptions,
type DropTriggerOptions,
type TriggerSpec,
} from '../ddl/trigger-ddl.ts';
import type { QueryOptionsBase } from '../model/runtime.ts';
import type { StatementRunner } from './statement-runner.ts';
const functions = new FunctionDdl();
const triggers = new TriggerDdl();
/**
* Function and trigger DDL of `QueryInterface`. Names are quoted or guarded words, trigger
* arguments are literals, function bodies are trusted SQL (ADR-025).
*
* @internal
*/
export class RoutineCommands {
readonly #runner: StatementRunner;
/**
* @param runner - Statement runner.
*/
constructor(runner: StatementRunner) {
this.#runner = runner;
}
/**
* Runs `CREATE FUNCTION`.
*
* @param name - Function name.
* @param params - Parameters.
* @param returnType - Return type.
* @param language - Language.
* @param body - Trusted body text.
* @param optionsArray - Characteristic keywords.
* @param options - Statement and query options.
*/
async createFunction(
name: FunctionName,
params: readonly FunctionParam[],
returnType: string,
language: string,
body: string,
optionsArray: readonly string[],
options: CreateFunctionOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(
functions.createSql(name, params, returnType, language, body, optionsArray, options),
options,
);
}
/**
* Runs `DROP FUNCTION`.
*
* @param name - Function name.
* @param params - Parameters identifying the overload.
* @param options - Statement and query options.
*/
async dropFunction(
name: FunctionName,
params: readonly FunctionParam[],
options: DropFunctionOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(functions.dropSql(name, params, options), options);
}
/**
* Runs `ALTER FUNCTION ... RENAME TO`.
*
* @param name - Current name.
* @param params - Parameters identifying the overload.
* @param newName - New name.
* @param options - Query options.
*/
async renameFunction(
name: FunctionName,
params: readonly FunctionParam[],
newName: string,
options: QueryOptionsBase,
): Promise<void> {
await this.#runner.run(functions.renameSql(name, params, newName), options);
}
/**
* Runs `CREATE TRIGGER`.
*
* @param spec - Trigger definition.
* @param options - Statement and query options.
*/
async createTrigger(
spec: TriggerSpec,
options: CreateTriggerOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(triggers.createSql(spec, options), options);
}
/**
* Runs `DROP TRIGGER`.
*
* @param table - Table.
* @param name - Trigger name.
* @param options - Statement and query options.
*/
async dropTrigger(
table: TableName,
name: string,
options: DropTriggerOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(triggers.dropSql(table, name, options), options);
}
/**
* Runs `ALTER TRIGGER ... RENAME TO`.
*
* @param table - Table.
* @param name - Current name.
* @param newName - New name.
* @param options - Query options.
*/
async renameTrigger(
table: TableName,
name: string,
newName: string,
options: QueryOptionsBase,
): Promise<void> {
await this.#runner.run(triggers.renameSql(table, name, newName), options);
}
}
|