From 4ec8018de620266be6da5b0d0265eadcb3da3d38 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 18 Jul 2023 18:21:15 -0500 Subject: [PATCH] update --- .cargo/{toml => config.toml} | 0 .gitignore | 5 + Cargo.lock | 285 ++++++++++++++++++++++++++++++++ Cargo.toml | 14 ++ flake.nix | 3 + {src => src-ts}/App.module.scss | 0 {src => src-ts}/App.tsx | 0 {src => src-ts}/main.tsx | 0 {src => src-ts}/styles.css | 0 {src => src-ts}/vite-env.d.ts | 0 src/db.rs | 63 +++++++ src/db_keys.rs | 14 ++ src/lib.rs | 5 + src/main.rs | 17 ++ 14 files changed, 406 insertions(+) rename .cargo/{toml => config.toml} (100%) create mode 100644 Cargo.lock create mode 100644 Cargo.toml rename {src => src-ts}/App.module.scss (100%) rename {src => src-ts}/App.tsx (100%) rename {src => src-ts}/main.tsx (100%) rename {src => src-ts}/styles.css (100%) rename {src => src-ts}/vite-env.d.ts (100%) create mode 100644 src/db.rs create mode 100644 src/db_keys.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.cargo/toml b/.cargo/config.toml similarity index 100% rename from .cargo/toml rename to .cargo/config.toml diff --git a/.gitignore b/.gitignore index 0d58e00..3b67bba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ node_modules /result* .solid /typedoc + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4055502 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,285 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "panorama" +version = "0.1.0" +dependencies = [ + "anyhow", + "bincode", + "dirs", + "once_cell", + "redb", + "serde", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pyo3-build-config" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "554db24f0b3c180a9c0b1268f91287ab3f17c162e15b54caaae5a6b3773396b0" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "quote" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe8a65d69dd0808184ebb5f836ab526bb259db23c657efa38711b1072ee47f0" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redb" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "717a806693d0e1ed6cc55b392066bf13e703dd835acf5c5888c74740f924d355" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "serde" +version = "1.0.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.12.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2faeef5759ab89935255b1a4cd98e0baf99d1085e37d36599c625dac49ae8e" + +[[package]] +name = "thiserror" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..9dac022 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "panorama" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.72" +bincode = "1.3.3" +dirs = "5.0.1" +once_cell = "1.18.0" +redb = "1.0.5" +serde = { version = "1.0.171", features = ["derive"] } diff --git a/flake.nix b/flake.nix index b1088a8..8a9cdfa 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,9 @@ devShells = { default = pkgs.mkShell ({ + allowUnfree = true; + permittedInsecurePackages = [ "openssl-1.1.1u" ]; + packages = with pkgs; [ cargo-deny cargo-edit diff --git a/src/App.module.scss b/src-ts/App.module.scss similarity index 100% rename from src/App.module.scss rename to src-ts/App.module.scss diff --git a/src/App.tsx b/src-ts/App.tsx similarity index 100% rename from src/App.tsx rename to src-ts/App.tsx diff --git a/src/main.tsx b/src-ts/main.tsx similarity index 100% rename from src/main.tsx rename to src-ts/main.tsx diff --git a/src/styles.css b/src-ts/styles.css similarity index 100% rename from src/styles.css rename to src-ts/styles.css diff --git a/src/vite-env.d.ts b/src-ts/vite-env.d.ts similarity index 100% rename from src/vite-env.d.ts rename to src-ts/vite-env.d.ts diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..6ba4935 --- /dev/null +++ b/src/db.rs @@ -0,0 +1,63 @@ +use std::path::Path; + +use anyhow::Result; + +use crate::db_keys::nodes_by_id; + +pub struct PanoramaDb { + redb_db: redb::Database, +} + +impl PanoramaDb { + pub fn open(path: impl AsRef) -> Result { + let redb_db = redb::Database::create(path)?; + + Ok(Self { redb_db }) + } + + pub fn check(&mut self) -> Result<()> { + self.redb_db.check_integrity()?; + Ok(()) + } + + pub fn begin_read(&self) -> Result { + let tx = self.redb_db.begin_read()?; + Ok(ReadTransaction { redb_tx: tx }) + } + + pub fn begin_write(&self) -> Result { + let tx = self.redb_db.begin_write()?; + Ok(WriteTransaction { redb_tx: tx }) + } +} + +pub struct ReadTransaction<'db> { + redb_tx: redb::ReadTransaction<'db>, +} + +impl<'db> ReadTransaction<'db> {} + +pub struct WriteTransaction<'db> { + redb_tx: redb::WriteTransaction<'db>, +} + +pub struct CreateNodeOptions { + label: String, +} + +impl<'db> WriteTransaction<'db> { + pub fn create_node(&self) -> Result<()> { + let mut table = self.redb_tx.open_table(*nodes_by_id())?; + + // Create the actual node + table.insert((), ())?; + + // Create metadata keys + + Ok(()) + } + + pub fn commit(self) -> Result<()> { + self.redb_tx.commit().map_err(|err| err.into()) + } +} diff --git a/src/db_keys.rs b/src/db_keys.rs new file mode 100644 index 0000000..44b1c16 --- /dev/null +++ b/src/db_keys.rs @@ -0,0 +1,14 @@ +use once_cell::sync::OnceCell; +use redb::TableDefinition; + +macro_rules! table_def { + ($str:ident, $key:ty, $val:ty) => { + pub fn $str() -> &'static TableDefinition<'static, $key, $val> { + static INSTANCE: OnceCell> = + OnceCell::new(); + INSTANCE.get_or_init(|| TableDefinition::new(stringify!($str))) + } + }; +} + +table_def!(nodes_by_id, (), ()); diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..57a109e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +#[macro_use] +extern crate serde; + +pub mod db; +pub mod db_keys; diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..628a093 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,17 @@ +use std::fs; + +use anyhow::Result; +use panorama::db::PanoramaDb; + +fn main() -> Result<()> { + let local_data_dir = dirs::data_local_dir().unwrap(); + let panorama_data_dir = local_data_dir.join("panorama"); + fs::create_dir_all(&panorama_data_dir)?; + let database_file_path = panorama_data_dir.join("data.redb"); + + let database = PanoramaDb::open(database_file_path)?; + + println!("Hello, world!"); + + Ok(()) +}