import type { RunSQLOptions } from '../run_sql_options'; import type { Annotation, MalloyQueryData, QueryDataRow, QueryRunStats, SQLSourceDef, TableSourceDef } from '../model/malloy_types'; import type { Dialect } from '../dialect'; import type { SQLSourceRequest } from '../lang/translate-response'; /** * Options passed to fetchSchema methods. */ export interface FetchSchemaOptions { refreshTimestamp?: number; modelAnnotation?: Annotation; } /** * An object capable of reading schemas for given table names. */ export interface InfoConnection { /** * Fetch schemas for multiple tables. * * @param tables The names of tables to fetch schemas for, represented * as a map of keys to table names. * @return A mapping of table keys to schemas. */ fetchSchemaForTables(tables: Record, options: FetchSchemaOptions): Promise<{ schemas: Record; errors: Record; }>; /** * Fetch schemas an SQL blocks * * @param block The SQL blocks to fetch schemas for. * @return A mapping of SQL block names to schemas. */ fetchSchemaForSQLStruct(sentence: SQLSourceRequest, options: FetchSchemaOptions): Promise<{ structDef: SQLSourceDef; error?: undefined; } | { error: string; structDef?: undefined; }>; /** * The name of the connection. */ get name(): string; get dialectName(): string; } export type ConnectionParameterValue = string | number | boolean | Array; export interface ConnectionParameter { name: string; label: string; type: 'string' | 'number' | 'boolean'; isOptional?: boolean; isSecret?: boolean; defaultValue?: ConnectionParameterValue; } export type ConnectionConfigSchema = ConnectionParameter[]; export interface ConnectionConfig { name: string; [key: string]: ConnectionParameterValue | undefined; } export interface ConnectionFactory { connectionName: string; configSchema: ConnectionConfigSchema; createConnection(connectionConfig: ConnectionConfig, dialectRegistrar?: (dialect: Dialect) => void): Connection & TestableConnection; } export interface ConnectionMetadata { url?: string; } export interface TableMetadata { url?: string; } /** * An object capable of running SQL. */ export interface Connection extends InfoConnection { /** * Run some SQL and yield results. * * @param sql The SQL to run. * @param options.pageSize Maximum number of results to return at once. * @return The rows of data resulting from running the given SQL query * and the total number of rows available. */ runSQL(sql: string, options?: RunSQLOptions): Promise; isPool(): this is PooledConnection; canPersist(): this is PersistSQLResults; canStream(): this is StreamingConnection; close(): Promise; estimateQueryCost(sqlCommand: string): Promise; fetchMetadata: () => Promise; fetchTableMetadata: (tablePath: string) => Promise; } export interface TestableConnection extends Connection { test(): Promise; } export interface PooledConnection extends Connection { drain(): Promise; isPool(): this is PooledConnection; } export interface PersistSQLResults extends Connection { manifestTemporaryTable(sqlCommand: string): Promise; } export interface StreamingConnection extends Connection { runSQLStream(sqlCommand: string, options?: RunSQLOptions): AsyncIterableIterator; } /** * A mapping of connection names to connections. */ export interface LookupConnection { /** * @param connectionName The name of the connection for which a `Connection` is required. * @return A promise to a `Connection` for the connection named `connectionName`. */ lookupConnection(connectionName?: string): Promise; }