use prax_query::row::{RowError, RowRef, into_row_error};
use tokio_postgres::Row;
#[repr(transparent)]
pub struct PgRow(Row);
impl PgRow {
pub fn into_inner(self) -> Row {
self.0
}
}
impl std::ops::Deref for PgRow {
type Target = Row;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<Row> for PgRow {
fn from(row: Row) -> Self {
PgRow(row)
}
}
impl RowRef for PgRow {
fn get_i32(&self, c: &str) -> Result<i32, RowError> {
into_row_error(c, self.try_get::<_, i32>(c))
}
fn get_i32_opt(&self, c: &str) -> Result<Option<i32>, RowError> {
into_row_error(c, self.try_get::<_, Option<i32>>(c))
}
fn get_i64(&self, c: &str) -> Result<i64, RowError> {
into_row_error(c, self.try_get::<_, i64>(c))
}
fn get_i64_opt(&self, c: &str) -> Result<Option<i64>, RowError> {
into_row_error(c, self.try_get::<_, Option<i64>>(c))
}
fn get_f64(&self, c: &str) -> Result<f64, RowError> {
into_row_error(c, self.try_get::<_, f64>(c))
}
fn get_f64_opt(&self, c: &str) -> Result<Option<f64>, RowError> {
into_row_error(c, self.try_get::<_, Option<f64>>(c))
}
fn get_bool(&self, c: &str) -> Result<bool, RowError> {
into_row_error(c, self.try_get::<_, bool>(c))
}
fn get_bool_opt(&self, c: &str) -> Result<Option<bool>, RowError> {
into_row_error(c, self.try_get::<_, Option<bool>>(c))
}
fn get_str(&self, c: &str) -> Result<&str, RowError> {
into_row_error(c, self.try_get::<_, &str>(c))
}
fn get_str_opt(&self, c: &str) -> Result<Option<&str>, RowError> {
into_row_error(c, self.try_get::<_, Option<&str>>(c))
}
fn get_bytes(&self, c: &str) -> Result<&[u8], RowError> {
into_row_error(c, self.try_get::<_, &[u8]>(c))
}
fn get_bytes_opt(&self, c: &str) -> Result<Option<&[u8]>, RowError> {
into_row_error(c, self.try_get::<_, Option<&[u8]>>(c))
}
fn get_datetime_utc(&self, c: &str) -> Result<chrono::DateTime<chrono::Utc>, RowError> {
into_row_error(c, self.try_get::<_, chrono::DateTime<chrono::Utc>>(c))
}
fn get_datetime_utc_opt(
&self,
c: &str,
) -> Result<Option<chrono::DateTime<chrono::Utc>>, RowError> {
into_row_error(
c,
self.try_get::<_, Option<chrono::DateTime<chrono::Utc>>>(c),
)
}
fn get_naive_datetime(&self, c: &str) -> Result<chrono::NaiveDateTime, RowError> {
into_row_error(c, self.try_get::<_, chrono::NaiveDateTime>(c))
}
fn get_naive_datetime_opt(&self, c: &str) -> Result<Option<chrono::NaiveDateTime>, RowError> {
into_row_error(c, self.try_get::<_, Option<chrono::NaiveDateTime>>(c))
}
fn get_naive_date(&self, c: &str) -> Result<chrono::NaiveDate, RowError> {
into_row_error(c, self.try_get::<_, chrono::NaiveDate>(c))
}
fn get_naive_date_opt(&self, c: &str) -> Result<Option<chrono::NaiveDate>, RowError> {
into_row_error(c, self.try_get::<_, Option<chrono::NaiveDate>>(c))
}
fn get_naive_time(&self, c: &str) -> Result<chrono::NaiveTime, RowError> {
into_row_error(c, self.try_get::<_, chrono::NaiveTime>(c))
}
fn get_naive_time_opt(&self, c: &str) -> Result<Option<chrono::NaiveTime>, RowError> {
into_row_error(c, self.try_get::<_, Option<chrono::NaiveTime>>(c))
}
fn get_uuid(&self, c: &str) -> Result<uuid::Uuid, RowError> {
into_row_error(c, self.try_get::<_, uuid::Uuid>(c))
}
fn get_uuid_opt(&self, c: &str) -> Result<Option<uuid::Uuid>, RowError> {
into_row_error(c, self.try_get::<_, Option<uuid::Uuid>>(c))
}
fn get_json(&self, c: &str) -> Result<serde_json::Value, RowError> {
into_row_error(c, self.try_get::<_, serde_json::Value>(c))
}
fn get_json_opt(&self, c: &str) -> Result<Option<serde_json::Value>, RowError> {
into_row_error(c, self.try_get::<_, Option<serde_json::Value>>(c))
}
fn get_decimal(&self, c: &str) -> Result<rust_decimal::Decimal, RowError> {
Err(RowError::TypeConversion {
column: c.to_string(),
message: "decimal columns require tokio-postgres with \
`with-rust_decimal-*` feature, which this workspace does not \
currently enable. Cast NUMERIC columns to TEXT in your SQL \
(e.g. amount::text) and decode as String, or upgrade \
tokio-postgres."
.to_string(),
})
}
fn get_decimal_opt(&self, c: &str) -> Result<Option<rust_decimal::Decimal>, RowError> {
Err(RowError::TypeConversion {
column: c.to_string(),
message: "decimal columns require tokio-postgres with \
`with-rust_decimal-*` feature, which this workspace does not \
currently enable. Cast NUMERIC columns to TEXT in your SQL \
(e.g. amount::text) and decode as String, or upgrade \
tokio-postgres."
.to_string(),
})
}
}