Skip to content

Commit 8a04f3d

Browse files
committed
Change the interface of open/create_db
1 parent 03bf8e8 commit 8a04f3d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

crates/mdbx-remote/src/any.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ pub enum TransactionAny<K: TransactionKind> {
204204
}
205205

206206
impl<K: TransactionKind> TransactionAny<K> {
207-
pub async fn open_db(&self, db: Option<String>) -> Result<DatabaseAny> {
207+
pub async fn open_db(&self, db: Option<&str>) -> Result<DatabaseAny> {
208208
match self {
209-
Self::Local(tx) => Ok(DatabaseAny::Local(
210-
tx.open_db(db.as_ref().map(|t| t.as_str()))?,
209+
Self::Local(tx) => Ok(DatabaseAny::Local(tx.open_db(db)?)),
210+
Self::Remote(tx) => Ok(DatabaseAny::Remote(
211+
tx.open_db(db.map(|t| t.to_string())).await?,
211212
)),
212-
Self::Remote(tx) => Ok(DatabaseAny::Remote(tx.open_db(db).await?)),
213213
}
214214
}
215215

@@ -274,12 +274,12 @@ impl TransactionAny<RW> {
274274
}
275275
}
276276

277-
pub async fn create_db(&self, db: Option<String>, flags: DatabaseFlags) -> Result<DatabaseAny> {
277+
pub async fn create_db(&self, db: Option<&str>, flags: DatabaseFlags) -> Result<DatabaseAny> {
278278
match self {
279-
Self::Local(tx) => Ok(DatabaseAny::Local(
280-
tx.create_db(db.as_ref().map(|t| t.as_str()), flags)?,
279+
Self::Local(tx) => Ok(DatabaseAny::Local(tx.create_db(db, flags)?)),
280+
Self::Remote(tx) => Ok(DatabaseAny::Remote(
281+
tx.create_db(db.map(|t| t.to_string()), flags).await?,
281282
)),
282-
Self::Remote(tx) => Ok(DatabaseAny::Remote(tx.create_db(db, flags).await?)),
283283
}
284284
}
285285

crates/mdbx/src/reth.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ pub async fn reth_main(args: RethArguments) -> Result<()> {
2626

2727
match args.table.to_lowercase().as_str() {
2828
"plainaccountstate" => {
29-
let db = tx
30-
.open_db(Some(PlainAccountState::NAME.to_string()))
31-
.await?;
29+
let db = tx.open_db(Some(PlainAccountState::NAME)).await?;
3230
let val = tx.get::<Vec<u8>>(db.dbi(), &args.key).await?;
3331
let val = val
3432
.map(|t| <PlainAccountState as reth_db::table::Table>::Value::decompress(&t))

crates/mdbx/src/stat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub async fn stat_main(args: StatArguments) -> Result<()> {
4141
while let Some(it) = st.next().await {
4242
let (k, _) = it?;
4343
let table = String::from_utf8(k)?;
44-
let db = tx.open_db(Some(table.clone())).await?;
44+
let db = tx.open_db(Some(&table)).await?;
4545

4646
let stat = tx.db_stat(&db).await?;
4747
println!("Table {}:", table);

0 commit comments

Comments
 (0)