add logging; update readme

This commit is contained in:
vms 2020-04-29 02:12:53 +03:00
parent fd63e926b4
commit 082cf3b6dd
3 changed files with 16 additions and 10 deletions

View File

@ -5,7 +5,7 @@ authors = ["Fluence Labs"]
edition = "2018" edition = "2018"
[lib] [lib]
name = "multi_module_example" name = "mm"
path = "src/lib.rs" path = "src/lib.rs"
crate-type = ["cdylib"] crate-type = ["cdylib"]

View File

@ -32,15 +32,15 @@ $> module successfully registered in Frank
Finally, you could execute requests inside FCE CLI: Finally, you could execute requests inside FCE CLI:
```bush ```bush
>> execute redis SET A 1 $> >> execute redis SET A 1
result: +OK result: +OK
>> execute redis GET A $> >> execute redis GET A
result: $1 result: $1
1 1
>> execute sqlite CREATE VIRTUAL TABLE users USING FTS5(body) $> >> execute sqlite CREATE VIRTUAL TABLE users USING FTS5(body)
result: OK result: OK
>> execute sqlite INSERT INTO users(body) VALUES('AB'), ('BC'), ('CD'), ('DE') $> >> execute sqlite INSERT INTO users(body) VALUES('AB'), ('BC'), ('CD'), ('DE')
result: OK result: OK
>> execute sqlite SELECT * FROM users WHERE users MATCH 'A* OR B*' $> >> execute sqlite SELECT * FROM users WHERE users MATCH 'A* OR B*'
result: AB|BC result: AB|BC
``` ```

View File

@ -4,18 +4,24 @@ fn init() {
logger::WasmLogger::init_with_level(log::Level::Info).unwrap(); logger::WasmLogger::init_with_level(log::Level::Info).unwrap();
} }
#[invocation_handler(init_fn = init, side_modules = (sqlite, redis))] #[invocation_handler(init_fn = init, side_modules = (redis, sqlite))]
fn run(arg: String) -> Vec<u8> { fn run(arg: String) -> Vec<u8> {
let cmd: Vec<_> = arg.split(" ").collect(); let cmd: Vec<_> = arg.split(" ").collect();
if cmd.len() < 2 { if cmd.len() < 2 {
return "incorrect command".as_bytes().to_vec(); return "please specify module and argument".as_bytes().to_vec();
} }
let arg = cmd[1..].join(" "); let arg = cmd[1..].join(" ");
match cmd[0] { match cmd[0] {
"redis" => redis::call(arg.as_bytes()), "redis" => {
"sqlite" => sqlite::call(arg.as_bytes()), log::info!("calling redis");
redis::call(arg.as_bytes())
},
"sqlite" => {
log::info!("calling sqlite");
sqlite::call(arg.as_bytes())
},
_ => "unknown_command".as_bytes().to_vec(), _ => "unknown_command".as_bytes().to_vec(),
} }
} }