Skip to content
This repository was archived by the owner on Apr 5, 2019. It is now read-only.

Commit ac2792f

Browse files
committed
Get only partial from and to
1 parent e8f3536 commit ac2792f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/db/queries/logs.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ pub fn search(conn: &postgres::Connection, params: LogQueryParams) -> postgres::
4848
}
4949
}
5050
if let Some(time) = params.time {
51-
let from_index = parameters.add(Rc::new(time.from_time));
52-
where_conditions.push(format!("timestamp > ${}", from_index));
53-
let to_index = parameters.add(Rc::new(time.to_time));
54-
where_conditions.push(format!("timestamp < ${}", to_index));
51+
if let Some(from) = time.from_time {
52+
let from_index = parameters.add(Rc::new(from));
53+
where_conditions.push(format!("timestamp > ${}", from_index));
54+
}
55+
if let Some(to) = time.to_time {
56+
let to_index = parameters.add(Rc::new(to));
57+
where_conditions.push(format!("timestamp < ${}", to_index));
58+
}
5559
}
5660

5761
let where_clause = if where_conditions.len() > 0 {

src/db/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ impl fmt::Display for LogLevel {
157157
#[derive(Debug, Deserialize, Clone)]
158158
#[serde(rename_all = "camelCase")]
159159
pub struct LogDuration {
160-
pub from_time: chrono::DateTime<chrono::Local>,
161-
pub to_time: chrono::DateTime<chrono::Local>,
160+
pub from_time: Option<chrono::DateTime<chrono::Local>>,
161+
pub to_time: Option<chrono::DateTime<chrono::Local>>,
162162
}
163163

164164
#[derive(Debug, Deserialize, Clone)]

0 commit comments

Comments
 (0)