Client
On this page
Calling a VGI worker from TypeScript, without DuckDB in the middle.
interface CatalogAttachOptions
Section titled âinterface CatalogAttachOptionsâexport interface CatalogAttachOptionsDescription
Options bag for VgiClient.catalogAttach.
Pass options as a plain keyâvalue map â the client serializes to an
Arrow RecordBatch with per-value type inference (see AttachOptionValue).
For Arrow types that inference canât express (Decimal, Timestamp, exact
int width, nested struct), use optionsBytes to supply pre-serialized
bytes. Providing both throws.
dataVersionSpec / implementationVersion are sent to versioned
catalogs for attach-time validation; workers that arenât versioned
ignore them.
Fields
optionsRecord<string, AttachOptionValue>optionaloptionsBytesUint8ArrayoptionaldataVersionSpecstring | nulloptionalimplementationVersionstring | nulloptional
type ClientCatalogFunctionType
Section titled âtype ClientCatalogFunctionTypeâexport type CatalogFunctionType = âSCALAR_FUNCTIONâ | âTABLE_FUNCTIONâ;Description
DuckDB catalog function type filter (sent as uppercase wire values).
type OnCreateConflict
Section titled âtype OnCreateConflictâexport type OnCreateConflict = âerrorâ | âignoreâ | âreplaceâ;Description
Conflict resolution strategy for create operations.
interface ScalarFunctionOptions
Section titled âinterface ScalarFunctionOptionsâexport interface ScalarFunctionOptionsDescription
Options for calling a scalar function.
Fields
functionNamestringName of the function to call.
inputIterable<VgiBatch> | AsyncIterable<VgiBatch>Input batches to process.
argumentsArgumentsoptionalPositional and named arguments.
settingsVgiBatchoptionalDuckDB settings to pass to the function.
secretsVgiBatchoptionalDuckDB secrets to pass to the function.
transactionOpaqueDataUint8ArrayoptionalTransaction ID for transactional catalogs.
attachOpaqueDataUint8ArrayoptionalAttach ID to bind this call to a specific catalog attach. Overrides the client-level attachOpaqueData.
onBindBindResultCallbackoptionalInvoked after bind, before init. Receives the bind response.
interface TableFunctionOptions
Section titled âinterface TableFunctionOptionsâexport interface TableFunctionOptionsDescription
Options for calling a table function.
Fields
functionNamestringName of the function to call.
argumentsArgumentsoptionalPositional and named arguments.
projectionIdsnumber[]optionalColumn indices to project (filter pushdown).
pushdownFiltersVgiBatchoptionalFilter pushdown batch.
settingsVgiBatchoptionalDuckDB settings to pass to the function.
transactionOpaqueDataUint8ArrayoptionalTransaction ID for transactional catalogs.
attachOpaqueDataUint8ArrayoptionalAttach ID to bind this call to a specific catalog attach. Overrides the client-level attachOpaqueData.
orderByOrderByPushdownoptionalORDER BY pushdown hint from DuckDBâs RowGroupPruner.
tablesampleTablesamplePushdownoptionalTABLESAMPLE pushdown hint from DuckDBâs SamplingPushdown optimizer.
joinKeysVgiBatch[]optionalJoin-key value batches, one per join-keys column.
onBindBindResultCallbackoptionalInvoked after bind, before init. Receives the bind response.
interface TableInOutFunctionOptions
Section titled âinterface TableInOutFunctionOptionsâexport interface TableInOutFunctionOptionsDescription
Options for calling a table-in-out function.
Fields
functionNamestringName of the function to call.
inputIterable<VgiBatch> | AsyncIterable<VgiBatch>Input batches to process.
argumentsArgumentsoptionalPositional and named arguments.
projectionIdsnumber[]optionalColumn indices to project (filter pushdown).
pushdownFiltersVgiBatchoptionalFilter pushdown batch.
settingsVgiBatchoptionalDuckDB settings to pass to the function.
transactionOpaqueDataUint8ArrayoptionalTransaction ID for transactional catalogs.
attachOpaqueDataUint8ArrayoptionalAttach ID to bind this call to a specific catalog attach. Overrides the client-level attachOpaqueData.
orderByOrderByPushdownoptionalORDER BY pushdown hint from DuckDBâs RowGroupPruner.
tablesampleTablesamplePushdownoptionalTABLESAMPLE pushdown hint from DuckDBâs SamplingPushdown optimizer.
joinKeysVgiBatch[]optionalJoin-key value batches, one per join-keys column.
onBindBindResultCallbackoptionalInvoked after bind, before init. Receives the bind response.
class VgiClient
Section titled âclass VgiClientâexport class VgiClientDescription
High-level client for calling VGI worker functions and catalog API.
Works with any RpcClient transport (subprocess or HTTP):
import { subprocessConnect } from "@query-farm/vgi-rpc";import { VgiClient, Arguments } from "@query-farm/vgi";
const rpc = subprocessConnect(["./my-worker"]);const client = new VgiClient(rpc);
for await (const rows of client.tableFunctionRows({functionName: "sequence",arguments: new Arguments([10]),})) {console.log(rows);}client.close();Methods
method tableFunction
Section titled âmethod tableFunctionâasync *tableFunction( opts: TableFunctionOptions,): AsyncGenerator<VgiBatch>Call a table function, yielding output as RecordBatch instances.
method scalarFunctionRows
Section titled âmethod scalarFunctionRowsâasync *scalarFunctionRows( opts: ScalarFunctionOptions,): AsyncGenerator<Record<string, any>[]>Call a scalar function, yielding output as row objects.
method scalarFunction
Section titled âmethod scalarFunctionâasync *scalarFunction( opts: ScalarFunctionOptions,): AsyncGenerator<VgiBatch>Call a scalar function, yielding output as RecordBatch instances.
method tableInOutFunctionRows
Section titled âmethod tableInOutFunctionRowsâasync *tableInOutFunctionRows( opts: TableInOutFunctionOptions,): AsyncGenerator<Record<string, any>[]>Call a table-in-out function, yielding output as row objects.
method tableInOutFunction
Section titled âmethod tableInOutFunctionâasync *tableInOutFunction( opts: TableInOutFunctionOptions,): AsyncGenerator<VgiBatch>Call a table-in-out function, yielding output as RecordBatch instances.
method tableFunctionRows
Section titled âmethod tableFunctionRowsâasync *tableFunctionRows( opts: TableFunctionOptions,): AsyncGenerator<Record<string, any>[]>Call a table function, yielding output as row objects.
method catalogsInfo
Section titled âmethod catalogsInfoâasync catalogsInfo(): Promise<CatalogInfo[]>List all catalogs with their advertised version metadata.
Each entry has {name, implementation_version?, data_version_spec?}.
Versioned workers populate the version fields; read-only workers
leave both null.
method catalogs
Section titled âmethod catalogsâasync catalogs(): Promise<string[]>List all available catalog names (shorthand for catalogsInfo().map(c => c.name)).
method catalogAttach
Section titled âmethod catalogAttachâasync catalogAttach( name: string, opts?: CatalogAttachOptions,): Promise<CatalogAttachResult>Attach a catalog by name. Returns connection details including the attachOpaqueData.
opts.options is a plain keyâvalue map; column types are inferred from
the value at runtime (see AttachOptionValue for the mapping). Use
opts.optionsBytes instead when you need Arrow types the inference
canât express (Decimal, Timestamp, Int32 vs Int64, nested structs).
Providing both throws.
Versioned catalogs (see vgi-example-versioned-worker) validate
dataVersionSpec / implementationVersion at attach time and echo
back the resolved values on the result â callers can read those from
result.resolved_data_version / result.resolved_implementation_version.
method catalogDetach
Section titled âmethod catalogDetachâasync catalogDetach(attachOpaqueData: AttachOpaqueData): Promise<void>Detach a previously-attached catalog.
method catalogCreate
Section titled âmethod catalogCreateâasync catalogCreate( name: string, onConflict: OnCreateConflict, options?: | Uint8Array |Create a new catalog.
options is a plain keyâvalue map; column types are inferred from the
value at runtime (see AttachOptionValue). Use optionsBytes instead
when you need Arrow types the inference canât express. Providing both
throws.
method catalogDrop
Section titled âmethod catalogDropâasync catalogDrop(name: string): Promise<void>Drop a catalog by name.
method catalogVersion
Section titled âmethod catalogVersionâasync catalogVersion( attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData,): Promise<number>Get the current catalog version number.
method transactionBegin
Section titled âmethod transactionBeginâasync transactionBegin(attachOpaqueData: AttachOpaqueData): Promise<Uint8Array>Begin a new transaction. Returns the transaction ID.
method transactionCommit
Section titled âmethod transactionCommitâasync transactionCommit( attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData,): Promise<void>Commit a transaction.
method transactionRollback
Section titled âmethod transactionRollbackâasync transactionRollback( attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData,): Promise<void>Rollback a transaction.
method schemas
Section titled âmethod schemasâasync schemas( attachOpaqueData: AttachOpaqueData, transactionOpaqueData?: TransactionOpaqueData,): Promise<SchemaInfo[]>List schemas in an attached catalog.
method schemaGet
Section titled âmethod schemaGetâasync schemaGet( attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<SchemaInfo | null>Get a schema by name, or null if not found.
method schemaCreate
Section titled âmethod schemaCreateâasync schemaCreate( attachOpaqueData: AttachOpaqueData, name: string, opts?:Create a new schema.
method schemaDrop
Section titled âmethod schemaDropâasync schemaDrop( attachOpaqueData: AttachOpaqueData, name: string, ignoreNotFound?: boolean, cascade?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Drop a schema by name.
method schemaContentsTables
Section titled âmethod schemaContentsTablesâasync schemaContentsTables( attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<TableInfo[]>List tables in a schema.
method schemaContentsViews
Section titled âmethod schemaContentsViewsâasync schemaContentsViews( attachOpaqueData: AttachOpaqueData, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<ViewInfo[]>List views in a schema.
method schemaContentsFunctions
Section titled âmethod schemaContentsFunctionsâasync schemaContentsFunctions( attachOpaqueData: AttachOpaqueData, name: string, type: CatalogFunctionType, transactionOpaqueData?: TransactionOpaqueData,): Promise<FunctionInfo[]>List functions in a schema, filtered by type.
method tableGet
Section titled âmethod tableGetâasync tableGet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<TableInfo | null>Get a table by name, or null if not found.
method tableCreate
Section titled âmethod tableCreateâasync tableCreate( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columns: Uint8Array, onConflict: OnCreateConflict, notNullConstraints?: number[], uniqueConstraints?: number[][], checkConstraints?: string[], transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Create a new table.
method tableDrop
Section titled âmethod tableDropâasync tableDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, ignoreNotFound?: boolean, cascade?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Drop a table by name.
method tableScanFunctionGet
Section titled âmethod tableScanFunctionGetâasync tableScanFunctionGet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, atUnit?: string | null, atValue?: string | null, transactionOpaqueData?: TransactionOpaqueData,): Promise<ScanFunctionResult>Get the scan function for a table â tells DuckDB which function to call
to read the table data (e.g. read_parquet with a path argument). Used
by the VGI extension during query planning.
method tableCommentSet
Section titled âmethod tableCommentSetâasync tableCommentSet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, comment?: string | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Set or clear the comment on a table.
method tableRename
Section titled âmethod tableRenameâasync tableRename( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, newName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Rename a table.
method tableColumnAdd
Section titled âmethod tableColumnAddâasync tableColumnAdd( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, columnType: string, defaultValue?: string | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Add a column to a table.
method tableColumnDrop
Section titled âmethod tableColumnDropâasync tableColumnDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Drop a column from a table.
method tableColumnRename
Section titled âmethod tableColumnRenameâasync tableColumnRename( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, newName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Rename a column in a table.
method tableColumnDefaultSet
Section titled âmethod tableColumnDefaultSetâasync tableColumnDefaultSet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, defaultValue: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Set the default value for a column.
method tableColumnDefaultDrop
Section titled âmethod tableColumnDefaultDropâasync tableColumnDefaultDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Remove the default value from a column.
method tableColumnTypeChange
Section titled âmethod tableColumnTypeChangeâasync tableColumnTypeChange( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnDefinition: Uint8Array, expression?: string | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Change the type of a column.
columnDefinition is a serialized Arrow Schema with a single field whose
name identifies the target column and whose type is the new column type.
expression is an optional SQL expression used to convert existing values.
method tableNotNullSet
Section titled âmethod tableNotNullSetâasync tableNotNullSet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Set a NOT NULL constraint on a column.
method tableNotNullDrop
Section titled âmethod tableNotNullDropâasync tableNotNullDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, columnName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Remove a NOT NULL constraint from a column.
method viewGet
Section titled âmethod viewGetâasync viewGet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<ViewInfo | null>Get a view by name, or null if not found.
method viewCreate
Section titled âmethod viewCreateâasync viewCreate( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, definition: string, onConflict: OnCreateConflict, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Create a new view.
method viewDrop
Section titled âmethod viewDropâasync viewDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, ignoreNotFound?: boolean, cascade?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Drop a view by name.
method viewRename
Section titled âmethod viewRenameâasync viewRename( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, newName: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Rename a view.
method viewCommentSet
Section titled âmethod viewCommentSetâasync viewCommentSet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, comment?: string | null, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Set or clear the comment on a view.
method macroGet
Section titled âmethod macroGetâasync macroGet( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, transactionOpaqueData?: TransactionOpaqueData,): Promise<MacroInfo | null>Get a macro by name, or null if not found.
method schemaContentsMacros
Section titled âmethod schemaContentsMacrosâasync schemaContentsMacros( attachOpaqueData: AttachOpaqueData, name: string, type: CatalogMacroType, transactionOpaqueData?: TransactionOpaqueData,): Promise<MacroInfo[]>List macros in a schema, filtered by type.
method macroCreate
Section titled âmethod macroCreateâasync macroCreate( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, macroType: MacroType, parameters: string[], definition: string, onConflict: OnCreateConflict, parameterDefaultValues?: Uint8Array | null, argumentsSchema?: Uint8Array | null, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Create a new macro.
method macroDrop
Section titled âmethod macroDropâasync macroDrop( attachOpaqueData: AttachOpaqueData, schemaName: string, name: string, ignoreNotFound?: boolean, transactionOpaqueData?: TransactionOpaqueData,): Promise<void>Drop a macro by name.
method close
Section titled âmethod closeâclose(): voidClose the underlying RPC connection.
class VgiClientError
Section titled âclass VgiClientErrorâexport class VgiClientError extends ErrorDescription
Error thrown by VgiClient when an RPC call fails or returns unexpected data.
Properties
property remoteTraceback
Section titled âproperty remoteTracebackâreadonly remoteTraceback?: string;Remote traceback from the worker, when an RpcError carried one.
property errorType
Section titled âproperty errorTypeâreadonly errorType?: string;Underlying error type from the worker (e.g. âValueErrorâ), when known.
interface VgiClientOptions
Section titled âinterface VgiClientOptionsâexport interface VgiClientOptionsDescription
Options for constructing a VgiClient.
Fields
attachOpaqueDataUint8ArrayoptionalPre-existing attach ID to bind this client to a specific catalog.