pub struct Collection {
pub name: String,
pub change_sender: Arc<Sender<ChangeEvent>>,
/* private fields */
}Expand description
Represents a collection of documents backed by RocksDB
Fields§
§name: StringCollection name (column family name)
change_sender: Arc<Sender<ChangeEvent>>Broadcast channel for real-time change events
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn put_blob_chunk(
&self,
key: &str,
chunk_index: u32,
data: &[u8],
) -> DbResult<()>
pub fn put_blob_chunk( &self, key: &str, chunk_index: u32, data: &[u8], ) -> DbResult<()>
Store a blob chunk
Sourcepub fn get_blob_chunk(
&self,
key: &str,
chunk_index: u32,
) -> DbResult<Option<Vec<u8>>>
pub fn get_blob_chunk( &self, key: &str, chunk_index: u32, ) -> DbResult<Option<Vec<u8>>>
Get a blob chunk
Sourcepub fn delete_blob_data(&self, key: &str) -> DbResult<()>
pub fn delete_blob_data(&self, key: &str) -> DbResult<()>
Delete all blob chunks for a document
Sourcepub fn blob_stats(&self) -> DbResult<(usize, u64)>
pub fn blob_stats(&self) -> DbResult<(usize, u64)>
Get blob statistics for this collection
Source§impl Collection
impl Collection
Sourcepub fn flush_stats(&self)
pub fn flush_stats(&self)
Flush count to disk if dirty (call periodically or on shutdown)
Sourcepub fn flush_stats_throttled(&self)
pub fn flush_stats_throttled(&self)
Flush count to disk if dirty AND at least 1 second has passed since last flush Use this during bulk operations to avoid excessive disk writes
Sourcepub fn stats(&self) -> CollectionStats
pub fn stats(&self) -> CollectionStats
Get usage statistics
Sourcepub fn disk_usage(&self) -> DiskUsage
pub fn disk_usage(&self) -> DiskUsage
Get disk usage statistics for this collection
Sourcepub fn set_shard_config(&self, config: &CollectionShardConfig) -> DbResult<()>
pub fn set_shard_config(&self, config: &CollectionShardConfig) -> DbResult<()>
Set sharding configuration for this collection
Sourcepub fn get_shard_config(&self) -> Option<CollectionShardConfig>
pub fn get_shard_config(&self) -> Option<CollectionShardConfig>
Get sharding configuration for this collection (None if not sharded)
Sourcepub fn set_shard_table(&self, table: &ShardTable) -> DbResult<()>
pub fn set_shard_table(&self, table: &ShardTable) -> DbResult<()>
Save shard table to storage (persisting assignments)
Sourcepub fn get_stored_shard_table(&self) -> Option<ShardTable>
pub fn get_stored_shard_table(&self) -> Option<ShardTable>
Load shard table from storage
Sourcepub fn is_sharded(&self) -> bool
pub fn is_sharded(&self) -> bool
Check if this collection is sharded
Sourcepub fn idx_entry_key(
index_name: &str,
values: &[Value],
doc_key: &str,
) -> Vec<u8> ⓘ
pub fn idx_entry_key( index_name: &str, values: &[Value], doc_key: &str, ) -> Vec<u8> ⓘ
Generate an index entry key: “idx:
Sourcepub fn geo_entry_key(index_name: &str, doc_key: &str) -> Vec<u8> ⓘ
pub fn geo_entry_key(index_name: &str, doc_key: &str) -> Vec<u8> ⓘ
Generate a geo entry key: “geo:
Sourcepub fn ft_term_key(index_name: &str, term: &str, doc_key: &str) -> Vec<u8> ⓘ
pub fn ft_term_key(index_name: &str, term: &str, doc_key: &str) -> Vec<u8> ⓘ
Generate a fulltext term mapping key: “ft_term:
Sourcepub fn ft_ngram_key(index_name: &str, ngram: &str, doc_key: &str) -> Vec<u8> ⓘ
pub fn ft_ngram_key(index_name: &str, ngram: &str, doc_key: &str) -> Vec<u8> ⓘ
Generate a fulltext n-gram mapping key: “ft:
Sourcepub fn blo_chunk_key(key: &str, chunk_index: usize) -> Vec<u8> ⓘ
pub fn blo_chunk_key(key: &str, chunk_index: usize) -> Vec<u8> ⓘ
Generate a blob chunk key: “blo:
Sourcepub fn ttl_expiry_key(
ttl_index_name: &str,
expiry_timestamp: u64,
doc_key: &str,
) -> Vec<u8> ⓘ
pub fn ttl_expiry_key( ttl_index_name: &str, expiry_timestamp: u64, doc_key: &str, ) -> Vec<u8> ⓘ
Build a TTL expiry index key: “ttl_exp:<ttl_index_name>:<expiry_ts>:<doc_key>” Sorted by (ttl_index_name, expiry_timestamp) for efficient range queries
Sourcepub fn ttl_expiry_prefix(ttl_index_name: &str) -> Vec<u8> ⓘ
pub fn ttl_expiry_prefix(ttl_index_name: &str) -> Vec<u8> ⓘ
Build a TTL expiry index prefix for a specific index: “doc:ttl_exp:<ttl_index_name>:”
Source§impl Collection
impl Collection
Sourcepub fn insert_no_index(&self, data: Value) -> DbResult<Document>
pub fn insert_no_index(&self, data: Value) -> DbResult<Document>
Insert a new document without updating indexes (for bulk loads)
Sourcepub fn update(&self, key: &str, data: Value) -> DbResult<Document>
pub fn update(&self, key: &str, data: Value) -> DbResult<Document>
Update a document with atomic document + index writes
Sourcepub fn update_with_rev(
&self,
key: &str,
expected_rev: &str,
data: Value,
) -> DbResult<Document>
pub fn update_with_rev( &self, key: &str, expected_rev: &str, data: Value, ) -> DbResult<Document>
Update a document with revision check (optimistic concurrency control)
Sourcepub fn delete(&self, key: &str) -> DbResult<()>
pub fn delete(&self, key: &str) -> DbResult<()>
Delete a document with atomic document + index removal
Sourcepub fn upsert_batch(&self, documents: Vec<(String, Value)>) -> DbResult<usize>
pub fn upsert_batch(&self, documents: Vec<(String, Value)>) -> DbResult<usize>
Batch upsert (insert or update) multiple documents - optimized for replication
Sourcepub fn delete_batch(&self, keys: Vec<String>) -> DbResult<usize>
pub fn delete_batch(&self, keys: Vec<String>) -> DbResult<usize>
Batch delete documents with atomic document + index removal
Sourcepub fn update_batch(
&self,
updates: &[(String, Value)],
) -> DbResult<Vec<Document>>
pub fn update_batch( &self, updates: &[(String, Value)], ) -> DbResult<Vec<Document>>
Batch update multiple documents with atomic document + index writes
Sourcepub fn insert_batch(&self, documents: Vec<Value>) -> DbResult<Vec<Document>>
pub fn insert_batch(&self, documents: Vec<Value>) -> DbResult<Vec<Document>>
Insert multiple documents with atomic batched write
Sourcepub fn scan(&self, limit: Option<usize>) -> Vec<Document>
pub fn scan(&self, limit: Option<usize>) -> Vec<Document>
Scan documents with an optional limit
Sourcepub fn recalculate_count(&self) -> usize
pub fn recalculate_count(&self) -> usize
Recalculate document count from storage
Sourcepub fn recount_documents(&self) -> usize
pub fn recount_documents(&self) -> usize
Recount documents from actual RocksDB data (slow but accurate)
Sourcepub fn prune_older_than(&self, timestamp_ms: u64) -> DbResult<usize>
pub fn prune_older_than(&self, timestamp_ms: u64) -> DbResult<usize>
Prune documents older than timestamp (for timeseries) The timestamp is in milliseconds since Unix epoch. This extracts the timestamp from UUIDv7 keys and deletes matching documents.
Source§impl Collection
impl Collection
Sourcepub fn get_all_fulltext_indexes(&self) -> Vec<FulltextIndex>
pub fn get_all_fulltext_indexes(&self) -> Vec<FulltextIndex>
Get all fulltext indexes
Sourcepub fn get_fulltext_index_for_field(&self, field: &str) -> Option<FulltextIndex>
pub fn get_fulltext_index_for_field(&self, field: &str) -> Option<FulltextIndex>
Get a fulltext index that covers a specific field
Sourcepub fn create_fulltext_index(
&self,
name: String,
fields: Vec<String>,
min_length: Option<usize>,
) -> DbResult<()>
pub fn create_fulltext_index( &self, name: String, fields: Vec<String>, min_length: Option<usize>, ) -> DbResult<()>
Create a fulltext index
Sourcepub fn drop_fulltext_index(&self, name: &str) -> DbResult<()>
pub fn drop_fulltext_index(&self, name: &str) -> DbResult<()>
Drop a fulltext index
Sourcepub fn list_fulltext_indexes(&self) -> Vec<FulltextIndex>
pub fn list_fulltext_indexes(&self) -> Vec<FulltextIndex>
List fulltext indexes
Sourcepub fn fulltext_search(
&self,
query: &str,
fields: Option<Vec<String>>,
limit: usize,
) -> DbResult<Vec<FulltextMatch>>
pub fn fulltext_search( &self, query: &str, fields: Option<Vec<String>>, limit: usize, ) -> DbResult<Vec<FulltextMatch>>
Perform a fulltext search
Source§impl Collection
impl Collection
Sourcepub fn get_all_geo_indexes(&self) -> Vec<GeoIndex>
pub fn get_all_geo_indexes(&self) -> Vec<GeoIndex>
Get all geo index metadata
Sourcepub fn create_geo_index(
&self,
name: String,
field: String,
) -> DbResult<GeoIndexStats>
pub fn create_geo_index( &self, name: String, field: String, ) -> DbResult<GeoIndexStats>
Create a geospatial index
Sourcepub fn drop_geo_index(&self, name: &str) -> DbResult<()>
pub fn drop_geo_index(&self, name: &str) -> DbResult<()>
Drop a geo index
Sourcepub fn list_geo_indexes(&self) -> Vec<GeoIndexStats>
pub fn list_geo_indexes(&self) -> Vec<GeoIndexStats>
List all geo indexes
Source§impl Collection
impl Collection
Sourcepub fn get_all_indexes(&self) -> Vec<Index>
pub fn get_all_indexes(&self) -> Vec<Index>
Get all index metadata
Sourcepub fn create_index(
&self,
name: String,
fields: Vec<String>,
index_type: IndexType,
unique: bool,
) -> DbResult<IndexStats>
pub fn create_index( &self, name: String, fields: Vec<String>, index_type: IndexType, unique: bool, ) -> DbResult<IndexStats>
Create an index on a field
Sourcepub fn drop_index(&self, name: &str) -> DbResult<()>
pub fn drop_index(&self, name: &str) -> DbResult<()>
Drop an index
Sourcepub fn list_indexes(&self) -> Vec<IndexStats>
pub fn list_indexes(&self) -> Vec<IndexStats>
List all indexes
Sourcepub fn rebuild_all_indexes(&self) -> DbResult<usize>
pub fn rebuild_all_indexes(&self) -> DbResult<usize>
Rebuild all indexes from existing documents Call this after bulk imports using insert_no_index()
Sourcepub fn index_documents(&self, docs: &[Document]) -> DbResult<usize>
pub fn index_documents(&self, docs: &[Document]) -> DbResult<usize>
Index only the provided documents (for incremental indexing)
Sourcepub fn get_index_stats(&self, name: &str) -> Option<IndexStats>
pub fn get_index_stats(&self, name: &str) -> Option<IndexStats>
Get index statistics
Sourcepub fn get_index_for_field(&self, field: &str) -> Option<Index>
pub fn get_index_for_field(&self, field: &str) -> Option<Index>
Get an index for a field
Sourcepub fn index_lookup_gt(
&self,
field: &str,
value: &Value,
) -> Option<Vec<Document>>
pub fn index_lookup_gt( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>
Lookup documents where field > value
Sourcepub fn index_lookup_gte(
&self,
field: &str,
value: &Value,
) -> Option<Vec<Document>>
pub fn index_lookup_gte( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>
Lookup documents where field >= value
Sourcepub fn index_lookup_lt(
&self,
field: &str,
value: &Value,
) -> Option<Vec<Document>>
pub fn index_lookup_lt( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>
Lookup documents where field < value
Sourcepub fn index_lookup_lte(
&self,
field: &str,
value: &Value,
) -> Option<Vec<Document>>
pub fn index_lookup_lte( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>
Lookup documents where field <= value
Sourcepub fn index_lookup_eq(
&self,
field: &str,
value: &Value,
) -> Option<Vec<Document>>
pub fn index_lookup_eq( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>
Lookup documents using index (equality)
Sourcepub fn index_lookup_eq_limit(
&self,
field: &str,
value: &Value,
limit: usize,
) -> Option<Vec<Document>>
pub fn index_lookup_eq_limit( &self, field: &str, value: &Value, limit: usize, ) -> Option<Vec<Document>>
Lookup documents using index (equality) with limit
Sourcepub fn index_sorted(
&self,
field: &str,
ascending: bool,
limit: Option<usize>,
) -> Option<Vec<Document>>
pub fn index_sorted( &self, field: &str, ascending: bool, limit: Option<usize>, ) -> Option<Vec<Document>>
Get documents sorted by indexed field
pub fn bloom_check(&self, index_name: &str, item: &str) -> bool
pub fn cuckoo_insert(&self, index_name: &str, item: &str)
pub fn cuckoo_delete(&self, index_name: &str, item: &str)
pub fn cuckoo_check(&self, index_name: &str, item: &str) -> bool
Source§impl Collection
impl Collection
Sourcepub fn get_cached_schema_validator(
&self,
) -> Result<Option<SchemaValidator>, DbError>
pub fn get_cached_schema_validator( &self, ) -> Result<Option<SchemaValidator>, DbError>
Get or create cached schema validator
Sourcepub fn set_json_schema(&self, schema: CollectionSchema) -> DbResult<()>
pub fn set_json_schema(&self, schema: CollectionSchema) -> DbResult<()>
Set JSON schema for collection validation Set JSON schema for collection validation
Sourcepub fn get_json_schema(&self) -> Option<CollectionSchema>
pub fn get_json_schema(&self) -> Option<CollectionSchema>
Get JSON schema
Sourcepub fn remove_json_schema(&self) -> DbResult<()>
pub fn remove_json_schema(&self) -> DbResult<()>
Remove JSON schema
Source§impl Collection
impl Collection
Sourcepub fn get_all_ttl_indexes(&self) -> Vec<TtlIndex>
pub fn get_all_ttl_indexes(&self) -> Vec<TtlIndex>
Get all TTL indexes
Sourcepub fn get_ttl_index(&self, name: &str) -> Option<TtlIndex>
pub fn get_ttl_index(&self, name: &str) -> Option<TtlIndex>
Get a TTL index by name
Sourcepub fn create_ttl_index(
&self,
name: String,
field: String,
expire_after_seconds: u64,
) -> DbResult<TtlIndexStats>
pub fn create_ttl_index( &self, name: String, field: String, expire_after_seconds: u64, ) -> DbResult<TtlIndexStats>
Create a TTL index
Sourcepub fn drop_ttl_index(&self, name: &str) -> DbResult<()>
pub fn drop_ttl_index(&self, name: &str) -> DbResult<()>
Drop a TTL index
Sourcepub fn list_ttl_indexes(&self) -> Vec<TtlIndexStats>
pub fn list_ttl_indexes(&self) -> Vec<TtlIndexStats>
List all TTL indexes
Sourcepub fn cleanup_expired_documents_for_ttl_index(
&self,
index: &TtlIndex,
) -> DbResult<usize>
pub fn cleanup_expired_documents_for_ttl_index( &self, index: &TtlIndex, ) -> DbResult<usize>
Cleanup expired documents for a specific TTL index using expiry index This is O(n) where n = expired documents (not all documents)
Sourcepub fn cleanup_all_expired_documents(&self) -> DbResult<usize>
pub fn cleanup_all_expired_documents(&self) -> DbResult<usize>
Cleanup all expired documents across all TTL indexes
Source§impl Collection
impl Collection
Sourcepub fn insert_tx(
&self,
tx: &mut Transaction,
_wal: &Arc<WalWriter>,
data: Value,
) -> DbResult<Document>
pub fn insert_tx( &self, tx: &mut Transaction, _wal: &Arc<WalWriter>, data: Value, ) -> DbResult<Document>
Insert a document within a transaction
Sourcepub fn update_tx(
&self,
tx: &mut Transaction,
_wal: &Arc<WalWriter>,
key: &str,
data: Value,
) -> DbResult<Document>
pub fn update_tx( &self, tx: &mut Transaction, _wal: &Arc<WalWriter>, key: &str, data: Value, ) -> DbResult<Document>
Update a document within a transaction
Source§impl Collection
impl Collection
Sourcepub fn get_all_vector_index_configs(&self) -> Vec<VectorIndexConfig>
pub fn get_all_vector_index_configs(&self) -> Vec<VectorIndexConfig>
Get all vector index configurations
Sourcepub fn get_vector_index(&self, name: &str) -> DbResult<Arc<VectorIndex>>
pub fn get_vector_index(&self, name: &str) -> DbResult<Arc<VectorIndex>>
Get vector index (loading it if necessary)
Sourcepub fn create_vector_index(
&self,
config: VectorIndexConfig,
) -> DbResult<VectorIndexStats>
pub fn create_vector_index( &self, config: VectorIndexConfig, ) -> DbResult<VectorIndexStats>
Create a vector index
Sourcepub fn drop_vector_index(&self, name: &str) -> DbResult<()>
pub fn drop_vector_index(&self, name: &str) -> DbResult<()>
Drop a vector index
Sourcepub fn list_vector_indexes(&self) -> Vec<VectorIndexStats>
pub fn list_vector_indexes(&self) -> Vec<VectorIndexStats>
List vector indexes
Sourcepub fn vector_search(
&self,
name: &str,
query: &[f32],
k: usize,
ef_search: Option<usize>,
) -> DbResult<Vec<VectorSearchResult>>
pub fn vector_search( &self, name: &str, query: &[f32], k: usize, ef_search: Option<usize>, ) -> DbResult<Vec<VectorSearchResult>>
Search similar vectors
Sourcepub fn vector_similarity(
&self,
name: &str,
query: Vec<f32>,
) -> DbResult<Vec<(String, f32)>>
pub fn vector_similarity( &self, name: &str, query: Vec<f32>, ) -> DbResult<Vec<(String, f32)>>
Calculate similarity between a vector and documents
Sourcepub fn quantize_vector_index(
&self,
name: &str,
quantization: VectorQuantization,
) -> DbResult<QuantizationStats>
pub fn quantize_vector_index( &self, name: &str, quantization: VectorQuantization, ) -> DbResult<QuantizationStats>
Quantize a vector index
Sourcepub fn dequantize_vector_index(&self, _name: &str) -> DbResult<()>
pub fn dequantize_vector_index(&self, _name: &str) -> DbResult<()>
Dequantize a vector index
Sourcepub fn persist_vector_indexes(&self) -> DbResult<()>
pub fn persist_vector_indexes(&self) -> DbResult<()>
Persist all in-memory vector indexes to disk
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Auto Trait Implementations§
impl Freeze for Collection
impl !RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl UnsafeUnpin for Collection
impl !UnwindSafe for Collection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more