Add SQLx operation tracing (#5223)
* wip: vendor sqlx-tracing * (compiles) standardize pg types used * more standardization * general log message improvements * wip: improve sqlx-tracing architecture * unify sqlx::Executor type * wip: try fix sqlx tracing * wip: sqlx-tracing compiles * so close * it compiles * fix ci
This commit is contained in:
@@ -7,9 +7,12 @@ use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::types::Json;
|
||||
|
||||
use crate::database::models::{
|
||||
DBFileId, DBProjectId, DatabaseError, DelphiReportId,
|
||||
DelphiReportIssueDetailsId, DelphiReportIssueId,
|
||||
use crate::database::{
|
||||
PgTransaction,
|
||||
models::{
|
||||
DBFileId, DBProjectId, DatabaseError, DelphiReportId,
|
||||
DelphiReportIssueDetailsId, DelphiReportIssueId,
|
||||
},
|
||||
};
|
||||
|
||||
/// A Delphi malware analysis report for a project version file.
|
||||
@@ -32,7 +35,7 @@ pub struct DBDelphiReport {
|
||||
impl DBDelphiReport {
|
||||
pub async fn upsert(
|
||||
&self,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<DelphiReportId, DatabaseError> {
|
||||
Ok(DelphiReportId(sqlx::query_scalar!(
|
||||
"
|
||||
@@ -47,7 +50,7 @@ impl DBDelphiReport {
|
||||
self.artifact_url,
|
||||
self.severity as DelphiSeverity,
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?))
|
||||
}
|
||||
}
|
||||
@@ -181,7 +184,7 @@ pub struct DelphiReportIssueResult {
|
||||
impl DBDelphiReportIssue {
|
||||
pub async fn insert(
|
||||
&self,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<DelphiReportIssueId, DatabaseError> {
|
||||
Ok(DelphiReportIssueId(
|
||||
sqlx::query_scalar!(
|
||||
@@ -193,7 +196,7 @@ impl DBDelphiReportIssue {
|
||||
self.report_id as DelphiReportId,
|
||||
self.issue_type,
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?,
|
||||
))
|
||||
}
|
||||
@@ -234,7 +237,7 @@ pub struct ReportIssueDetail {
|
||||
impl ReportIssueDetail {
|
||||
pub async fn insert(
|
||||
&self,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<DelphiReportIssueDetailsId, DatabaseError> {
|
||||
Ok(DelphiReportIssueDetailsId(sqlx::query_scalar!(
|
||||
"
|
||||
@@ -249,19 +252,19 @@ impl ReportIssueDetail {
|
||||
sqlx::types::Json(&self.data) as Json<&HashMap<String, serde_json::Value>>,
|
||||
self.severity as DelphiSeverity,
|
||||
)
|
||||
.fetch_one(&mut **transaction)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await?))
|
||||
}
|
||||
|
||||
pub async fn remove_all_by_issue_id(
|
||||
issue_id: DelphiReportIssueId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
transaction: &mut PgTransaction<'_>,
|
||||
) -> Result<u64, DatabaseError> {
|
||||
Ok(sqlx::query!(
|
||||
"DELETE FROM delphi_report_issue_details WHERE issue_id = $1",
|
||||
issue_id as DelphiReportIssueId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.execute(&mut *transaction)
|
||||
.await?
|
||||
.rows_affected())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user