|
Couchbase Lite C++
Couchbase Lite C++ API
|
A database query. More...
#include <cbl++/Query.hh>
Classes | |
| class | Change |
| The change passed to a live query's listener callback, giving access to the updated results. More... | |
| class | ChangeListener |
| The token returned by Query::addChangeListener for a live query. More... | |
Public Member Functions | |
| Query (const Database &db, CBLQueryLanguage language, std::string_view queryString) | |
| Creates a new query by compiling the input string. | |
| std::vector< std::string > | columnNames () const |
| Returns the column names that will appear in the query results. | |
| void | setParameters (fleece::Dict parameters) |
| Assigns values to the query's parameters. | |
| fleece::Dict | parameters () const |
| Returns the query's current parameter bindings, if any. | |
| ResultSet | execute () |
| Runs the query, returning the results. | |
| std::string | explain () |
| Returns information about the query, including the translated SQLite form, and the search strategy. | |
| ChangeListener | addChangeListener (ListenerToken< Change >::Callback callback) |
| Registers a change listener callback to the query, turning it into a "live query" until the listener is removed (via ListenerToken::remove() ). | |
| Query () noexcept | |
| Constructs a null reference (one that points to no object). | |
| Query & | operator= (std::nullptr_t) |
| Releases the underlying object and resets this to a null reference. | |
| bool | valid () const |
| Returns true if this references an object, or false if it is a null reference. | |
| operator bool () const | |
| Returns true if this references an object (same as valid). | |
| bool | operator== (const Query &other) const |
| Returns true if both sides reference the same object, or are both null references. | |
| bool | operator!= (const Query &other) const |
| Returns true if the two sides reference different objects. | |
| CBLQuery *_Nullable | ref () const |
| Returns a pointer to the underlying C object (CBLQuery), or NULL if this is a null reference. | |
| Query (const Query &other) noexcept | |
Copy constructor: creates another reference to the same object as other. | |
| Query (Query &&other) noexcept | |
Move constructor: takes over the reference from other, leaving it a null reference. | |
| Query & | operator= (const Query &other) noexcept |
Copy assignment: replaces this reference with a reference to other's object. | |
| Query & | operator= (Query &&other) noexcept |
Move assignment: replaces this reference with other's, leaving other a null reference. | |
Protected Member Functions | |
| Query (CBLQuery *_Nullable ref) | |
| (Internal) Constructs a reference wrapping, and retaining, a C object pointer. | |
A database query.
|
inline |
Creates a new query by compiling the input string.
This is fast, but not instantaneous. If you need to run the same query many times, keep the Query object around instead of compiling it each time. If you need to run related queries with only some values different, create one query with placeholder parameter(s), and substitute the desired value(s) with Query::setParameters(fleece::Dict parameters) each time you run the query.
| db | The database the query runs against. |
| language | The query language |
| queryString | The query string. |
|
inlinenoexcept |
Constructs a null reference (one that points to no object).
|
inlineexplicitprotected |
(Internal) Constructs a reference wrapping, and retaining, a C object pointer.
|
inlinenoexcept |
Copy constructor: creates another reference to the same object as other.
|
inlinenoexcept |
Move constructor: takes over the reference from other, leaving it a null reference.
|
inlinenodiscard |
Registers a change listener callback to the query, turning it into a "live query" until the listener is removed (via ListenerToken::remove() ).
When the first change listener is added, the query will run (in the background) and notify the listener(s) of the results when ready. After that, it will run in the background after the database changes, and only notify the listeners when the result set changes.
| callback | The callback to be invoked. |
|
inline |
Returns the column names that will appear in the query results.
The column names are based on their expression in the SELECT... or WHAT: section of the query. A column that returns a property or property path will be named after that property. A column that returns an expression will have an automatically-generated name like $1. To give a column a custom name, use the AS syntax in the query. Every column is guaranteed to have a unique name.
|
inline |
Runs the query, returning the results.
|
inline |
Returns information about the query, including the translated SQLite form, and the search strategy.
You can use this to help optimize the query: the word SCAN in the strategy indicates a linear scan of the entire database, which should be avoided by adding an index. The strategy will also show which index(es), if any, are used.
|
inlineexplicit |
Returns true if this references an object (same as valid).
|
inline |
Returns true if the two sides reference different objects.
Copy assignment: replaces this reference with a reference to other's object.
Move assignment: replaces this reference with other's, leaving other a null reference.
|
inline |
Releases the underlying object and resets this to a null reference.
|
inline |
Returns true if both sides reference the same object, or are both null references.
|
inline |
Returns the query's current parameter bindings, if any.
|
inline |
Returns a pointer to the underlying C object (CBLQuery), or NULL if this is a null reference.
|
inline |
Assigns values to the query's parameters.
These values will be substited for those parameters whenever the query is executed, until they are next assigned.
Parameters are specified in the query source as e.g. $PARAM (N1QL) or ["$PARAM"] (JSON). In this example, the parameters dictionary to this call should have a key PARAM that maps to the value of the parameter.
| parameters | The parameters in the form of a Fleece Dict (dictionary) whose keys are the parameter names. (It's easiest to construct this by using the fleece::MutableDict) |
|
inline |
Returns true if this references an object, or false if it is a null reference.