The Query Processor Store caches resolved Tables and Fields for the duration of a query execution. Certain middleware handles resolving things like the query's source Table and any Fields that are referenced in a query, and saves the referenced objects in the store; other middleware and driver-specific query processor implementations use functions in the store to fetch those objects as needed.
For example, a driver might be converting a Field ID clause (e.g. [:field-id 10]
) to its native query language. It
can fetch the underlying Metabase FieldInstance by calling field
:
(qp.store/field 10) ;; get Field 10
Of course, it would be entirely possible to call (Field 10)
every time you needed information about that Field,
but fetching all Fields in a single pass and storing them for reuse is dramatically more efficient than fetching
those Fields potentially dozens of times in a single query execution.
The Query Processor Store caches resolved Tables and Fields for the duration of a query execution. Certain middleware handles resolving things like the query's source Table and any Fields that are referenced in a query, and saves the referenced objects in the store; other middleware and driver-specific query processor implementations use functions in the store to fetch those objects as needed. For example, a driver might be converting a Field ID clause (e.g. `[:field-id 10]`) to its native query language. It can fetch the underlying Metabase FieldInstance by calling `field`: (qp.store/field 10) ;; get Field 10 Of course, it would be entirely possible to call `(Field 10)` every time you needed information about that Field, but fetching all Fields in a single pass and storing them for reuse is dramatically more efficient than fetching those Fields potentially dozens of times in a single query execution.
(database)
Inputs: [] Returns: DatabaseInstanceWithRequiredStoreKeys
Fetch the Database referenced by the current query from the QP Store. Throws an Exception if valid item is not returned.
Inputs: [] Returns: DatabaseInstanceWithRequiredStoreKeys Fetch the Database referenced by the current query from the QP Store. Throws an Exception if valid item is not returned.
(do-with-new-store f)
Execute f
with a freshly-bound *store*
.
Execute `f` with a freshly-bound `*store*`.
(fetch-and-store-database! database-id)
Inputs: [database-id :- su/IntGreaterThanZero]
Fetch the Database this query will run against from the application database, and store it in the QP Store for the duration of the current query execution. If Database has already been fetched, this function will no-op. Throws an Exception if Table does not exist.
Inputs: [database-id :- su/IntGreaterThanZero] Fetch the Database this query will run against from the application database, and store it in the QP Store for the duration of the current query execution. If Database has already been fetched, this function will no-op. Throws an Exception if Table does not exist.
(fetch-and-store-fields! field-ids)
Inputs: [field-ids :- IDs]
Fetch Field(s) from the application database, and store them in the QP Store for the duration of the current query execution. If Field(s) have already been fetched, this function will no-op. Throws an Exception if Field(s) do not exist.
Inputs: [field-ids :- IDs] Fetch Field(s) from the application database, and store them in the QP Store for the duration of the current query execution. If Field(s) have already been fetched, this function will no-op. Throws an Exception if Field(s) do not exist.
(fetch-and-store-tables! table-ids)
Inputs: [table-ids :- IDs]
Fetch Table(s) from the application database, and store them in the QP Store for the duration of the current query execution. If Table(s) have already been fetched, this function will no-op. Throws an Exception if Table(s) do not exist.
Inputs: [table-ids :- IDs] Fetch Table(s) from the application database, and store them in the QP Store for the duration of the current query execution. If Table(s) have already been fetched, this function will no-op. Throws an Exception if Table(s) do not exist.
(field field-id)
Inputs: [field-id :- su/IntGreaterThanZero] Returns: FieldInstanceWithRequiredStorekeys
Fetch Field with field-id
from the QP Store. Throws an Exception if valid item is not returned.
Inputs: [field-id :- su/IntGreaterThanZero] Returns: FieldInstanceWithRequiredStorekeys Fetch Field with `field-id` from the QP Store. Throws an Exception if valid item is not returned.
(initialized?)
Is the QP store currently initialized?
Is the QP store currently initialized?
(store-field! field)
Inputs: [field :- FieldInstanceWithRequiredStorekeys]
Store a field
in the QP Store for the duration of the current query execution. Throws an Exception if field is
invalid or doesn't have all required keys.
Inputs: [field :- FieldInstanceWithRequiredStorekeys] Store a `field` in the QP Store for the duration of the current query execution. Throws an Exception if field is invalid or doesn't have all required keys.
(store-table! table)
Inputs: [table :- TableInstanceWithRequiredStoreKeys]
Store a table
in the QP Store for the duration of the current query execution. Throws an Exception if table is
invalid or doesn't have all required keys.
Inputs: [table :- TableInstanceWithRequiredStoreKeys] Store a `table` in the QP Store for the duration of the current query execution. Throws an Exception if table is invalid or doesn't have all required keys.
(table table-id)
Inputs: [table-id :- su/IntGreaterThanZero] Returns: TableInstanceWithRequiredStoreKeys
Fetch Table with table-id
from the QP Store. Throws an Exception if valid item is not returned.
Inputs: [table-id :- su/IntGreaterThanZero] Returns: TableInstanceWithRequiredStoreKeys Fetch Table with `table-id` from the QP Store. Throws an Exception if valid item is not returned.
(with-store & body)
Execute body
with a freshly-bound QP *store*
. The store
middleware takes care of setting up a fresh store for
each query execution; you should have no need to use this macro yourself outside of that namespace.
Execute `body` with a freshly-bound QP `*store*`. The `store` middleware takes care of setting up a fresh store for each query execution; you should have no need to use this macro yourself outside of that namespace.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close