@@ -23,18 +23,18 @@ Add to your `Cargo.toml`:
23
23
24
24
``` toml
25
25
[dependencies ]
26
- prollytree = " 0.2 .0"
26
+ prollytree = " 0.3 .0"
27
27
28
28
# Optional features
29
- prollytree = { version = " 0.2 .0" , features = [" git" , " sql" , " rig" ] }
29
+ prollytree = { version = " 0.3 .0" , features = [" git" , " sql" , " rig" ] }
30
30
```
31
31
32
32
## Examples
33
33
34
34
### Basic Tree Operations
35
35
36
36
``` rust
37
- use prollytree :: tree :: ProllyTree ;
37
+ use prollytree :: tree :: { ProllyTree , Tree } ;
38
38
use prollytree :: storage :: InMemoryNodeStorage ;
39
39
40
40
let storage = InMemoryNodeStorage :: <32 >:: new ();
@@ -44,89 +44,87 @@ let mut tree = ProllyTree::new(storage, Default::default());
44
44
tree . insert (b " user:alice" . to_vec (), b " Alice Johnson" . to_vec ());
45
45
tree . insert (b " config:timeout" . to_vec (), b " 30" . to_vec ());
46
46
47
- // Query data
48
- let value = tree . find (b " user:alice" )? ;
49
- println! (" Found: {}" , String :: from_utf8 (value )? );
47
+ // Query data - find returns a node, extract the value
48
+ if let Some (node ) = tree . find (b " user:alice" ) {
49
+ for (i , key ) in node . keys. iter (). enumerate () {
50
+ if key == b " user:alice" {
51
+ let value = & node . values[i ];
52
+ println! (" Found: {}" , String :: from_utf8 (value . clone ())? );
53
+ break ;
54
+ }
55
+ }
56
+ }
50
57
51
58
// Generate cryptographic proof
52
- let proof = tree . generate_proof (b " user:alice" )? ;
53
- let is_valid = tree . verify_proof ( & proof , b " user:alice" , b " Alice Johnson" );
59
+ let proof = tree . generate_proof (b " user:alice" );
60
+ let is_valid = tree . verify ( proof , b " user:alice" , Some ( b " Alice Johnson" ) );
54
61
```
55
62
56
63
### Git-backed Versioned Storage
57
64
58
65
``` rust
59
66
use prollytree :: git :: GitVersionedKvStore ;
67
+ use std :: process :: Command ;
68
+ use std :: fs;
60
69
61
- let mut store = GitVersionedKvStore :: init (" ./data" )? ;
70
+ // Setup: Create a temporary Git repository (in real use, you'd have an existing repo)
71
+ let repo_path = " /tmp/demo_git_repo" ;
72
+ fs :: create_dir_all (repo_path )? ;
73
+ Command :: new (" git" ). args (& [" init" ]). current_dir (repo_path ). output ()? ;
62
74
63
- // Version your data like Git
64
- store . set (b " config/api_key" , b " secret123" )? ;
65
- store . commit (" Initial config" )? ;
66
-
67
- // Branch for experiments
68
- store . checkout_new_branch (" feature/optimization" )? ;
69
- store . set (b " config/timeout" , b " 60" )? ;
70
- store . commit (" Increase timeout" )? ;
71
-
72
- // Three-way merge back to main
73
- store . checkout (" main" )? ;
74
- store . merge (" feature/optimization" )? ;
75
- ```
75
+ // Switch to repo directory and create dataset
76
+ std :: env :: set_current_dir (repo_path )? ;
77
+ fs :: create_dir_all (" data" )? ;
78
+ let mut store = GitVersionedKvStore :: <32 >:: init (" data" )? ;
76
79
77
- ### SQL Interface with Time Travel
78
-
79
- ``` rust
80
- use prollytree :: sql :: ProllyStorage ;
81
- use gluesql_core :: prelude :: Glue ;
82
-
83
- let storage = ProllyStorage :: <32 >:: init (" ./data" )? ;
84
- let mut glue = Glue :: new (storage );
80
+ // Now use Git-backed versioned storage
81
+ store . insert (b " config/api_key" . to_vec (), b " secret123" . to_vec ())? ;
82
+ store . commit (" Initial config" )? ;
85
83
86
- // Standard SQL operations
87
- glue . execute (" CREATE TABLE users (id INTEGER, name TEXT)" ). await ? ;
88
- glue . execute (" INSERT INTO users VALUES (1, 'Alice')" ). await ? ;
84
+ // Retrieve data
85
+ if let Some (value ) = store . get (b " config/api_key" ) {
86
+ println! (" Retrieved: {}" , String :: from_utf8 (value )? );
87
+ }
89
88
90
- // Time travel queries
91
- glue . storage . commit ( " v1.0 " ) . await ? ;
92
- glue . execute ( " UPDATE users SET name = 'Alice Smith' WHERE id = 1 " ) . await ? ;
89
+ // Add more data and commit
90
+ store . insert ( b " config/timeout " . to_vec (), b " 30 " . to_vec ()) ? ;
91
+ store . commit ( " Add timeout config " ) ? ;
93
92
94
- // Query historical data
95
- let v1_data = glue . storage . query_at_commit ( " v1.0 " ,
96
- " SELECT * FROM users WHERE id = 1 " ) . await ? ;
93
+ // Create branches for parallel development
94
+ store . create_branch ( " experimental " ) ? ;
95
+ println! ( " Git-backed storage with full version control! " ) ;
97
96
```
98
97
99
- ### AI Agent Memory
98
+ ### Multiple Storage Backends
100
99
101
100
``` rust
102
- use prollytree :: agent :: {AgentMemorySystem , MemoryQuery };
103
-
104
- let mut memory = AgentMemorySystem :: init_with_thread_safe_git (
105
- " ./agent_memory" , " agent_001" . to_string (), None
106
- )? ;
107
-
108
- // Store conversation context
109
- memory . short_term. store_conversation_turn (
110
- " session_123" , " user" , " What's the weather today?" , None
111
- ). await ? ;
112
-
113
- // Store persistent knowledge
114
- memory . semantic. store_fact (
115
- " weather" , " temperature" ,
116
- json! ({" location" : " Tokyo" , " temp" : " 22°C" }),
117
- 0.9 , " weather_api"
118
- ). await ? ;
119
-
120
- // Query and checkpoint
121
- let memories = memory . semantic. query (MemoryQuery :: text (" Tokyo" )). await ? ;
122
- let checkpoint = memory . checkpoint (" Weather conversation" ). await ? ;
101
+ use prollytree :: tree :: {ProllyTree , Tree };
102
+ use prollytree :: storage :: {InMemoryNodeStorage , FileNodeStorage };
103
+
104
+ // In-memory storage (fast, temporary)
105
+ let mem_storage = InMemoryNodeStorage :: <32 >:: new ();
106
+ let mut mem_tree = ProllyTree :: new (mem_storage , Default :: default ());
107
+ mem_tree . insert (b " session:abc123" . to_vec (), b " active" . to_vec ());
108
+
109
+ // File-based storage (persistent)
110
+ let file_storage = FileNodeStorage :: <32 >:: new (" ./tree_data" . into ());
111
+ let mut file_tree = ProllyTree :: new (file_storage , Default :: default ());
112
+ file_tree . insert (b " user:alice" . to_vec (), b " Alice Johnson" . to_vec ());
113
+
114
+ // Both trees support the same operations
115
+ if let Some (node ) = mem_tree . find (b " session:abc123" ) {
116
+ println! (" Session found in memory storage" );
117
+ }
118
+
119
+ // For SQL functionality, see examples/sql.rs
120
+ println! (" Multiple storage backends working!" );
123
121
```
124
122
125
123
## Feature Flags
126
124
127
125
``` toml
128
126
[dependencies .prollytree ]
129
- version = " 0.2 .0"
127
+ version = " 0.3 .0"
130
128
features = [
131
129
" git" , # Git-backed versioned storage
132
130
" sql" , # SQL interface via GlueSQL
@@ -148,22 +146,24 @@ Run benchmarks: `cargo bench`
148
146
149
147
## Documentation & Examples
150
148
151
- - ** [ 📖 Full API Documentation] ( https://docs.rs/prollytree ) **
152
- - ** [ 💡 Use Cases & Examples] ( examples/README.md ) ** - AI agents, version control, distributed systems
153
- - ** [ 🐍 Python Bindings] ( python/README.md ) ** - Complete Python API
154
- - ** [ ⚡ Performance Guide] ( docs/performance.md ) ** - Optimization tips
149
+ - ** [ Full API Documentation] ( https://docs.rs/prollytree ) **
150
+ - ** [ Use Cases & Examples] ( examples/README.md ) ** - AI agents, version control, distributed systems
151
+ - ** [ Python Bindings] ( python/README.md ) ** - Complete Python API
152
+ - ** [ Performance Guide] ( docs/performance.md ) ** - Optimization tips
155
153
156
154
## CLI Tool
157
155
158
156
``` bash
159
157
# Install git-prolly CLI
160
158
cargo install prollytree --features git
161
159
162
- # Use like Git for key-value data
163
- git-prolly init my-data
160
+ # Setup git repository and create dataset
161
+ git init my-repo && cd my-repo
162
+ mkdir my-data && git-prolly init my-data # Create dataset directory
163
+ cd my-data
164
164
git-prolly set " user:alice" " Alice Johnson"
165
165
git-prolly commit -m " Add user"
166
- git-prolly checkout -b feature/updates
166
+ git checkout -b feature/updates # Use regular git for branching
167
167
git-prolly merge main
168
168
```
169
169
0 commit comments