Skip to content

Commit

Permalink
cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ethe committed Dec 16, 2024
1 parent 9d05f1c commit ca90c0e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::fs;
use std::sync::Arc;

use fusio::path::Path;
use tonbo::executor::tokio::TokioExecutor;
use tonbo::record::{Datatype, DynRecord, DynSchema, Value, ValueDesc};
use tonbo::{DbOption, DB};

#[tokio::main]
async fn main() {
fs::create_dir_all("./db_path/users").unwrap();

let schema = DynSchema::new(
vec![
ValueDesc::new("foo".into(), Datatype::String, false),
ValueDesc::new("bar".into(), Datatype::Int32, true),
],
0,
);

let options = DbOption::from((
Path::from_filesystem_path("./db_path/users").unwrap(),
&schema,
));
let db = DB::with_schema(options, TokioExecutor::new(), schema)
.await
.unwrap();

{
let mut txn = db.transaction().await;
txn.insert(DynRecord::new(
vec![
Value::new(
Datatype::String,
"foo".into(),
Arc::new("hello".to_owned()),
false,
),
Value::new(Datatype::Int32, "bar".into(), Arc::new(1), true),
],
0,
));

txn.commit().await.unwrap();
}

db.get(
&Value::new(
Datatype::String,
"foo".into(),
Arc::new("hello".to_owned()),
false,
),
|v| {
let v = v.get();
println!("{:?}", v.columns[0].value.downcast_ref::<String>());
Some(())
},
)
.await
.unwrap();
}

0 comments on commit ca90c0e

Please sign in to comment.