-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from pubky/feat/basic-data-store
Feat/basic data store
- Loading branch information
Showing
25 changed files
with
897 additions
and
344 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,17 @@ | ||
use heed::{types::Str, Database, Env, RwTxn}; | ||
|
||
use super::tables; | ||
mod m0; | ||
|
||
pub const TABLES_COUNT: u32 = 2; | ||
use super::tables::Tables; | ||
|
||
pub fn create_users_table(env: &Env, wtxn: &mut RwTxn) -> anyhow::Result<()> { | ||
let _: tables::users::UsersTable = | ||
env.create_database(wtxn, Some(tables::users::USERS_TABLE))?; | ||
pub fn run(env: &Env) -> anyhow::Result<Tables> { | ||
let mut wtxn = env.write_txn()?; | ||
|
||
Ok(()) | ||
} | ||
m0::run(env, &mut wtxn); | ||
|
||
let tables = Tables::new(env, &mut wtxn)?; | ||
|
||
pub fn create_sessions_table(env: &Env, wtxn: &mut RwTxn) -> anyhow::Result<()> { | ||
let _: tables::sessions::SessionsTable = | ||
env.create_database(wtxn, Some(tables::sessions::SESSIONS_TABLE))?; | ||
wtxn.commit()?; | ||
|
||
Ok(()) | ||
Ok(tables) | ||
} |
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,15 @@ | ||
use heed::{types::Str, Database, Env, RwTxn}; | ||
|
||
use crate::database::tables::{blobs, entries, sessions, users}; | ||
|
||
pub fn run(env: &Env, wtxn: &mut RwTxn) -> anyhow::Result<()> { | ||
let _: users::UsersTable = env.create_database(wtxn, Some(users::USERS_TABLE))?; | ||
|
||
let _: sessions::SessionsTable = env.create_database(wtxn, Some(sessions::SESSIONS_TABLE))?; | ||
|
||
let _: blobs::BlobsTable = env.create_database(wtxn, Some(blobs::BLOBS_TABLE))?; | ||
|
||
let _: entries::EntriesTable = env.create_database(wtxn, Some(entries::ENTRIES_TABLE))?; | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,30 @@ | ||
pub mod blobs; | ||
pub mod entries; | ||
pub mod sessions; | ||
pub mod users; | ||
|
||
use heed::{Env, RwTxn}; | ||
|
||
use blobs::{BlobsTable, BLOBS_TABLE}; | ||
use entries::{EntriesTable, ENTRIES_TABLE}; | ||
|
||
pub const TABLES_COUNT: u32 = 4; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Tables { | ||
pub blobs: BlobsTable, | ||
pub entries: EntriesTable, | ||
} | ||
|
||
impl Tables { | ||
pub fn new(env: &Env, wtxn: &mut RwTxn) -> anyhow::Result<Self> { | ||
Ok(Self { | ||
blobs: env | ||
.open_database(wtxn, Some(BLOBS_TABLE))? | ||
.expect("Blobs table already created"), | ||
entries: env | ||
.open_database(wtxn, Some(ENTRIES_TABLE))? | ||
.expect("Entries table already created"), | ||
}) | ||
} | ||
} |
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,11 @@ | ||
use std::{borrow::Cow, time::SystemTime}; | ||
|
||
use heed::{ | ||
types::{Bytes, Str}, | ||
BoxedError, BytesDecode, BytesEncode, Database, | ||
}; | ||
|
||
/// hash of the blob => bytes. | ||
pub type BlobsTable = Database<Bytes, Bytes>; | ||
|
||
pub const BLOBS_TABLE: &str = "blobs"; |
Oops, something went wrong.