-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding the feature
upgrade_0_5_x
for auto-upgrading from vers…
…ion 0.5.x to the higher version 0.6.x
- Loading branch information
1 parent
8f0919e
commit bcf1c6b
Showing
23 changed files
with
885 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::db_type::Result; | ||
use redb::Builder; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
|
||
pub(crate) struct DatabaseInstance { | ||
kind: DatabaseInstanceKind, | ||
} | ||
|
||
impl DatabaseInstance { | ||
pub(crate) fn create_on_disk(builder: Builder, path: impl AsRef<Path>) -> Result<Self> { | ||
let db = builder.create(path.as_ref())?; | ||
Ok(Self { | ||
kind: DatabaseInstanceKind::OnDisk { | ||
redb_database: db, | ||
path: path.as_ref().to_path_buf(), | ||
}, | ||
}) | ||
} | ||
|
||
pub(crate) fn open_on_disk(builder: Builder, path: impl AsRef<Path>) -> Result<Self> { | ||
let db = builder.open(path.as_ref())?; | ||
Ok(Self { | ||
kind: DatabaseInstanceKind::OnDisk { | ||
redb_database: db, | ||
path: path.as_ref().to_path_buf(), | ||
}, | ||
}) | ||
} | ||
|
||
pub(crate) fn create_in_memory(builder: Builder) -> Result<Self> { | ||
let in_memory_backend = redb::backends::InMemoryBackend::new(); | ||
let db = builder.create_with_backend(in_memory_backend)?; | ||
Ok(Self { | ||
kind: DatabaseInstanceKind::InMemory { | ||
redb_database: db, | ||
}, | ||
}) | ||
} | ||
|
||
pub(crate) fn redb_database(&self) -> Result<&redb::Database> { | ||
self.kind.redb_database() | ||
} | ||
} | ||
|
||
enum DatabaseInstanceKind { | ||
InMemory { | ||
redb_database: redb::Database, | ||
}, | ||
OnDisk { | ||
redb_database: redb::Database, | ||
#[allow(dead_code)] | ||
path: PathBuf, | ||
} | ||
} | ||
|
||
impl DatabaseInstanceKind { | ||
pub(crate) fn redb_database(&self) -> Result<&redb::Database> { | ||
match self { | ||
DatabaseInstanceKind::InMemory { redb_database } => Ok(redb_database), | ||
DatabaseInstanceKind::OnDisk { redb_database, .. } => Ok(redb_database) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.