pub struct RelTable<'a, B>where
B: StorageBackend,{ /* private fields */ }Expand description
One table of a RelationalDb. Every method runs (and commits) its own
transaction; use RelationalDb::write_tx or Db::write_tx to group
several operations atomically.
Implementations§
Source§impl<'a, B> RelTable<'a, B>where
B: StorageBackend,
impl<'a, B> RelTable<'a, B>where
B: StorageBackend,
Sourcepub fn schema(&self) -> &TableSchema
pub fn schema(&self) -> &TableSchema
The schema this handle was created with (for a handle from
RelationalDb::table_named, the definition at that time —
operations always use the current one).
Sourcepub fn insert(
&self,
values: BTreeMap<String, PropValue>,
) -> Result<PropValue, BknError>
pub fn insert( &self, values: BTreeMap<String, PropValue>, ) -> Result<PropValue, BknError>
Inserts a new row. For an auto-increment schema, values should not
include the primary-key column (it’s allocated here); the generated
PK is returned. For a non-auto-increment schema, values must
include the primary-key column — use RelTable::insert_with_pk
instead if the PK comes from elsewhere (e.g. an existing NodeId).
Fails with BknError::DuplicateKey if the pk is taken.
Sourcepub fn insert_bulk(
&self,
rows: impl IntoIterator<Item = BTreeMap<String, PropValue>>,
) -> Result<Vec<PropValue>, BknError>
pub fn insert_bulk( &self, rows: impl IntoIterator<Item = BTreeMap<String, PropValue>>, ) -> Result<Vec<PropValue>, BknError>
Inserts multiple rows in a single transaction, reserving PKs in one counter update if auto-increment is enabled.
Sourcepub fn insert_with_pk(
&self,
pk: PropValue,
values: BTreeMap<String, PropValue>,
) -> Result<(), BknError>
pub fn insert_with_pk( &self, pk: PropValue, values: BTreeMap<String, PropValue>, ) -> Result<(), BknError>
Inserts a row under an explicit, caller-supplied PK — the mechanism
for linking a relational row to an existing id from elsewhere (e.g.
a graph crate::graph::NodeId). Rejected on an auto-increment
schema, where PKs must come from RelTable::insert instead.
Sourcepub fn insert_with_pk_bulk(
&self,
rows: impl IntoIterator<Item = (PropValue, BTreeMap<String, PropValue>)>,
) -> Result<(), BknError>
pub fn insert_with_pk_bulk( &self, rows: impl IntoIterator<Item = (PropValue, BTreeMap<String, PropValue>)>, ) -> Result<(), BknError>
Inserts multiple rows with caller-supplied PKs in a single transaction.
Sourcepub fn upsert(
&self,
values: BTreeMap<String, PropValue>,
) -> Result<PropValue, BknError>
pub fn upsert( &self, values: BTreeMap<String, PropValue>, ) -> Result<PropValue, BknError>
Like RelTable::insert, but replaces an existing row with the same
pk instead of failing. On an auto-increment schema, a row without a
pk gets a fresh one and a row with a pk is upserted under it.
pub fn upsert_bulk( &self, rows: impl IntoIterator<Item = BTreeMap<String, PropValue>>, ) -> Result<Vec<PropValue>, BknError>
Sourcepub fn upsert_with_pk(
&self,
pk: PropValue,
values: BTreeMap<String, PropValue>,
) -> Result<(), BknError>
pub fn upsert_with_pk( &self, pk: PropValue, values: BTreeMap<String, PropValue>, ) -> Result<(), BknError>
Inserts the row, or replaces the existing row with the same PK (keeping every secondary index consistent). Works on any schema, including auto-increment ones.