Skip to content

@sqlrooms/mosaic / vg / Coordinator

Class: Coordinator

A Mosaic Coordinator manages all database communication for clients and handles selection updates. The Coordinator also performs optimizations including query caching, consolidation, and pre-aggregation.

Constructors

Constructor

new Coordinator(db?, options?): Coordinator

Parameters

ParameterTypeDescription
db?ConnectorDatabase connector. Defaults to a web socket connection.
options?{ logger?: Logger | null; manager?: QueryManager; cache?: boolean; consolidate?: boolean; preagg?: PreAggregateOptions; }Coordinator options.
options.logger?Logger | nullThe logger to use, defaults to console.
options.manager?QueryManagerThe query manager to use.
options.cache?booleanBoolean flag to enable/disable query caching.
options.consolidate?booleanBoolean flag to enable/disable query consolidation.
options.preagg?PreAggregateOptionsOptions for the Pre-aggregator.

Returns

Coordinator

Properties

PropertyModifierType
managerpublicQueryManager
preaggregatorpublicPreAggregator
clientspublicSet<MosaicClient>
filterGroupspublicMap<Selection, FilterGroupEntry>
_loggerprotectedLogger

Methods

clear()

clear(options?): void

Clear the coordinator state.

Parameters

ParameterTypeDescription
options?{ clients?: boolean; cache?: boolean; }Options object.
options.clients?booleanIf true, disconnect all clients.
options.cache?booleanIf true, clear the query cache.

Returns

void


databaseConnector()

Call Signature

databaseConnector(): Connector | null

Get or set the database connector.

Returns

Connector | null

The current database connector.

Call Signature

databaseConnector(db): Connector

Get or set the database connector.

Parameters
ParameterTypeDescription
dbConnectorThe database connector to use.
Returns

Connector

The current database connector.


logger()

logger(logger?): Logger

Get or set the logger.

Parameters

ParameterTypeDescription
logger?Logger | nullThe logger to use.

Returns

Logger

The current logger


cancel()

cancel(requests): void

Cancel previously submitted query requests. These queries will be canceled if they are queued but have not yet been submitted.

Parameters

ParameterTypeDescription
requestsQueryResult<unknown>[]An array of query result objects, such as those returned by the query method.

Returns

void


exec()

exec(query, options?): QueryResult

Issue a query for which no result (return value) is needed.

Parameters

ParameterTypeDescription
queryMaybeArray<QueryType>The query or an array of queries. Each query should be either a Query builder object or a SQL string.
options?{ priority?: number; }An options object.
options.priority?numberThe query priority, defaults to Priority.Normal.

Returns

QueryResult

A query result promise.


query()

Call Signature

query(query, options?): QueryResult<Table<TypeMap>>

Issue a query to the backing database. The submitted query may be consolidate with other queries and its results may be cached.

Parameters
ParameterTypeDescription
queryQueryTypeThe query as either a Query builder object or a SQL string.
options?{[key: string]: unknown; type?: "arrow"; cache?: boolean; persist?: boolean; priority?: number; }An options object.
options.type?"arrow"The query result format type.
options.cache?booleanIf true, cache the query result client-side within the QueryManager.
options.persist?booleanIf true, request the database server to persist a cached query server-side.
options.priority?numberThe query priority, defaults to Priority.Normal.
Returns

QueryResult<Table<TypeMap>>

A query result promise.

Call Signature

query(query, options?): QueryResult<unknown>

Issue a query to the backing database. The submitted query may be consolidate with other queries and its results may be cached.

Parameters
ParameterTypeDescription
queryQueryTypeThe query as either a Query builder object or a SQL string.
options?{[key: string]: unknown; type?: "json"; cache?: boolean; persist?: boolean; priority?: number; }An options object.
options.type?"json"The query result format type.
options.cache?booleanIf true, cache the query result client-side within the QueryManager.
options.persist?booleanIf true, request the database server to persist a cached query server-side.
options.priority?numberThe query priority, defaults to Priority.Normal.
Returns

QueryResult<unknown>

A query result promise.


prefetch()

Call Signature

prefetch(query, options?): QueryResult<Table<TypeMap>>

Issue a query to prefetch data for later use. The query result is cached for efficient future access.

Parameters
ParameterTypeDescription
queryQueryTypeThe query as either a Query builder object or a SQL string.
options?{[key: string]: unknown; type?: "arrow"; }An options object.
options.type?"arrow"The query result format type.
Returns

QueryResult<Table<TypeMap>>

A query result promise.

Call Signature

prefetch(query, options?): QueryResult<unknown>

Issue a query to prefetch data for later use. The query result is cached for efficient future access.

Parameters
ParameterTypeDescription
queryQueryTypeThe query as either a Query builder object or a SQL string.
options?{[key: string]: unknown; type?: "json"; }An options object.
options.type?"json"The query result format type.
Returns

QueryResult<unknown>

A query result promise.


updateClient()

updateClient(client, query, priority?): Promise<unknown>

Update client data by submitting the given query and returning the() data (or error) to the client.

Parameters

ParameterTypeDescription
clientMosaicClientA Mosaic client.
queryQueryTypeThe data query.
priority?numberThe query priority.

Returns

Promise<unknown>

A Promise that resolves upon completion of the update.


requestQuery()

requestQuery(client, query?): Promise<unknown>

Issue a query request for a client. If the query is null or undefined, the client is simply updated. Otherwise updateClient is called. As a side effect, this method clears the current preaggregator state.

Parameters

ParameterTypeDescription
clientMosaicClientThe client to update.
query?QueryType | nullThe query to issue.

Returns

Promise<unknown>


connect()

connect(client): void

Connect a client to the coordinator. Throws an error if the client is already connected.

Parameters

ParameterTypeDescription
clientMosaicClientThe Mosaic client to connect.

Returns

void


disconnect()

disconnect(client): void

Disconnect a client from the coordinator. This method has no effect if the client is already disconnected.

Parameters

ParameterTypeDescription
clientMosaicClientThe Mosaic client to disconnect.

Returns

void