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