Skip to main content

Collection

Struct Collection 

Source
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: String

Collection name (column family name)

§change_sender: Arc<Sender<ChangeEvent>>

Broadcast channel for real-time change events

Implementations§

Source§

impl Collection

Source

pub fn put_blob_chunk( &self, key: &str, chunk_index: u32, data: &[u8], ) -> DbResult<()>

Store a blob chunk

Source

pub fn get_blob_chunk( &self, key: &str, chunk_index: u32, ) -> DbResult<Option<Vec<u8>>>

Get a blob chunk

Source

pub fn delete_blob_data(&self, key: &str) -> DbResult<()>

Delete all blob chunks for a document

Source

pub fn blob_stats(&self) -> DbResult<(usize, u64)>

Get blob statistics for this collection

Source§

impl Collection

Source

pub fn new(name: String, db: Arc<DB>) -> Self

Create a new collection handle

Source

pub fn get_type(&self) -> String

Get collection type

Source

pub fn set_type(&self, type_: &str) -> DbResult<()>

Set collection type (persists to disk)

Source

pub fn flush_stats(&self)

Flush count to disk if dirty (call periodically or on shutdown)

Source

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

Source

pub fn compact(&self)

Compact the collection to remove tombstones and reclaim space

Source

pub fn stats(&self) -> CollectionStats

Get usage statistics

Source

pub fn disk_usage(&self) -> DiskUsage

Get disk usage statistics for this collection

Source

pub fn set_shard_config(&self, config: &CollectionShardConfig) -> DbResult<()>

Set sharding configuration for this collection

Source

pub fn get_shard_config(&self) -> Option<CollectionShardConfig>

Get sharding configuration for this collection (None if not sharded)

Source

pub fn set_shard_table(&self, table: &ShardTable) -> DbResult<()>

Save shard table to storage (persisting assignments)

Source

pub fn get_stored_shard_table(&self) -> Option<ShardTable>

Load shard table from storage

Source

pub fn is_sharded(&self) -> bool

Check if this collection is sharded

Source

pub fn doc_key(key: &str) -> Vec<u8>

Generate a document key: “doc:

Source

pub fn idx_meta_key(name: &str) -> Vec<u8>

Generate an index metadata key: “idx_meta:

Source

pub fn idx_entry_key( index_name: &str, values: &[Value], doc_key: &str, ) -> Vec<u8>

Generate an index entry key: “idx:::<doc_key>”

Source

pub fn geo_meta_key(name: &str) -> Vec<u8>

Generate a geo metadata key: “geo_meta:

Source

pub fn geo_entry_key(index_name: &str, doc_key: &str) -> Vec<u8>

Generate a geo entry key: “geo::<doc_key>”

Source

pub fn ft_meta_key(name: &str) -> Vec<u8>

Generate a fulltext index metadata key: “ft_meta:

Source

pub fn ft_term_key(index_name: &str, term: &str, doc_key: &str) -> Vec<u8>

Generate a fulltext term mapping key: “ft_term:::<doc_key>”

Source

pub fn ft_ngram_key(index_name: &str, ngram: &str, doc_key: &str) -> Vec<u8>

Generate a fulltext n-gram mapping key: “ft:::<doc_key>”

Source

pub fn blo_chunk_key(key: &str, chunk_index: usize) -> Vec<u8>

Generate a blob chunk key: “blo::<chunk_index>”

Source

pub fn ttl_meta_key(name: &str) -> Vec<u8>

Build a TTL index metadata key: “ttl_meta:

Source

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

Source

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

pub fn ttl_expiry_prefix_until( ttl_index_name: &str, max_timestamp: u64, ) -> Vec<u8>

Build a TTL expiry index prefix for scanning up to a timestamp: “doc:ttl_exp:<ttl_index_name>:<max_ts>:”

Source

pub fn vec_meta_key(name: &str) -> Vec<u8>

Create vector index metadata key: “vec_meta:

Source

pub fn vec_data_key(name: &str) -> Vec<u8>

Create vector index data key: “vec_data:

Source§

impl Collection

Source

pub fn get(&self, key: &str) -> DbResult<Document>

Get a document by key

Source

pub fn get_many(&self, keys: &[String]) -> Vec<Document>

Get multiple documents by keys

Source

pub fn insert(&self, data: Value) -> DbResult<Document>

Insert a new document

Source

pub fn insert_no_index(&self, data: Value) -> DbResult<Document>

Insert a new document without updating indexes (for bulk loads)

Source

pub fn update(&self, key: &str, data: Value) -> DbResult<Document>

Update a document with atomic document + index writes

Source

pub fn update_with_rev( &self, key: &str, expected_rev: &str, data: Value, ) -> DbResult<Document>

Update a document with revision check (optimistic concurrency control)

Source

pub fn delete(&self, key: &str) -> DbResult<()>

Delete a document with atomic document + index removal

Source

pub fn upsert_batch(&self, documents: Vec<(String, Value)>) -> DbResult<usize>

Batch upsert (insert or update) multiple documents - optimized for replication

Source

pub fn delete_batch(&self, keys: Vec<String>) -> DbResult<usize>

Batch delete documents with atomic document + index removal

Source

pub fn update_batch( &self, updates: &[(String, Value)], ) -> DbResult<Vec<Document>>

Batch update multiple documents with atomic document + index writes

Source

pub fn insert_batch(&self, documents: Vec<Value>) -> DbResult<Vec<Document>>

Insert multiple documents with atomic batched write

Source

pub fn all(&self) -> Vec<Document>

Get all documents

Source

pub fn scan(&self, limit: Option<usize>) -> Vec<Document>

Scan documents with an optional limit

Source

pub fn recalculate_count(&self) -> usize

Recalculate document count from storage

Source

pub fn count(&self) -> usize

Count documents in the collection

Source

pub fn recount_documents(&self) -> usize

Recount documents from actual RocksDB data (slow but accurate)

Source

pub fn truncate(&self) -> DbResult<usize>

Truncate collection (delete all documents)

Source

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

Source

pub fn get_all_fulltext_indexes(&self) -> Vec<FulltextIndex>

Get all fulltext indexes

Source

pub fn get_fulltext_index_for_field(&self, field: &str) -> Option<FulltextIndex>

Get a fulltext index that covers a specific field

Source

pub fn create_fulltext_index( &self, name: String, fields: Vec<String>, min_length: Option<usize>, ) -> DbResult<()>

Create a fulltext index

Source

pub fn drop_fulltext_index(&self, name: &str) -> DbResult<()>

Drop a fulltext index

Source

pub fn list_fulltext_indexes(&self) -> Vec<FulltextIndex>

List fulltext indexes

Perform a fulltext search

Source§

impl Collection

Source

pub fn get_all_geo_indexes(&self) -> Vec<GeoIndex>

Get all geo index metadata

Source

pub fn create_geo_index( &self, name: String, field: String, ) -> DbResult<GeoIndexStats>

Create a geospatial index

Source

pub fn drop_geo_index(&self, name: &str) -> DbResult<()>

Drop a geo index

Source

pub fn list_geo_indexes(&self) -> Vec<GeoIndexStats>

List all geo indexes

Source

pub fn geo_near( &self, field: &str, lat: f64, lon: f64, limit: usize, ) -> Option<Vec<(Document, f64)>>

Find documents near a point

Source

pub fn geo_within( &self, field: &str, lat: f64, lon: f64, radius: f64, ) -> Option<Vec<(Document, f64)>>

Find documents within a radius

Source§

impl Collection

Source

pub fn get_all_indexes(&self) -> Vec<Index>

Get all index metadata

Source

pub fn create_index( &self, name: String, fields: Vec<String>, index_type: IndexType, unique: bool, ) -> DbResult<IndexStats>

Create an index on a field

Source

pub fn drop_index(&self, name: &str) -> DbResult<()>

Drop an index

Source

pub fn list_indexes(&self) -> Vec<IndexStats>

List all indexes

Source

pub fn rebuild_all_indexes(&self) -> DbResult<usize>

Rebuild all indexes from existing documents Call this after bulk imports using insert_no_index()

Source

pub fn index_documents(&self, docs: &[Document]) -> DbResult<usize>

Index only the provided documents (for incremental indexing)

Source

pub fn get_index_stats(&self, name: &str) -> Option<IndexStats>

Get index statistics

Source

pub fn get_index_for_field(&self, field: &str) -> Option<Index>

Get an index for a field

Source

pub fn index_lookup_gt( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>

Lookup documents where field > value

Source

pub fn index_lookup_gte( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>

Lookup documents where field >= value

Source

pub fn index_lookup_lt( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>

Lookup documents where field < value

Source

pub fn index_lookup_lte( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>

Lookup documents where field <= value

Source

pub fn index_lookup_eq( &self, field: &str, value: &Value, ) -> Option<Vec<Document>>

Lookup documents using index (equality)

Source

pub fn index_lookup_eq_limit( &self, field: &str, value: &Value, limit: usize, ) -> Option<Vec<Document>>

Lookup documents using index (equality) with limit

Source

pub fn index_sorted( &self, field: &str, ascending: bool, limit: Option<usize>, ) -> Option<Vec<Document>>

Get documents sorted by indexed field

Source

pub fn bloom_check(&self, index_name: &str, item: &str) -> bool

Source

pub fn cuckoo_insert(&self, index_name: &str, item: &str)

Source

pub fn cuckoo_delete(&self, index_name: &str, item: &str)

Source

pub fn cuckoo_check(&self, index_name: &str, item: &str) -> bool

Source§

impl Collection

Source

pub fn get_cached_schema_validator( &self, ) -> Result<Option<SchemaValidator>, DbError>

Get or create cached schema validator

Source

pub fn set_json_schema(&self, schema: CollectionSchema) -> DbResult<()>

Set JSON schema for collection validation Set JSON schema for collection validation

Source

pub fn get_json_schema(&self) -> Option<CollectionSchema>

Get JSON schema

Source

pub fn remove_json_schema(&self) -> DbResult<()>

Remove JSON schema

Source§

impl Collection

Source

pub fn get_all_ttl_indexes(&self) -> Vec<TtlIndex>

Get all TTL indexes

Source

pub fn get_ttl_index(&self, name: &str) -> Option<TtlIndex>

Get a TTL index by name

Source

pub fn create_ttl_index( &self, name: String, field: String, expire_after_seconds: u64, ) -> DbResult<TtlIndexStats>

Create a TTL index

Source

pub fn drop_ttl_index(&self, name: &str) -> DbResult<()>

Drop a TTL index

Source

pub fn list_ttl_indexes(&self) -> Vec<TtlIndexStats>

List all TTL indexes

Source

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)

Source

pub fn cleanup_all_expired_documents(&self) -> DbResult<usize>

Cleanup all expired documents across all TTL indexes

Source§

impl Collection

Source

pub fn insert_tx( &self, tx: &mut Transaction, _wal: &Arc<WalWriter>, data: Value, ) -> DbResult<Document>

Insert a document within a transaction

Source

pub fn update_tx( &self, tx: &mut Transaction, _wal: &Arc<WalWriter>, key: &str, data: Value, ) -> DbResult<Document>

Update a document within a transaction

Source

pub fn delete_tx( &self, tx: &mut Transaction, _wal: &Arc<WalWriter>, key: &str, ) -> DbResult<()>

Delete a document within a transaction

Source

pub fn apply_transaction_operations( &self, operations: Vec<Operation>, ) -> DbResult<()>

Apply operations from a committed transaction with atomic document + index writes

Source§

impl Collection

Source

pub fn get_all_vector_index_configs(&self) -> Vec<VectorIndexConfig>

Get all vector index configurations

Source

pub fn get_vector_index(&self, name: &str) -> DbResult<Arc<VectorIndex>>

Get vector index (loading it if necessary)

Source

pub fn create_vector_index( &self, config: VectorIndexConfig, ) -> DbResult<VectorIndexStats>

Create a vector index

Source

pub fn drop_vector_index(&self, name: &str) -> DbResult<()>

Drop a vector index

Source

pub fn list_vector_indexes(&self) -> Vec<VectorIndexStats>

List vector indexes

Search similar vectors

Source

pub fn vector_similarity( &self, name: &str, query: Vec<f32>, ) -> DbResult<Vec<(String, f32)>>

Calculate similarity between a vector and documents

Source

pub fn quantize_vector_index( &self, name: &str, quantization: VectorQuantization, ) -> DbResult<QuantizationStats>

Quantize a vector index

Source

pub fn dequantize_vector_index(&self, _name: &str) -> DbResult<()>

Dequantize a vector index

Source

pub fn persist_vector_indexes(&self) -> DbResult<()>

Persist all in-memory vector indexes to disk

Trait Implementations§

Source§

impl Clone for Collection

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Collection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,