#1 pull request : add env_borrow for Txn and MutTxn

Closed on June 15, 2021
gcxfd on June 15, 2021
pijul push gcxfd@ssh.pijul.com:pijul/sanakirja  --to-channel main:1
gcxfd added a change on June 15, 2021
ECPAFJSBBQ6KMGESKYDMSGPSO32TKLWOUQ4ABALKP6U2IEABWN6AC
main
gcxfd on June 15, 2021

I need this for create db if not exist

 52
 53 impl<'a> ReadTx<'a> {
 54   pub fn ptr(&self) -> *const TxnEnv<'a> {
 55     &self.0
 56   }
 57   pub fn btree<K: Storable, V: Storable>(&self, id: usize) -> btree::Db<K, V> {
 58     let tx = &self.0;
 59     match tx.root_db::<K, V, Page<K, V>>(id) {
 60       None => {
 61         let mut w = Env::mut_txn_begin(tx.env_borrow()).unwrap();
 62         let tree = btree::create_db::<_, K, V>(&mut w).unwrap();
 63         w.set_root(id, tree.db);
 64         w.commit().unwrap();
 65         tree
 66       }
 67       Some(tree) => tree,
 68     }
 69   }
 70 }
pmeunier on June 15, 2021

Thanks! I’ve just applied it to main, and published it to crates.io.

pmeunier closed this discussion on June 15, 2021