pub struct ColumnDefinition {
pub name: String,
pub nullable: bool,
/* private fields */
}Expand description
A column definition.
This struct supports both string-based type names (for simplicity) and SqlType-based definitions (for type safety). Internally, it uses a single source of truth to avoid synchronization issues.
Fields§
§name: StringColumn name.
nullable: boolWhether the column is nullable.
Implementations§
Source§impl ColumnDefinition
impl ColumnDefinition
Sourcepub fn new(
name: impl Into<String>,
type_name: impl Into<String>,
nullable: bool,
) -> Self
pub fn new( name: impl Into<String>, type_name: impl Into<String>, nullable: bool, ) -> Self
Creates a new column definition using a type name string.
§Example
use hyperdb_api::ColumnDefinition;
let col = ColumnDefinition::new("id", "INT", false);
assert_eq!(col.name, "id");
assert_eq!(col.type_name(), "INT");Sourcepub fn with_sql_type(
name: impl Into<String>,
sql_type: SqlType,
nullability: Nullability,
) -> Self
pub fn with_sql_type( name: impl Into<String>, sql_type: SqlType, nullability: Nullability, ) -> Self
Creates a column definition using SqlType.
§Example
use hyperdb_api::ColumnDefinition;
use hyperdb_api_core::types::{SqlType, Nullability};
let col = ColumnDefinition::with_sql_type("id", SqlType::int(), Nullability::NotNullable);
assert_eq!(col.name, "id");
assert!(!col.nullable);Sourcepub fn with_collation(
name: impl Into<String>,
sql_type: SqlType,
collation: impl Into<String>,
nullability: Nullability,
) -> Self
pub fn with_collation( name: impl Into<String>, sql_type: SqlType, collation: impl Into<String>, nullability: Nullability, ) -> Self
Creates a column definition with a collation.
The collation specifies the sorting and comparison behavior for text columns.
§Example
use hyperdb_api::ColumnDefinition;
use hyperdb_api_core::types::{SqlType, Nullability};
let col = ColumnDefinition::with_collation("name", SqlType::text(), "en_US", Nullability::Nullable);
assert_eq!(col.collation(), Some("en_US"));Sourcepub fn nullable(name: impl Into<String>, sql_type: SqlType) -> Self
pub fn nullable(name: impl Into<String>, sql_type: SqlType) -> Self
Creates a nullable column definition using SqlType.
Sourcepub fn not_null(name: impl Into<String>, sql_type: SqlType) -> Self
pub fn not_null(name: impl Into<String>, sql_type: SqlType) -> Self
Creates a non-nullable column definition using SqlType.
Sourcepub fn nullability(&self) -> Nullability
pub fn nullability(&self) -> Nullability
Returns the nullability as a Nullability enum.
Sourcepub fn sql_type(&self) -> Option<SqlType>
pub fn sql_type(&self) -> Option<SqlType>
Returns the SQL type if this column was created with a structured type.
Sourcepub fn type_name(&self) -> Cow<'_, str>
pub fn type_name(&self) -> Cow<'_, str>
Returns the type name string representation.
When created with SqlType, this is derived from it. Otherwise, it’s the
string provided during construction.
Returns Cow<str> to avoid allocation when the type name is already stored
as a string internally.
Sourcepub fn set_collation(&mut self, collation: impl Into<String>)
pub fn set_collation(&mut self, collation: impl Into<String>)
Sets the collation for this column.
Sourcepub fn set_sql_type(&mut self, sql_type: SqlType)
pub fn set_sql_type(&mut self, sql_type: SqlType)
Sets the SQL type, replacing any previous type information.
This replaces the internal type representation with the provided SqlType.
Sourcepub fn to_types_column_definition(&self) -> Option<TypesColumnDefinition>
pub fn to_types_column_definition(&self) -> Option<TypesColumnDefinition>
Converts to the hyper-types ColumnDefinition (if SqlType is set).
Trait Implementations§
Source§impl Clone for ColumnDefinition
impl Clone for ColumnDefinition
Source§fn clone(&self) -> ColumnDefinition
fn clone(&self) -> ColumnDefinition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ColumnDefinition
impl Debug for ColumnDefinition
Source§impl From<ColumnDefinition> for ColumnDefinition
impl From<ColumnDefinition> for ColumnDefinition
Source§fn from(col: TypesColumnDefinition) -> Self
fn from(col: TypesColumnDefinition) -> Self
Auto Trait Implementations§
impl Freeze for ColumnDefinition
impl RefUnwindSafe for ColumnDefinition
impl Send for ColumnDefinition
impl Sync for ColumnDefinition
impl Unpin for ColumnDefinition
impl UnsafeUnpin for ColumnDefinition
impl UnwindSafe for ColumnDefinition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request