pub trait IntoValue {
// Required method
fn add_to_inserter(&self, inserter: &mut Inserter<'_>) -> Result<()>;
}Expand description
Trait for types that can be inserted into a Hyper table.
This trait is implemented for common Rust types, allowing them to be
used with Inserter::add_row() for type-safe insertion.
§Supported Types
- Integers:
i16,i32,i64 - Floats:
f32,f64 bool&str,StringOption<T>whereT: IntoValue(for nullable columns)- Date/time types:
Date,Time,Timestamp,Interval Numeric,Geography,Oid,Vec<u8>(bytes)
§Example
use hyperdb_api::{Connection, CreateMode, Catalog, TableDefinition, Inserter, IntoValue, SqlType, Result};
fn main() -> Result<()> {
let conn = Connection::connect("localhost:7483", "test.hyper", CreateMode::CreateIfNotExists)?;
let table_def = TableDefinition::new("example")
.add_required_column("a", SqlType::int())
.add_nullable_column("b", SqlType::text())
.add_nullable_column("c", SqlType::double());
Catalog::new(&conn).create_table(&table_def)?;
let mut inserter = Inserter::new(&conn, &table_def)?;
// IntoValue allows adding rows with mixed types
inserter.add_row(&[&1i32, &"Alice", &Some(3.14f64)])?;
inserter.add_row(&[&2i32, &"Bob", &None::<f64>])?; // NULL value
inserter.execute()?;
Ok(())
}Required Methods§
Sourcefn add_to_inserter(&self, inserter: &mut Inserter<'_>) -> Result<()>
fn add_to_inserter(&self, inserter: &mut Inserter<'_>) -> Result<()>
Adds this value to the inserter.
§Errors
Implementations call the matching Inserter::add_* method and
forward its error — see Inserter::add_bool for the shared
failure modes (too many columns, NULL into non-nullable, etc).