ok i think i'm getting this interface now
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Michael Zhang 2023-07-18 18:54:13 -05:00
parent 4ec8018de6
commit 38e21a8c56
8 changed files with 94 additions and 8 deletions

47
Cargo.lock generated
View file

@ -89,8 +89,15 @@ dependencies = [
"once_cell", "once_cell",
"redb", "redb",
"serde", "serde",
"uuid",
] ]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.66" version = "1.0.66"
@ -119,6 +126,36 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "redb" name = "redb"
version = "1.0.5" version = "1.0.5"
@ -212,6 +249,16 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "uuid"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
dependencies = [
"getrandom",
"rand",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"

View file

@ -12,3 +12,4 @@ dirs = "5.0.1"
once_cell = "1.18.0" once_cell = "1.18.0"
redb = "1.0.5" redb = "1.0.5"
serde = { version = "1.0.171", features = ["derive"] } serde = { version = "1.0.171", features = ["derive"] }
uuid = { version = "1.4.1", features = ["v4", "v8", "fast-rng"] }

View file

@ -29,9 +29,9 @@ impl AppManager {
/// Register apps into the pool /// Register apps into the pool
/// ///
/// Using these search paths: /// Using these search paths:
/// - Anything specified in a config file (TODO) /// - Anything specified in a config file (`TODO`)
/// - If DEVELOPMENT=true, look at PANORAMA_SRC/apps /// - If `DEVELOPMENT=true`, look at `$PANORAMA_SRC/apps`
/// - Default location at dirs::data_dir()/apps /// - Default location at `${dirs::data_dir()}/apps`
pub async fn register(&mut self) -> Result<()> { pub async fn register(&mut self) -> Result<()> {
let mut search_locations = vec![]; let mut search_locations = vec![];
@ -45,7 +45,9 @@ impl AppManager {
} }
/// Figure out which indices are required by the set of known apps /// Figure out which indices are required by the set of known apps
pub async fn compute_indices(&self) -> Result<()> { Ok(()) } pub async fn compute_indices(&self) -> Result<()> {
Ok(())
}
} }
pub struct App { pub struct App {

View file

@ -1,8 +1,10 @@
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use redb::ReadableTable;
use uuid::Uuid;
use crate::db_keys::nodes_by_id; use crate::db_keys::{metadata_by_id, nodes_by_id};
pub struct PanoramaDb { pub struct PanoramaDb {
redb_db: redb::Database, redb_db: redb::Database,
@ -29,6 +31,20 @@ impl PanoramaDb {
let tx = self.redb_db.begin_write()?; let tx = self.redb_db.begin_write()?;
Ok(WriteTransaction { redb_tx: tx }) Ok(WriteTransaction { redb_tx: tx })
} }
pub fn print_all_nodes(&self) -> Result<()> {
let tx = self.redb_db.begin_read()?;
let table = tx.open_table(*nodes_by_id())?;
for node in table.iter()? {
let (key, value) = node?;
let key = key.value();
let value = value.value();
println!("key: {key:?}, value: {value:?}");
}
Ok(())
}
} }
pub struct ReadTransaction<'db> { pub struct ReadTransaction<'db> {
@ -47,12 +63,16 @@ pub struct CreateNodeOptions {
impl<'db> WriteTransaction<'db> { impl<'db> WriteTransaction<'db> {
pub fn create_node(&self) -> Result<()> { pub fn create_node(&self) -> Result<()> {
let mut table = self.redb_tx.open_table(*nodes_by_id())?; let id = Uuid::new_v4();
let id_str = id.to_string();
// Create the actual node // Create the actual node
table.insert((), ())?; let mut node_table = self.redb_tx.open_table(*nodes_by_id())?;
node_table.insert(id_str.as_str(), ())?;
// Create metadata keys // Create metadata keys
let mut metadata_table = self.redb_tx.open_table(*metadata_by_id())?;
metadata_table.insert((id_str.as_str(), "", ""), ())?;
Ok(()) Ok(())
} }

View file

@ -11,4 +11,11 @@ macro_rules! table_def {
}; };
} }
table_def!(nodes_by_id, (), ()); table_def!(nodes_by_id, &'static str, ());
// (node id, metadata app, app key)
table_def!(
metadata_by_id,
(&'static str, &'static str, &'static str),
()
);

View file

@ -1,5 +1,6 @@
#[macro_use] #[macro_use]
extern crate serde; extern crate serde;
pub mod apps;
pub mod db; pub mod db;
pub mod db_keys; pub mod db_keys;

View file

@ -11,6 +11,14 @@ fn main() -> Result<()> {
let database = PanoramaDb::open(database_file_path)?; let database = PanoramaDb::open(database_file_path)?;
{
let write = database.begin_write()?;
write.create_node()?;
write.commit()?;
}
database.print_all_nodes()?;
println!("Hello, world!"); println!("Hello, world!");
Ok(()) Ok(())