Skip to main content

spg_sqlx/
column.rs

1//! v7.16.0 — `sqlx::Column` for SPG result-set columns.
2
3use sqlx_core::column::Column;
4use sqlx_core::ext::ustr::UStr;
5
6use crate::database::Spg;
7use crate::type_info::SpgTypeInfo;
8
9/// Per-column metadata in an SPG result set. mailrs's
10/// `#[derive(FromRow)]` reads columns by name via
11/// [`Row::column`][sqlx_core::row::Row::column] which calls
12/// `name()` on this type.
13#[derive(Debug, Clone)]
14pub struct SpgColumn {
15    ordinal: usize,
16    name: UStr,
17    type_info: SpgTypeInfo,
18}
19
20impl SpgColumn {
21    /// Construct a column descriptor. Internal — typically
22    /// produced by the adapter when it converts an engine
23    /// `Vec<ColumnSchema>` into the sqlx `Row` shape.
24    #[must_use]
25    pub fn new(ordinal: usize, name: impl Into<String>, type_info: SpgTypeInfo) -> Self {
26        // UStr stores a &'static str OR owns its bytes — using
27        // the `new` constructor copies the input into an
28        // internal Arc so the result is `'static`-borrow-shaped
29        // without leaking.
30        let owned: String = name.into();
31        Self {
32            ordinal,
33            name: UStr::new(&owned),
34            type_info,
35        }
36    }
37}
38
39impl Column for SpgColumn {
40    type Database = Spg;
41
42    fn ordinal(&self) -> usize {
43        self.ordinal
44    }
45
46    fn name(&self) -> &str {
47        &self.name
48    }
49
50    fn type_info(&self) -> &SpgTypeInfo {
51        &self.type_info
52    }
53}