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 | 131x 387x 167x 92x 92x 183x | import {
ViewDdl,
type CreateMaterializedViewOptions,
type CreateViewOptions,
type DropViewOptions,
type RefreshMaterializedViewOptions,
} from '../ddl/view-ddl.ts';
import type { TableName } from '../ddl/sql-literal.ts';
import type { QueryOptionsBase } from '../model/runtime.ts';
import type { StatementRunner } from './statement-runner.ts';
const views = new ViewDdl();
/**
* View and materialized view DDL of `QueryInterface`. Names are quoted; the query is trusted SQL.
*
* @internal
*/
export class ViewCommands {
readonly #runner: StatementRunner;
/**
* @param runner - Statement runner.
*/
constructor(runner: StatementRunner) {
this.#runner = runner;
}
/**
* Runs `CREATE VIEW`.
*
* @param name - View name.
* @param query - Trusted `SELECT` text.
* @param options - View and query options.
*/
async createView(
name: TableName,
query: string,
options: CreateViewOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(views.createSql(name, query, options), options);
}
/**
* Runs `CREATE MATERIALIZED VIEW`.
*
* @param name - View name.
* @param query - Trusted `SELECT` text.
* @param options - View and query options.
*/
async createMaterializedView(
name: TableName,
query: string,
options: CreateMaterializedViewOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(views.createMaterializedSql(name, query, options), options);
}
/**
* Runs `REFRESH MATERIALIZED VIEW`.
*
* @param name - View name.
* @param options - Refresh and query options.
*/
async refreshMaterializedView(
name: TableName,
options: RefreshMaterializedViewOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(views.refreshSql(name, options), options);
}
/**
* Runs `DROP VIEW` or `DROP MATERIALIZED VIEW`.
*
* @param name - View name.
* @param materialized - Drops a materialized view.
* @param options - Drop and query options.
*/
async dropView(
name: TableName,
materialized: boolean,
options: DropViewOptions & QueryOptionsBase,
): Promise<void> {
await this.#runner.run(views.dropSql(name, materialized, options), options);
}
}
|