Skip to content

Commit

Permalink
Merge pull request #551 from hatoo/fix-sqlite-error
Browse files Browse the repository at this point in the history
FIx sqlite error handling
  • Loading branch information
hatoo authored Aug 3, 2024
2 parents d6ea80e + d70463f commit c3ff290
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ pub fn store(
create_db(&conn)?;

let t = conn.transaction()?;
let affected_rows =
request_records
.iter()
.map(|req| {
t.execute(
"INSERT INTO oha (start, start_latency_correction, end, duration, status, len_bytes) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
((req.start - start).as_secs_f64(), req.start_latency_correction.map(|d| (d-start).as_secs_f64()), (req.end - start).as_secs_f64(), req.duration().as_secs_f64(), req.status.as_u16() as i64, req.len_bytes)
).unwrap_or(0)
})
.sum();
let mut affected_rows = 0;

for request in request_records {
affected_rows += t.execute(
"INSERT INTO oha (start, start_latency_correction, end, duration, status, len_bytes) VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
(
(request.start - start).as_secs_f64(),
request.start_latency_correction.map(|d| (d - start).as_secs_f64()),
(request.end - start).as_secs_f64(),
request.duration().as_secs_f64(),
request.status.as_u16() as i64,
request.len_bytes,
),
)?;
}

t.commit()?;

Ok(affected_rows)
Expand Down

0 comments on commit c3ff290

Please sign in to comment.