started with using surealdb

This commit is contained in:
Sebastian Moser
2022-09-18 21:02:42 +02:00
parent 463e58691b
commit 87ebad4bce
4 changed files with 2010 additions and 37 deletions

2003
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@ path = "src/client-main.rs"
[dependencies]
futures-util = "0.3.24"
rocksdb = "0.19.0"
surrealdb = "1.0.0-beta.7"
tokio = {version = "1.21.0", features = ["full"]}
tokio-stream = "0.1.9"
warp = "0.3.2"

View File

@@ -73,16 +73,21 @@ pub fn run_server(args: Vec<String>) {
//println!("{}", err.message);
//}
// get itemstore
let itemstore = crate::server::itemstore::itemstore::new(mize_folder + "/db");
//run the webserver
warp_server();
warp_server(mize_folder);
}
#[tokio::main]
async fn warp_server() {
async fn warp_server(mize_folder: String) {
/*
*
*
@@ -92,6 +97,10 @@ async fn warp_server() {
//## any number (with "-" in them) is interpreted as an item id
//## $api/socket/id
//## $api/rest/
// get itemstore
let itemstore = crate::server::itemstore::itemstore::new(mize_folder + "/db").await;
println!("haöasldjkfsdfi");
let mut clients: Arc<Mutex<Vec<Client>>> = Arc::new(Mutex::new(Vec::new()));

View File

@@ -1,24 +1,27 @@
use rocksdb::{SingleThreaded, DBCommon, DB, Options};
use std::io;
use surrealdb::Datastore;
pub struct itemstore {
db: DB,
db: surrealdb::Datastore,
}
impl itemstore {
pub fn new(path: String) -> itemstore {
let db = DB::open_default(&path).expect(&format!("Could not open rocksdb database at {}", &path)[..]);
pub type Item = Vec<[String; 2]>;
match db.get(b"0") {
impl itemstore {
pub async fn new(path: String) -> itemstore {
let ds = Datastore::new(&(String::from("file://") + &path[..] + "/db")[..]).await.expect("Could not open database");
let mut tr = ds.transaction(true, false).await.expect("creation of transaction failed");
match tr.get(vec!('0' as u8)).await {
Ok(Some(val)) => (),
Ok(None) => {
//db.set(b"0", )
println!("hi")
},
Err(e) => println!("Error reading item 0 from db: {}", e),
}
return itemstore{db:db};
Err(e) => println!("Error while getting item index with id 0: {}", e)
};
return itemstore {db:ds};
}
}