aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/mod.rs1
-rw-r--r--src/core/storage.rs36
2 files changed, 37 insertions, 0 deletions
diff --git a/src/core/mod.rs b/src/core/mod.rs
new file mode 100644
index 0000000..e626ba5
--- /dev/null
+++ b/src/core/mod.rs
@@ -0,0 +1 @@
+pub mod storage; \ No newline at end of file
diff --git a/src/core/storage.rs b/src/core/storage.rs
new file mode 100644
index 0000000..a4bb1bb
--- /dev/null
+++ b/src/core/storage.rs
@@ -0,0 +1,36 @@
+
+use structsy::{Structsy, StructsyError, StructsyTx};
+use structsy_derive::{Persistent, queries};
+
+#[derive(Persistent)]
+struct DirectoryNode {
+ dirname: string,
+ path: string,
+ files: Vec<FileNode>
+}
+
+#[derive(PersistentEmbedded)]
+struct FileNode {
+ filename: string,
+ path: string,
+ hash: string,
+ combined_hash: string,
+}
+#[queries(MyData)]
+trait FileNode {
+ fn search(self, name:&str) -> Self;
+}
+
+pub fn open_db(path: string) -> Result<Structsy, StructsyError> {
+ let db = Structsy::open(path)?;
+ db.define::<DirectoryNode>()?
+}
+
+
+pub fn add(dir: DirectoryNode) -> Result<(), StructsyError> {
+ let db = open_db("my_db.db")?;
+ let mut tx = db.begin()?;
+ tx.insert(&dir)?;
+ tx.commit()?;
+ Ok(())
+} \ No newline at end of file