Compare commits
6 Commits
500ab56be0
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 94a6dcbba6 | |||
| d76d1afd9d | |||
| 7c895c8191 | |||
| a3158ba034 | |||
| bf8f64b904 | |||
| 26803724c6 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -16,3 +16,8 @@ target/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
# ignorable files in migrations/
|
||||||
|
**/__pycache__
|
||||||
|
migrations/env/
|
||||||
|
migrations/test_db.sqlite
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ path_separator = os
|
|||||||
# database URL. This is consumed by the user-maintained env.py script only.
|
# database URL. This is consumed by the user-maintained env.py script only.
|
||||||
# other means of configuring database URLs may be customized within the env.py
|
# other means of configuring database URLs may be customized within the env.py
|
||||||
# file.
|
# file.
|
||||||
sqlalchemy.url = driver://user:pass@localhost/dbname
|
sqlalchemy.url = sqlite+pysqlite:///test_db.sqlite
|
||||||
|
|
||||||
|
|
||||||
[post_write_hooks]
|
[post_write_hooks]
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"""initial outline-rs schema
|
||||||
|
|
||||||
|
Revision ID: 040713502ba4
|
||||||
|
Revises:
|
||||||
|
Create Date: 2026-03-30 10:47:36.255978
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '040713502ba4'
|
||||||
|
down_revision: Union[str, Sequence[str], None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
|
||||||
|
# block table holds individual bullet points in the outline
|
||||||
|
op.create_table(
|
||||||
|
"blocks",
|
||||||
|
sa.Column("id", sa.INTEGER, primary_key=True),
|
||||||
|
sa.Column("first_child_id", sa.INTEGER, sa.schema.ForeignKey("blocks.id")),
|
||||||
|
sa.Column("next_sibling_id", sa.INTEGER, sa.schema.ForeignKey("blocks.id")),
|
||||||
|
sa.Column("page_id", sa.INTEGER, sa.schema.ForeignKey("pages.id"), index=True),
|
||||||
|
sa.Column("content", sa.types.UnicodeText)
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_table(
|
||||||
|
"pages",
|
||||||
|
sa.Column("id", sa.INTEGER, primary_key=True),
|
||||||
|
sa.Column("root_block_id", sa.INTEGER, sa.schema.ForeignKey("blocks.id")),
|
||||||
|
sa.Column("title", sa.types.UnicodeText)
|
||||||
|
)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
op.drop_table("blocks")
|
||||||
|
op.drop_table("pages")
|
||||||
|
pass
|
||||||
@@ -5,8 +5,8 @@ use std::collections::HashMap;
|
|||||||
pub struct NoteBlock {
|
pub struct NoteBlock {
|
||||||
// IDs are int64 as this is the datatype of rowids in sqlite
|
// IDs are int64 as this is the datatype of rowids in sqlite
|
||||||
id: i128,
|
id: i128,
|
||||||
first_child_id: Option<i128>,
|
pub first_child_id: Option<i128>,
|
||||||
next_sibling_id: Option<i128>,
|
pub next_sibling_id: Option<i128>,
|
||||||
|
|
||||||
content: String
|
content: String
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ impl NoteBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct BlockTreeNode {
|
pub struct BlockTreeNode {
|
||||||
// a tree of nodes, where each node refers to its block by id.
|
// 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.
|
// the id is used as the key in a page's block table.
|
||||||
block_id: i128,
|
block_id: i128,
|
||||||
@@ -28,7 +28,7 @@ struct BlockTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BlockTreeNode {
|
impl BlockTreeNode {
|
||||||
pub fn new(block_id: i128) -> Self {
|
fn new(block_id: i128) -> Self {
|
||||||
BlockTreeNode {
|
BlockTreeNode {
|
||||||
block_id,
|
block_id,
|
||||||
block_level: None,
|
block_level: None,
|
||||||
@@ -38,12 +38,12 @@ impl BlockTreeNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockTreeIterator<'a> {
|
pub struct BlockTreeIterator<'a> {
|
||||||
node_stack: Vec<&'a BlockTreeNode>
|
node_stack: Vec<&'a BlockTreeNode>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BlockTreeIterator<'a> {
|
impl<'a> BlockTreeIterator<'a> {
|
||||||
fn new(root_node: &'a BlockTreeNode) -> Self {
|
pub fn new(root_node: &'a BlockTreeNode) -> Self {
|
||||||
Self {
|
Self {
|
||||||
node_stack: vec![root_node]
|
node_stack: vec![root_node]
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ impl<'a> Iterator for BlockTreeIterator<'a> {
|
|||||||
pub struct NotePage {
|
pub struct NotePage {
|
||||||
title: String,
|
title: String,
|
||||||
id: i128,
|
id: i128,
|
||||||
block_tree_root: BlockTreeNode,
|
pub block_tree_root: BlockTreeNode,
|
||||||
|
|
||||||
block_table: HashMap<i128, NoteBlock>
|
block_table: HashMap<i128, NoteBlock>
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/main.rs
46
src/main.rs
@@ -1,20 +1,44 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use outline_rs::blocktree::{NoteBlock, NotePage, BlockTreeIterator};
|
||||||
use outline_rs::blocktree::{NoteBlock, NotePage};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let root_block = NoteBlock::new(0,Some(1),Some(2),String::from("hello"));
|
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 mut page = NotePage::new(String::from("page 1"), 0, root_block);
|
let mut page = NotePage::new(String::from("page 1"), 0, root_block);
|
||||||
let new_block = NoteBlock::new(1,None,None, String::from("world"));
|
|
||||||
page.insert(new_block);
|
// take each new block and give it some children/siblings
|
||||||
let new_block = NoteBlock::new(2,Some(3),None, String::from("world"));
|
let mut block1 = block_map.remove(&1).unwrap();
|
||||||
page.insert(new_block);
|
block1.next_sibling_id = Some(2);
|
||||||
let new_block = NoteBlock::new(3,Some(4),None, String::from("world"));
|
page.insert(block1);
|
||||||
page.insert(new_block);
|
|
||||||
let new_block = NoteBlock::new(4,None,None, String::from("world"));
|
let mut block2 = block_map.remove(&2).unwrap();
|
||||||
page.insert(new_block);
|
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);
|
||||||
|
|
||||||
page.build_tree();
|
page.build_tree();
|
||||||
|
|
||||||
println!("{:?}", page);
|
println!("{:?}", page);
|
||||||
// println!("{:?}", page.block_tree_root.first_child_node)
|
// println!("{:?}", page.block_tree_root.first_child_node)
|
||||||
|
let iter = BlockTreeIterator::new(&page.block_tree_root);
|
||||||
|
for id in iter {
|
||||||
|
println!("{}", id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user