pub struct RelTable { /* private fields */ }Expand description
RelTable — the main relational interface for one entity type. Thin, cheap to clone (Arc internally).
Implementations§
Source§impl RelTable
impl RelTable
pub fn new(db: Arc<DonaDb>, config: RelTableConfig) -> Self
pub fn schema(&self) -> &Schema
pub fn domain_id(&self) -> DomainId
Sourcepub fn put_record(
&self,
record: &Record,
block_height: BlockHeight,
entropy: &[u8],
) -> Result<(), RelError>
pub fn put_record( &self, record: &Record, block_height: BlockHeight, entropy: &[u8], ) -> Result<(), RelError>
Write a typed record at block_height. Validates field types, encodes key + value, maintains all secondary indexes. Everything goes into a single WriteBatch — atomic across primary + all indexes.
Sourcepub fn put_records(
&self,
records: &[Record],
block_height: BlockHeight,
entropy: &[u8],
) -> Result<(), RelError>
pub fn put_records( &self, records: &[Record], block_height: BlockHeight, entropy: &[u8], ) -> Result<(), RelError>
Batch put for multiple records — single WriteBatch for all of them. More efficient than calling put_record() N times when writing multiple records at the same block height.
Sourcepub fn get_record(
&self,
key_values: &[FieldValue],
) -> Result<Option<Record>, RelError>
pub fn get_record( &self, key_values: &[FieldValue], ) -> Result<Option<Record>, RelError>
Get a record by its primary key field values (latest version).
Sourcepub fn get_record_at(
&self,
key_values: &[FieldValue],
block_height: BlockHeight,
) -> Result<Option<Record>, RelError>
pub fn get_record_at( &self, key_values: &[FieldValue], block_height: BlockHeight, ) -> Result<Option<Record>, RelError>
Get a record at a specific block height (point-in-time read).
Sourcepub fn scan_where(
&self,
predicates: &[Predicate],
) -> Result<Vec<Record>, RelError>
pub fn scan_where( &self, predicates: &[Predicate], ) -> Result<Vec<Record>, RelError>
Filter records by predicates. Uses secondary index when available for Eq predicates. All predicates must be satisfied (implicit AND).
Sourcepub fn scan_range(
&self,
start_key: &[FieldValue],
end_key: &[FieldValue],
) -> Result<Vec<Record>, RelError>
pub fn scan_range( &self, start_key: &[FieldValue], end_key: &[FieldValue], ) -> Result<Vec<Record>, RelError>
Range scan by primary key bounds. Returns records ordered by primary key.
Sourcepub fn scan_prefix_raw(&self, prefix: &[u8]) -> Result<Vec<Record>, RelError>
pub fn scan_prefix_raw(&self, prefix: &[u8]) -> Result<Vec<Record>, RelError>
Prefix scan on primary key bytes. Returns all records whose key starts with prefix.
Sourcepub fn count_where(&self, predicates: &[Predicate]) -> Result<usize, RelError>
pub fn count_where(&self, predicates: &[Predicate]) -> Result<usize, RelError>
Count records matching predicates without materialising them.
Sourcepub fn scan_all_raw(&self) -> Result<Vec<Record>, RelError>
pub fn scan_all_raw(&self) -> Result<Vec<Record>, RelError>
Scan all records in this table (no filter).
Sourcepub fn follow_ref(
&self,
record: &Record,
ref_field: &str,
target: &RelTable,
) -> Result<Option<Record>, RelError>
pub fn follow_ref( &self, record: &Record, ref_field: &str, target: &RelTable, ) -> Result<Option<Record>, RelError>
Follow a foreign key reference: read ref_field from this record,
then look it up as a primary key in target RelTable.
Example: token_transfers.follow_ref(record, “holder_address”, &accounts_table) → returns the Account record for the holder
Sourcepub fn delete_record(
&self,
key_values: &[FieldValue],
block_height: BlockHeight,
entropy: &[u8],
) -> Result<(), RelError>
pub fn delete_record( &self, key_values: &[FieldValue], block_height: BlockHeight, entropy: &[u8], ) -> Result<(), RelError>
Tombstone a record: write an empty value to mark it deleted. DonaDB never physically removes data — this is the correct deletion model. Index entries are also tombstoned so they do not appear in future scans.