/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { ISqlDialect } from "./Dialect"; /** * Minimal column descriptor used by the prefix-DDL helpers. This mirrors the * `PrefixColumn` shape that backends like the job queue and rate limiter use, * without forcing `@workglow/storage` to take a dependency on those packages. * * Backends that have their own `PrefixColumn`-like type pass instances of it * directly — the structural match is enough. */ export interface ISqlPrefixColumn { readonly name: string; readonly type: "uuid" | "number"; } /** * Throws if any prefix column name would be unsafe to splice into DDL. * * Beyond shape-checking via {@link SAFE_IDENTIFIER}, this also rejects names * that match a common SQL reserved word ({@link SQL_RESERVED_WORDS}) since * they're spliced unquoted and would otherwise produce confusing syntax * errors at the database level. Every helper in this module that splices * `prefix.name` into SQL calls this first, so storage backends don't need to * remember to validate at construction time. */ export declare function assertPrefixesSafe(prefixes: readonly ISqlPrefixColumn[]): void; /** * Throws if any declared prefix column lacks a value in `prefixValues`. * * Prefix columns are declared `NOT NULL` in the DDL helpers; binding * `undefined` for them later yields opaque database errors ("invalid input * syntax for type X" / "null value violates not-null constraint"). Catch the * misconfiguration at the call site instead. */ export declare function assertPrefixValuesPresent(prefixes: readonly ISqlPrefixColumn[], prefixValues: Readonly>): void; /** Returns the SQL column type for a {@link ISqlPrefixColumn} on the given dialect. */ export declare function prefixColumnType(dialect: ISqlDialect, type: ISqlPrefixColumn["type"]): string; /** * Builds the prefix portion of a CREATE TABLE column list, e.g. * `tenant_id UUID NOT NULL,\n project_id INTEGER NOT NULL,\n ` * * Returns an empty string when there are no prefixes so callers can splice it * directly into a column list without a trailing comma. */ export declare function buildPrefixColumnsSql(dialect: ISqlDialect, prefixes: readonly ISqlPrefixColumn[]): string; /** Returns prefix column names in declaration order. */ export declare function getPrefixColumnNames(prefixes: readonly ISqlPrefixColumn[]): string[]; /** * Comma-joined prefix column list with a trailing `, ` for index/insert use, * or an empty string when there are no prefixes. */ export declare function getPrefixIndexPrefix(prefixes: readonly ISqlPrefixColumn[]): string; /** Returns the index-name suffix derived from prefix columns. */ export declare function getPrefixIndexSuffix(prefixes: readonly ISqlPrefixColumn[]): string; /** * Builds an ` AND col1 = ? AND col2 = ?` (or `$N` for Postgres) suffix. * * @param startParam 1-based starting parameter index (Postgres only — SQLite * placeholders are positional and ignore this). */ export declare function buildPrefixWhereClause(dialect: ISqlDialect, prefixes: readonly ISqlPrefixColumn[], prefixValues: Readonly>, startParam?: number): { conditions: string; params: Array; }; /** Returns prefix values in column order for binding to placeholders. */ export declare function getPrefixParamValues(prefixes: readonly ISqlPrefixColumn[], prefixValues: Readonly>): Array; /** * Builds the prefix-portion of an INSERT column list and its placeholder list, * starting at parameter index `startParam`. Returns empty strings when there * are no prefixes so callers can concatenate without a trailing comma. */ export declare function buildPrefixInsertFragments(dialect: ISqlDialect, prefixes: readonly ISqlPrefixColumn[], startParam?: number): { columns: string; placeholders: string; }; //# sourceMappingURL=PrefixDdl.d.ts.map