Compare commits

..

1 Commits

Author SHA1 Message Date
91ff9a4caf create directory for DB migrations with alembic 2026-03-30 10:29:31 -04:00
3 changed files with 20 additions and 42 deletions

View File

@@ -0,0 +1,2 @@
alembic

View File

@@ -5,8 +5,8 @@ use std::collections::HashMap;
pub struct NoteBlock {
// IDs are int64 as this is the datatype of rowids in sqlite
id: i128,
pub first_child_id: Option<i128>,
pub next_sibling_id: Option<i128>,
first_child_id: Option<i128>,
next_sibling_id: Option<i128>,
content: String
}
@@ -18,7 +18,7 @@ impl NoteBlock {
}
#[derive(Debug)]
pub struct BlockTreeNode {
struct BlockTreeNode {
// a tree of nodes, where each node refers to its block by id.
// the id is used as the key in a page's block table.
block_id: i128,
@@ -28,7 +28,7 @@ pub struct BlockTreeNode {
}
impl BlockTreeNode {
fn new(block_id: i128) -> Self {
pub fn new(block_id: i128) -> Self {
BlockTreeNode {
block_id,
block_level: None,
@@ -38,12 +38,12 @@ impl BlockTreeNode {
}
}
pub struct BlockTreeIterator<'a> {
struct BlockTreeIterator<'a> {
node_stack: Vec<&'a BlockTreeNode>
}
impl<'a> BlockTreeIterator<'a> {
pub fn new(root_node: &'a BlockTreeNode) -> Self {
fn new(root_node: &'a BlockTreeNode) -> Self {
Self {
node_stack: vec![root_node]
}
@@ -78,7 +78,7 @@ impl<'a> Iterator for BlockTreeIterator<'a> {
pub struct NotePage {
title: String,
id: i128,
pub block_tree_root: BlockTreeNode,
block_tree_root: BlockTreeNode,
block_table: HashMap<i128, NoteBlock>
}

View File

@@ -1,44 +1,20 @@
use std::collections::HashMap;
use outline_rs::blocktree::{NoteBlock, NotePage, BlockTreeIterator};
use outline_rs::blocktree::{NoteBlock, NotePage};
fn main() {
let root_block = NoteBlock::new(0,Some(1),None,String::from("hello"));
let mut block_map = HashMap::new();
for idx in 1..=5 {
let new_block = NoteBlock::new(idx,None, None, String::from("I'm block {idx}"));
block_map.insert(idx,new_block);
}
let root_block = NoteBlock::new(0,Some(1),Some(2),String::from("hello"));
let mut page = NotePage::new(String::from("page 1"), 0, root_block);
// take each new block and give it some children/siblings
let mut block1 = block_map.remove(&1).unwrap();
block1.next_sibling_id = Some(2);
page.insert(block1);
let mut block2 = block_map.remove(&2).unwrap();
block2.first_child_id = Some(3);
block2.next_sibling_id = Some(4);
page.insert(block2);
let mut block3 = block_map.remove(&3).unwrap();
page.insert(block3);
let mut block4 = block_map.remove(&4).unwrap();
block4.first_child_id = Some(5);
page.insert(block4);
let mut block5 = block_map.remove(&5).unwrap();
page.insert(block5);
let new_block = NoteBlock::new(1,None,None, String::from("world"));
page.insert(new_block);
let new_block = NoteBlock::new(2,Some(3),None, String::from("world"));
page.insert(new_block);
let new_block = NoteBlock::new(3,Some(4),None, String::from("world"));
page.insert(new_block);
let new_block = NoteBlock::new(4,None,None, String::from("world"));
page.insert(new_block);
page.build_tree();
println!("{:?}", page);
// println!("{:?}", page.block_tree_root.first_child_node)
let iter = BlockTreeIterator::new(&page.block_tree_root);
for id in iter {
println!("{}", id);
}
}