Skip to content

QueryController

Official

Responsible for executing the Bases query and evaluating filters and formulas. Notifies views of updated results.

Import:

import { QueryController } from 'obsidian';

Signature:

export class QueryController extends Component

Extends: Component

Constructor

new QueryController(app: App, plugin: BasesPluginInstance, containerEl: HTMLElement, currentFile?: TFile | null | undefined)

Constructor.

To get the constructor instance, use getQueryControllerConstructor from obsidian-typings/implementations.

Properties

Property Type Description
_children Component[] Child Components attached to current component, will be unloaded on unloading parent component.
(Inherited from Component)
_events EventRef[] Events that are attached to the current component, will be detached on unloading parent component.
(Inherited from Component)
_loaded boolean Whether the component and its children are loaded.
(Inherited from Component)
app App The app instance.
ctx BasesContext | null The current evaluation context, or null if none has been built yet.
currentFile null | TFile The file the query is evaluated against, or null if none.
error null | string The category of the currently displayed error (e.g. 'query' or 'view'), or null if none.
errorEl HTMLDivElement The element that displays errors in place of the view.
errors Set<string> The error messages collected during the current query run.
events Events The event registry, emitting 'view-changed' when the active view changes.
filterMenu BasesFilterMenu The filter menu.
initialScan boolean Whether the initial scan of the query results is in progress.
mockContext BasesMockContext The mock context used to evaluate identifiers and resolve widget types.
newItemMenu BasesNewItemMenu The new item menu.
plugin BasesPluginInstance The Bases plugin instance.
propertyMenu BasesPropertyMenu The property menu.
query BasesQuery | null The current query, or null if none is set.
queryState null | string A serialized snapshot of the last-run query state, used to skip redundant re-runs, or null when cleared.
queue BasesQueryQueue The scan queue that streams vault files into the query.
relevantProperties Set<string> The lowercased property keys relevant to the current results.
requestNotifyView Debouncer<[], void> Debounced QueryController.notifyView.
results Map<TFile, BasesEntry> The recorded result entries, keyed by file.
resultsMenu BasesResultsMenu The results menu.
searchMenu BasesSearchMenu The search menu.
searchQuery null | string The current search query, or null if none is set.
sortMenu BasesSortMenu The sort menu.
view BasesView | null The active Bases view, or null if none.
viewContainerEl HTMLDivElement The container element that hosts the active view.
viewEstates Record<string, unknown> Per-view ephemeral state, keyed by view name.
viewHeaderEl HTMLDivElement The view header (toolbar) element.
viewMenu BasesViewMenu The view menu.
viewName string The name of the currently selected view.

Methods

Method Returns Description
addChild(component) T Adds a child component, loading it if this component is loaded.
(Inherited from Component)
addResult(file, entry) void Records a query result entry for a file.
applySearchQuery(entries, order) BasesEntry[] Filters entries by the current search query.
buildBasesContext(filters?) BasesContext Builds the Bases evaluation context from the query's filters and formulas.
clear() void Clears the current query and view state.
clearError() void Clears the currently displayed error.
displayError(type, error) void Displays an error in place of the view.
evaluateRelevantProperties(entries) void Pre-evaluates the properties relevant to the given entries.
getActiveBasesViewOfType(type) null | T Gets the active Bases view if it is an instance of the given type.
getCurrentFile() null | TFile Gets the current file the query is evaluated against.
getEditorLanguageSupport() EditorLanguageSupport Gets the editor language support used for the query editor.
getEphemeralState() QueryControllerEphemeralState Gets the controller's ephemeral state.
getProperties() BasesPropertyId[] Gets the property identifiers available to the query.
getQueryViewNames() string[] Gets the names of the views defined in the query.
getSearchQuery() null | string Gets the current search query string.
getViewConfig() BasesViewConfig Gets the config for the currently selected view.
getWidgetForIdent(ident) string Gets the widget type identifier for a property identifier.
load() void Load this component and its children.
(Inherited from Component)
notifyView() void Notifies the active view of updated results.
onConfigChanged(key) void Handles a config change.
onload() void Override this to load your component.
(Inherited from Component)
onResize() void Handles a resize of the view container.
onunload() void Override this to unload your component
(Inherited from Component)
promptForAddView() void Prompts the user to add a new view.
register(cb) void Registers a callback to be called when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading
(Inherited from Component)
registerDomEvent(el, type, callback, options?) void Registers a DOM event to be detached when unloading
(Inherited from Component)
registerEvent(eventRef) void Registers an event to be detached when unloading.
(Inherited from Component)
registerInterval(id) number Registers an interval (from setInterval) to be cancelled when unloading. Use window.setInterval instead of setInterval to avoid TypeScript confusing between NodeJS vs Browser API
(Inherited from Component)
registerScopeEvent(keymapEventHandler) void Register a scope keymap event handler to be removed on unload.
(Inherited from Component)
removeChild(component) T Removes a child component, unloading it.
(Inherited from Component)
removeResult(file) void Removes a previously recorded result entry for a file.
runQuery(context) void Runs the query against the given context.
selectView(viewName) void Selects the view with the given name.
setEphemeralState(state) void Sets the controller's ephemeral state.
setQuery(query) void Sets the query, or displays an error if an Error is given.
setQueryAndView(query, viewName) void Sets both the query and the selected view name.
startLoader() void Starts the loading indicator.
stopLoader() void Stops the loading indicator.
unload() void Override this to unload your component.
(Inherited from Component)
update() void Re-evaluates the query for the current view.
updateCurrentFile(file) void Updates the current file and re-runs the query if needed.
updateSearchQuery(searchQuery) void Updates the search query and re-notifies the view if it changed.

Links to this page: