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

PropertyTypeDescription
_childrenComponent[]Child Components attached to current component, will be unloaded on unloading parent component.
(Inherited from Component)
_eventsEventRef[]Events that are attached to the current component, will be detached on unloading parent component.
(Inherited from Component)
_loadedbooleanWhether the component and its children are loaded.
(Inherited from Component)
appAppThe app instance.
ctxBasesContext | nullThe current evaluation context, or null if none has been built yet.
currentFilenull | TFileThe file the query is evaluated against, or null if none.
errornull | stringThe category of the currently displayed error (e.g. 'query' or 'view'), or null if none.
errorElHTMLDivElementThe element that displays errors in place of the view.
errorsSet<string>The error messages collected during the current query run.
eventsEventsThe event registry, emitting 'view-changed' when the active view changes.
filterMenuBasesFilterMenuThe filter menu.
initialScanbooleanWhether the initial scan of the query results is in progress.
mockContextBasesMockContextThe mock context used to evaluate identifiers and resolve widget types.
newItemMenuBasesNewItemMenuThe new item menu.
pluginBasesPluginInstanceThe Bases plugin instance.
propertyMenuBasesPropertyMenuThe property menu.
queryBasesQuery | nullThe current query, or null if none is set.
queryStatenull | stringA serialized snapshot of the last-run query state, used to skip redundant re-runs, or null when cleared.
queueBasesQueryQueueThe scan queue that streams vault files into the query.
relevantPropertiesSet<string>The lowercased property keys relevant to the current results.
requestNotifyViewDebouncer<[], void>Debounced QueryController.notifyView.
resultsMap<TFile, BasesEntry>The recorded result entries, keyed by file.
resultsMenuBasesResultsMenuThe results menu.
searchMenuBasesSearchMenuThe search menu.
searchQuerynull | stringThe current search query, or null if none is set.
sortMenuBasesSortMenuThe sort menu.
viewBasesView | nullThe active Bases view, or null if none.
viewContainerElHTMLDivElementThe container element that hosts the active view.
viewEstatesRecord<string, unknown>Per-view ephemeral state, keyed by view name.
viewHeaderElHTMLDivElementThe view header (toolbar) element.
viewMenuBasesViewMenuThe view menu.
viewNamestringThe name of the currently selected view.

Methods

MethodReturnsDescription
addChild(component)TAdds a child component, loading it if this component is loaded.
(Inherited from Component)
addResult(file, entry)voidRecords a query result entry for a file.
applySearchQuery(entries, order)BasesEntry[]Filters entries by the current search query.
buildBasesContext(filters?)BasesContextBuilds the Bases evaluation context from the query's filters and formulas.
clear()voidClears the current query and view state.
clearError()voidClears the currently displayed error.
displayError(type, error)voidDisplays an error in place of the view.
evaluateRelevantProperties(entries)voidPre-evaluates the properties relevant to the given entries.
getActiveBasesViewOfType(type)null | TGets the active Bases view if it is an instance of the given type.
getCurrentFile()null | TFileGets the current file the query is evaluated against.
getEditorLanguageSupport()EditorLanguageSupportGets the editor language support used for the query editor.
getEphemeralState()QueryControllerEphemeralStateGets 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 | stringGets the current search query string.
getViewConfig()BasesViewConfigGets the config for the currently selected view.
getWidgetForIdent(ident)stringGets the widget type identifier for a property identifier.
load()voidLoad this component and its children.
(Inherited from Component)
notifyView()voidNotifies the active view of updated results.
onConfigChanged(key)voidHandles a config change.
onload()voidOverride this to load your component.
(Inherited from Component)
onResize()voidHandles a resize of the view container.
onunload()voidOverride this to unload your component
(Inherited from Component)
promptForAddView()voidPrompts the user to add a new view.
register(cb)voidRegisters a callback to be called when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading.
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
(Inherited from Component)
registerEvent(eventRef)voidRegisters an event to be detached when unloading.
(Inherited from Component)
registerInterval(id)numberRegisters 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)voidRegister a scope keymap event handler to be removed on unload.
(Inherited from Component)
removeChild(component)TRemoves a child component, unloading it.
(Inherited from Component)
removeResult(file)voidRemoves a previously recorded result entry for a file.
runQuery(context)voidRuns the query against the given context.
selectView(viewName)voidSelects the view with the given name.
setEphemeralState(state)voidSets the controller's ephemeral state.
setQuery(query)voidSets the query, or displays an error if an Error is given.
setQueryAndView(query, viewName)voidSets both the query and the selected view name.
startLoader()voidStarts the loading indicator.
stopLoader()voidStops the loading indicator.
unload()voidOverride this to unload your component.
(Inherited from Component)
update()voidRe-evaluates the query for the current view.
updateCurrentFile(file)voidUpdates the current file and re-runs the query if needed.
updateSearchQuery(searchQuery)voidUpdates the search query and re-notifies the view if it changed.

Links to this page: