/
germanubis
/
sqlx
Обзор
Документация
Войти
/
germanubis
/
sqlx
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
sqlx-postgres/src/row.rs
56 строк
1 KB
David Cornu
feat: Unify `Debug` implementations across `PgRow`, `MySqlRow` and `SqliteRow` (#3890)
07 июл 2025, 05:24
Не верифицирован
07 июл 2025, 05:24
2702b98
Код
Авторство
О чём код?
use crate::column::ColumnIndex; use crate::error::Error; use crate::message::DataRow; use crate::statement::PgStatementMetadata; use crate::value::PgValueFormat; use crate::{PgColumn, PgValueRef, Postgres}; use sqlx_core::row::debug_row; pub(crate) use sqlx_core::row::Row; use std::sync::Arc; /// Implementation of [`Row`] for PostgreSQL. pub struct PgRow { pub(crate) data: DataRow, pub(crate) format: PgValueFormat, pub(crate) metadata: Arc<PgStatementMetadata>, } impl Row for PgRow { type Database = Postgres; fn columns(&self) -> &[PgColumn] { &self.metadata.columns } fn try_get_raw<I>(&self, index: I) -> Result<PgValueRef<'_>, Error> where I: ColumnIndex<Self>, { let index = index.index(self)?; let column = &self.metadata.columns[index]; let value = self.data.get(index); Ok(PgValueRef { format: self.format, row: Some(&self.data.storage), type_info: column.type_info.clone(), value, }) } } impl ColumnIndex<PgRow> for &'_ str { fn index(&self, row: &PgRow) -> Result<usize, Error> { row.metadata .column_names .get(*self) .ok_or_else(|| Error::ColumnNotFound((*self).into())) .copied() } } impl std::fmt::Debug for PgRow { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { debug_row(self, f) } }