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"
[lib]
name = "multi_module_example"
name = "mm"
path = "src/lib.rs"
crate-type = ["cdylib"]

View File

@ -32,15 +32,15 @@ $> module successfully registered in Frank
Finally, you could execute requests inside FCE CLI:
```bush
>> execute redis SET A 1
$> >> execute redis SET A 1
result: +OK
>> execute redis GET A
$> >> execute redis GET A
result: $1
1
>> execute sqlite CREATE VIRTUAL TABLE users USING FTS5(body)
$> >> execute sqlite CREATE VIRTUAL TABLE users USING FTS5(body)
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
>> 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
```

View File

@ -4,18 +4,24 @@ fn init() {
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> {
let cmd: Vec<_> = arg.split(" ").collect();
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(" ");
match cmd[0] {
"redis" => redis::call(arg.as_bytes()),
"sqlite" => sqlite::call(arg.as_bytes()),
"redis" => {
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(),
}
}