From 13302ca655d3d21422be683881a4248499f0f1d2 Mon Sep 17 00:00:00 2001 From: Alessandro Mazza <121622391+alessandromazza98@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:09:54 +0100 Subject: [PATCH] feat(db): make init_db function accepts a TableSet (#13222) --- crates/storage/db/src/mdbx.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/storage/db/src/mdbx.rs b/crates/storage/db/src/mdbx.rs index d6947e10bd2b..c0e11079f3ae 100644 --- a/crates/storage/db/src/mdbx.rs +++ b/crates/storage/db/src/mdbx.rs @@ -1,6 +1,6 @@ //! Bindings for [MDBX](https://libmdbx.dqdkfa.ru/). -use crate::is_database_empty; +use crate::{is_database_empty, TableSet, Tables}; use eyre::Context; use std::path::Path; @@ -28,12 +28,21 @@ pub fn create_db>(path: P, args: DatabaseArguments) -> eyre::Resu Ok(DatabaseEnv::open(rpath, DatabaseEnvKind::RW, args)?) } -/// Opens up an existing database or creates a new one at the specified path. Creates tables if -/// necessary. Read/Write mode. +/// Opens up an existing database or creates a new one at the specified path. Creates tables defined +/// in [`Tables`] if necessary. Read/Write mode. pub fn init_db>(path: P, args: DatabaseArguments) -> eyre::Result { + init_db_for::(path, args) +} + +/// Opens up an existing database or creates a new one at the specified path. Creates tables defined +/// in the given [`TableSet`] if necessary. Read/Write mode. +pub fn init_db_for, TS: TableSet>( + path: P, + args: DatabaseArguments, +) -> eyre::Result { let client_version = args.client_version().clone(); let db = create_db(path, args)?; - db.create_tables()?; + db.create_tables_for::()?; db.record_client_version(client_version)?; Ok(db) }