impl fromstr for query

feat/vaults
Tomáš Mládek 2021-12-21 12:01:40 +01:00
parent 8e71e34a09
commit 7d0b23e955
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
2 changed files with 10 additions and 2 deletions

View File

@ -234,6 +234,15 @@ impl TryFrom<&lexpr::Value> for Query {
}
}
impl FromStr for Query {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let sexp = lexpr::from_str(s)?;
Query::try_from(&sexp)
}
}
impl Query {
pub(crate) fn to_sqlite_predicates(&self) -> Result<Box<Predicate>> {
match self {

View File

@ -89,8 +89,7 @@ pub async fn get_query(
) -> Result<HttpResponse, Error> {
let connection = state.db_pool.get().map_err(ErrorInternalServerError)?;
let sexp = lexpr::from_str(info.query.as_str()).map_err(ErrorBadRequest)?;
let in_query = Query::try_from(&sexp).map_err(ErrorBadRequest)?;
let in_query: Query = info.query.as_str().parse().map_err(ErrorBadRequest)?;
let entries = query(&connection, in_query).map_err(ErrorInternalServerError)?;
let mut result: HashMap<String, Entry> = HashMap::new();
for entry in entries {