Skip to main content

@terascope/data-mate / teal-frame/database

teal-frame/database

Functions​

closeDuckDatabase()​

closeDuckDatabase(database?): Promise<void>

Defined in: data-mate/src/teal-frame/database.ts:93

Closes a cached database and removes it from the cache. Intended for test teardown; a process that is exiting does not need to call it.

Parameters​

ParameterTypeDefault value
databasestring':memory:'

Returns​

Promise<void>


configureDuckDatabase()​

configureDuckDatabase(options?): Promise<void>

Defined in: data-mate/src/teal-frame/database.ts:45

Opens or reconfigures a database, and resolves once the settings are applied.

Call it once at startup, for example to give DuckDB a directory to spill to: configureDuckDatabase({ tempDirectory: '/var/tmp/duck', memoryLimit: '48GB' }). Calling it on a database that is already open updates the settings in place.

Parameters​

ParameterType
optionsDuckDatabaseOptions

Returns​

Promise<void>


getContext()​

getContext(database?): Promise<DuckContext>

Defined in: data-mate/src/teal-frame/database.ts:13

Returns the context for a database path, creating it on first use and caching it per path.

:memory: is the process-wide default. Any other path is a file-backed database, which is also how a test gets an isolated catalog.

Parameters​

ParameterTypeDefault value
databasestring':memory:'

Returns​

Promise<DuckContext>


registeredFunctionCount()​

registeredFunctionCount(database?): Promise<number>

Defined in: data-mate/src/teal-frame/database.ts:85

The number of scalar functions registered on a database.

DuckDB cannot unregister a function, so this grows with the functions and data types in use (never with their arguments; see scalar-function.ts). A long-running process may want to report it as a metric.

Parameters​

ParameterType
database?string

Returns​

Promise<number>


registerScalarFunction()​

registerScalarFunction(spec): Promise<string>

Defined in: data-mate/src/teal-frame/database.ts:70

Registers a scalar function (UDF) so SQL can call a data-mate function's JavaScript implementation.

This is how a data-mate function without a native SQL translation runs inside a query. Calling the JavaScript implementation guarantees the same results as DataFrame, whereas DuckDB's own casts and functions often differ from it on edge cases.

Registration is instance-wide, so the function is available to every frame and every stream on that database. Returns the function's name.

Parameters​

ParameterType
specScalarFunctionSpec & object

Returns​

Promise<string>