started with using surealdb
This commit is contained in:
2003
Cargo.lock
generated
2003
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@ path = "src/client-main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures-util = "0.3.24"
|
futures-util = "0.3.24"
|
||||||
rocksdb = "0.19.0"
|
surrealdb = "1.0.0-beta.7"
|
||||||
tokio = {version = "1.21.0", features = ["full"]}
|
tokio = {version = "1.21.0", features = ["full"]}
|
||||||
tokio-stream = "0.1.9"
|
tokio-stream = "0.1.9"
|
||||||
warp = "0.3.2"
|
warp = "0.3.2"
|
||||||
|
|||||||
@@ -73,16 +73,21 @@ pub fn run_server(args: Vec<String>) {
|
|||||||
//println!("{}", err.message);
|
//println!("{}", err.message);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// get itemstore
|
|
||||||
let itemstore = crate::server::itemstore::itemstore::new(mize_folder + "/db");
|
|
||||||
|
|
||||||
//run the webserver
|
//run the webserver
|
||||||
warp_server();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
warp_server(mize_folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn warp_server() {
|
async fn warp_server(mize_folder: String) {
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@@ -93,6 +98,10 @@ async fn warp_server() {
|
|||||||
//## $api/socket/id
|
//## $api/socket/id
|
||||||
//## $api/rest/
|
//## $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()));
|
let mut clients: Arc<Mutex<Vec<Client>>> = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
let socket_route = warp::path!("$api" / "socket")
|
let socket_route = warp::path!("$api" / "socket")
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
|
|
||||||
use rocksdb::{SingleThreaded, DBCommon, DB, Options};
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use surrealdb::Datastore;
|
||||||
|
|
||||||
pub struct itemstore {
|
pub struct itemstore {
|
||||||
db: DB,
|
db: surrealdb::Datastore,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl itemstore {
|
pub type Item = Vec<[String; 2]>;
|
||||||
pub fn new(path: String) -> itemstore {
|
|
||||||
let db = DB::open_default(&path).expect(&format!("Could not open rocksdb database at {}", &path)[..]);
|
|
||||||
|
|
||||||
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(Some(val)) => (),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
//db.set(b"0", )
|
|
||||||
println!("hi")
|
|
||||||
},
|
},
|
||||||
Err(e) => println!("Error reading item 0 from db: {}", e),
|
Err(e) => println!("Error while getting item index with id 0: {}", e)
|
||||||
}
|
};
|
||||||
return itemstore{db:db};
|
return itemstore {db:ds};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user