Skip to content

Commit 6a5ea88

Browse files
committed
used compile time query_as! in get_eeg_data_by_range
1 parent b831799 commit 6a5ea88

File tree

1 file changed

+13
-12
lines changed
  • backend/shared-logic/src

1 file changed

+13
-12
lines changed

backend/shared-logic/src/db.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,13 @@ pub async fn insert_time_labels(client: &DbClient, session_id: i32, labels: Vec<
393393
pub async fn get_eeg_data_by_range(client: &DbClient, session_id: i32, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<EegDataRow>, Error> {
394394
info!("Retrieving EEG data for session {} from {} to {}", session_id, start, end);
395395

396-
let data = sqlx::query_as::<_, EegDataRow>(
396+
let data = sqlx::query_as!(
397+
EegDataRow,
397398
"SELECT time, channel1, channel2, channel3, channel4 FROM eeg_data WHERE session_id = $1 AND time >= $2 AND time <= $3 ORDER BY time",
399+
session_id,
400+
start,
401+
end,
398402
)
399-
.bind(session_id)
400-
.bind(start)
401-
.bind(end)
402403
.fetch_all(&**client)
403404
.await?;
404405

@@ -413,14 +414,14 @@ pub async fn export_eeg_data_as_csv(client: &DbClient, session_id: i32, start_ti
413414
info!("Exporting EEG data for session id {} from {} to {}", session_id, start_time, end_time);
414415

415416
// get the data from the database
416-
let data = sqlx::query_as::<_, EegDataRow>(
417+
let data = sqlx::query!(
417418
"SELECT time, channel1, channel2, channel3, channel4 FROM eeg_data
418419
WHERE session_id = $1 AND time >= $2 AND time <= $3
419420
ORDER BY time ASC",
421+
session_id,
422+
start_time,
423+
end_time
420424
)
421-
.bind(session_id)
422-
.bind(start_time)
423-
.bind(end_time)
424425
.fetch_all(&**client)
425426
.await?;
426427

@@ -462,12 +463,12 @@ pub async fn export_eeg_data_as_csv(client: &DbClient, session_id: i32, start_ti
462463
///
463464
/// Returns the earliest timestamp on success.
464465
pub async fn get_earliest_eeg_timestamp(client: &DbClient, session_id: i32) -> Result<Option<DateTime<Utc>>, Error> {
465-
let earliest = sqlx::query_scalar::<_, Option<DateTime<Utc>>>(
466-
"SELECT MIN(time) FROM eeg_data WHERE session_id = $1",
466+
let row = sqlx::query!(
467+
"SELECT MIN(time) as earliest_time FROM eeg_data WHERE session_id = $1",
468+
session_id
467469
)
468-
.bind(session_id)
469470
.fetch_one(&**client)
470471
.await?;
471472

472-
Ok(earliest)
473+
Ok(row.earliest_time)
473474
}

0 commit comments

Comments
 (0)