Files
windmill/typescript-client/sqlUtils.d.ts
T
Ruben FiszelandClaude Opus 5.5 85e73ae4f1 feat: add the viewer's roles to a data table connection that names none
The default role of a data table under roles is now a floor: a connection
naming no role also holds the roles its viewer is a tenant of, unless the
default is admin. This replaces the explicit as=viewer option, which is
removed from the reference parser, the executors and both clients. The roles
drawer warns while the default is admin and confirms before removing the
default role.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 09:27:24 +02:00

108 lines
3.1 KiB
TypeScript

type ResultCollection =
| "last_statement_all_rows"
| "last_statement_first_row"
| "last_statement_all_rows_scalar"
| "last_statement_first_row_scalar"
| "all_statements_all_rows"
| "all_statements_first_row"
| "all_statements_all_rows_scalar"
| "all_statements_first_row_scalar"
| "legacy";
type FetchParams<ResultCollectionT extends ResultCollection> = {
resultCollection?: ResultCollectionT;
};
type SqlResult<
T,
ResultCollectionT extends ResultCollection
> = ResultCollectionT extends "last_statement_first_row"
? T | null
: ResultCollectionT extends "all_statements_first_row"
? T[]
: ResultCollectionT extends "last_statement_all_rows"
? T[]
: ResultCollectionT extends "all_statements_all_rows"
? T[][]
: ResultCollectionT extends "last_statement_all_rows_scalar"
? T[keyof T][]
: ResultCollectionT extends "all_statements_all_rows_scalar"
? T[keyof T][][]
: ResultCollectionT extends "last_statement_first_row_scalar"
? T[keyof T] | null
: ResultCollectionT extends "all_statements_first_row_scalar"
? T[keyof T][]
: unknown;
export type SqlStatement<T> = {
content: string;
args: Record<string, any>;
fetch<ResultCollectionT extends ResultCollection = "last_statement_all_rows">(
params?: FetchParams<ResultCollectionT | ResultCollection> // The union is for auto-completion
): Promise<SqlResult<T, ResultCollectionT>>;
fetchOne(
params?: Omit<FetchParams<"last_statement_first_row">, "resultCollection">
): Promise<SqlResult<T, "last_statement_first_row">>;
/**
* Execute the SQL query and return only the first row as a scalar value
* @param params - Optional parameters
* @returns First row of the query result
*/
fetchOneScalar(
params?: Omit<
FetchParams<"last_statement_first_row_scalar">,
"resultCollection"
>
): Promise<SqlResult<T, "last_statement_first_row_scalar">>;
/**
* Execute the SQL query without fetching rows
* @param params - Optional parameters
*/
execute(
params?: Omit<
FetchParams<"last_statement_first_row_scalar">,
"resultCollection"
>
): Promise<void>;
};
export declare class RawSql {
readonly __brand: "RawSql";
readonly value: string;
constructor(value: string);
}
export interface SqlTemplateFunction {
<T = any>(strings: TemplateStringsArray, ...values: any[]): SqlStatement<T>;
raw(value: string): RawSql;
}
export interface DatatableSqlTemplateFunction extends SqlTemplateFunction {
query<T = any>(sql: string, ...params: any[]): SqlStatement<T>;
}
export interface DatatableOptions {
role?: string;
}
export declare function datatable(name?: string, opts?: DatatableOptions): DatatableSqlTemplateFunction;
export declare function ducklake(name: string): SqlTemplateFunction;
export interface DucklakeMaterializeOptions {
ducklake?: string;
table: string;
selectSql: string;
partition?: string;
uniqueKey?: string;
partitionCol?: string;
}
export declare function upsertPartition(
opts: DucklakeMaterializeOptions,
): SqlStatement<any>;
export declare function appendPartition(
opts: Omit<DucklakeMaterializeOptions, "uniqueKey">,
): SqlStatement<any>;