mirror of
https://github.com/fluencelabs/fluid
synced 2025-04-24 22:32:16 +00:00
optimize sqlite call
This commit is contained in:
parent
167fc19b6a
commit
b2fdcd889e
@ -1,24 +1,19 @@
|
|||||||
use crate::errors::{err_msg, AppResult};
|
use crate::errors::{err_msg, AppResult};
|
||||||
use crate::sqlite;
|
use crate::sqlite;
|
||||||
|
|
||||||
pub fn query(query: &str) -> AppResult<String> {
|
pub fn query(bytes: &str) -> AppResult<String> {
|
||||||
let response = sqlite::call(query.as_bytes());
|
let response = sqlite::call(bytes.as_bytes());
|
||||||
|
|
||||||
// Decode query result to a utf8 string
|
// Decode query result to a utf8 string
|
||||||
let result_str = std::str::from_utf8(&response);
|
match String::from_utf8(response) {
|
||||||
|
Ok(string) => Ok(string),
|
||||||
// Log if there's an error
|
Err(err) => {
|
||||||
if result_str.is_err() {
|
log::error!("unable to decode result from bytes: {:#x?}", bytes);
|
||||||
log::error!("unable to decode result from bytes: {:#x?}", response);
|
Err(err_msg(&format!(
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap error with a better message, and return Result
|
|
||||||
result_str
|
|
||||||
.map_err(|e| {
|
|
||||||
err_msg(&format!(
|
|
||||||
"unable to decode result from bytes {:#x?}: {}",
|
"unable to decode result from bytes {:#x?}: {}",
|
||||||
response, e
|
bytes, err
|
||||||
))
|
)))
|
||||||
})
|
}
|
||||||
.map(|s| s.to_string())
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,19 @@
|
|||||||
use crate::errors::{err_msg, AppResult};
|
use crate::errors::{err_msg, AppResult};
|
||||||
use crate::sqlite;
|
use crate::sqlite;
|
||||||
|
|
||||||
pub fn query(query: &str) -> AppResult<String> {
|
pub fn query(bytes: &str) -> AppResult<String> {
|
||||||
let response = sqlite::call(query.as_bytes());
|
let response = sqlite::call(bytes.as_bytes());
|
||||||
|
|
||||||
// Decode query result to a utf8 string
|
// Decode query result to a utf8 string
|
||||||
let result_str = std::str::from_utf8(&response);
|
match String::from_utf8(response) {
|
||||||
|
Ok(string) => Ok(string),
|
||||||
// Log if there's an error
|
Err(err) => {
|
||||||
if result_str.is_err() {
|
log::error!("unable to decode result from bytes: {:#x?}", bytes);
|
||||||
log::error!("unable to decode result from bytes: {:#x?}", response);
|
Err(err_msg(&format!(
|
||||||
}
|
|
||||||
|
|
||||||
// Wrap error with a better message, and return Result
|
|
||||||
result_str
|
|
||||||
.map_err(|e| {
|
|
||||||
err_msg(&format!(
|
|
||||||
"unable to decode result from bytes {:#x?}: {}",
|
"unable to decode result from bytes {:#x?}: {}",
|
||||||
response, e
|
bytes, err
|
||||||
))
|
)))
|
||||||
})
|
}
|
||||||
.map(|s| s.to_string())
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user