pub struct Database { /* private fields */ }Expand description
A connection to a couchbase-lite database.
Implementations§
Source§impl Database
impl Database
pub fn open_named(name: &str, cfg: DatabaseConfig<'_>) -> Result<Self, Error>
pub fn open_with_flags(path: &Path, flags: DatabaseFlags) -> Result<Self, Error>
Sourcepub fn transaction<'a>(&'a mut self) -> Result<Transaction<'a>, Error>
pub fn transaction<'a>(&'a mut self) -> Result<Transaction<'a>, Error>
Begin a new transaction, the transaction defaults to rolling back
when it is dropped. If you want the transaction to commit,
you must call Transaction::commit
Sourcepub fn document_count(&self) -> u64
pub fn document_count(&self) -> u64
Returns the number of (undeleted) documents in the database
Sourcepub fn get_existing(&self, doc_id: &str) -> Result<Document, Error>
pub fn get_existing(&self, doc_id: &str) -> Result<Document, Error>
Return existing document from database
Sourcepub fn query<'a>(&'a self, query_json: &str) -> Result<Query<'a>, Error>
pub fn query<'a>(&'a self, query_json: &str) -> Result<Query<'a>, Error>
Compiles a query from an expression given as JSON. The expression is a predicate that describes which documents should be returned. A separate, optional sort expression describes the ordering of the results.
Sourcepub fn n1ql_query<'a>(&'a self, query: &str) -> Result<Query<'a>, Error>
pub fn n1ql_query<'a>(&'a self, query: &str) -> Result<Query<'a>, Error>
Compiles a query from an expression given as N1QL.
Sourcepub fn enumerate_all_docs<'a>(
&'a self,
flags: DocEnumeratorFlags,
) -> Result<DocEnumerator<'a>, Error>
pub fn enumerate_all_docs<'a>( &'a self, flags: DocEnumeratorFlags, ) -> Result<DocEnumerator<'a>, Error>
Creates an enumerator ordered by docID.
Sourcepub fn register_observer<F>(&mut self, callback_f: F) -> Result<(), Error>
pub fn register_observer<F>(&mut self, callback_f: F) -> Result<(), Error>
Register a database observer, with a callback that will be invoked after the database
changes. The callback will be called once, after the first change. After that it won’t
be called again until all of the changes have been read by calling Database::observed_changes.
Sourcepub fn clear_observers(&mut self)
pub fn clear_observers(&mut self)
Remove all database observers
Sourcepub fn observed_changes<'a>(&'a mut self) -> ObserverdChangesIter<'a>
pub fn observed_changes<'a>(&'a mut self) -> ObserverdChangesIter<'a>
Get observed changes for this database
Sourcepub fn init_socket_impl(handle: Handle)
pub fn init_socket_impl(handle: Handle)
Intialize socket implementation for replication (builtin couchbase-lite websocket library)
Get shared “fleece” encoder, &mut self to make possible
exists only one session
Sourcepub fn get_indexes(
&self,
) -> Result<impl FallibleStreamingIterator<Item = IndexInfo, Error = Error>, Error>
pub fn get_indexes( &self, ) -> Result<impl FallibleStreamingIterator<Item = IndexInfo, Error = Error>, Error>
Returns the names of all indexes in the database
Sourcepub fn create_index(
&mut self,
index_name: &str,
expression_json: &str,
index_type: IndexType,
index_options: Option<IndexOptions<'_>>,
) -> Result<(), Error>
pub fn create_index( &mut self, index_name: &str, expression_json: &str, index_type: IndexType, index_options: Option<IndexOptions<'_>>, ) -> Result<(), Error>
Creates a database index, of the values of specific expressions across all documents. The name is used to identify the index for later updating or deletion; if an index with the same name already exists, it will be replaced unless it has the exact same expressions. Note: If some documents are missing the values to be indexed, those documents will just be omitted from the index. It’s not an error.