Expose a catalog
Functions are callable, but a catalog lets the worker look like a database: users can query plain tables, inspect schemas and constraints, and use worker-defined views and macros.
using QueryFarm.Vgi.Catalog;
using QueryFarm.Vgi.Protocol;
namespace QueryFarm.Vgi.DocsExamples;
public static class CatalogExample
{
public static void Register(Worker worker, NumbersFunction numbers)
{
worker.RegisterCatalogTable(new CatalogTable
{
Name = "first_five",
SchemaName = "catalog",
Comment = "The integers zero through four",
ScanFunction = numbers,
ScanArguments = [5L],
});
worker.RegisterView(new CatalogView
{
Name = "evens",
SchemaName = "catalog",
Definition = "SELECT * FROM first_five WHERE n % 2 = 0",
Comment = "Even values from catalog.first_five",
});
worker.RegisterMacro(new CatalogMacro
{
Name = "triple",
SchemaName = "catalog",
MacroType = MacroType.Scalar,
Definition = "value * 3",
Parameters = ["value"],
Comment = "Multiply a value by three",
});
}
}
CatalogTable.ScanFunction is the recommended table shape. Its output schema is reused as the table
columns unless Columns is set explicitly, and ScanArguments / ScanNamedArguments bind fixed
values for that table.
SELECT * FROM demo.catalog.first_five;
SELECT * FROM demo.catalog.evens;
SELECT demo.catalog.triple(7);
CatalogTable can additionally declare comments, tags, defaults, generated columns, primary and
foreign keys, required filters, statistics, row IDs, writable handlers, time travel, or multi-branch
scans. Keep declarations internally consistent: a constraint names the table’s published columns,
and an advertised write operation needs the matching table-in/out function.
RegisterCatalogTable registers its ScanFunction as a callable table function. Do not separately
register the same instance under the same schema and name, or DuckDB will see duplicate overloads.