Skip to content

Commit

Permalink
refactor(db): Change UserCompletionDAO to use query_as! (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxbeam authored Apr 3, 2024
1 parent aae8163 commit 1e0d0e3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ee/tabby-db/src/user_completions.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::time::Duration;

use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use chrono::DateTime;
use sqlx::{prelude::FromRow, query};

use crate::DbConn;
use crate::{DateTimeUtc, DbConn};

#[derive(FromRow)]
pub struct UserCompletionDAO {
pub user_id: i32,
pub user_id: i64,
pub completion_id: String,
pub language: String,

pub views: i64,
pub selects: i64,
pub dismisses: i64,

pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
}

impl DbConn {
Expand Down Expand Up @@ -63,8 +63,10 @@ impl DbConn {

#[cfg(any(test, feature = "testutils"))]
pub async fn fetch_one_user_completion(&self) -> Result<Option<UserCompletionDAO>> {
Ok(sqlx::query_as("SELECT * FROM user_completions")
.fetch_optional(&self.pool)
.await?)
Ok(
sqlx::query_as!(UserCompletionDAO, "SELECT user_id, completion_id, language, created_at, updated_at, views, selects, dismisses FROM user_completions")
.fetch_optional(&self.pool)
.await?,
)
}
}

0 comments on commit 1e0d0e3

Please sign in to comment.