diff --git a/src/conn.rs b/src/conn.rs index eb54dbbf..bc351244 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -387,6 +387,11 @@ impl<'a, 'c> HasSchema for InProgress<'a, 'c> { } } +impl<'a, 'c> InProgressRead<'a, 'c> { + pub fn last_tx_id(&self) -> Entid { + self.0.last_tx_id() + } +} impl<'a, 'c> InProgress<'a, 'c> { pub fn builder(self) -> InProgressBuilder<'a, 'c> { @@ -526,6 +531,10 @@ impl<'a, 'c> InProgress<'a, 'c> { }, } } + + pub fn last_tx_id(&self) -> Entid { + self.partition_map[":db.part/tx"].index - 1 + } } struct InProgressTransactWatcher<'a, 'o> { @@ -617,6 +626,13 @@ impl Conn { self.metadata.lock().unwrap().attribute_cache.clone() } + pub fn last_tx_id(&self) -> Entid { + // The mutex is taken during this entire method. + let metadata = self.metadata.lock().unwrap(); + + metadata.partition_map[":db.part/tx"].index - 1 + } + /// Query the Mentat store, using the given connection and the current metadata. pub fn q_once(&self, sqlite: &rusqlite::Connection, diff --git a/src/store.rs b/src/store.rs index 1614d0f5..e3b269e0 100644 --- a/src/store.rs +++ b/src/store.rs @@ -191,6 +191,10 @@ impl Store { pub fn unregister_observer(&mut self, key: &String) { self.conn.unregister_observer(key); } + + pub fn last_tx_id(&self) -> Entid { + self.conn.last_tx_id() + } } impl Queryable for Store {