pub struct TableBuilder { /* private fields */ }Expand description
Builder for creating database tables
This builder provides a fluent, chainable API for constructing tables with comprehensive validation and configuration options.
§Examples
use ignis_db::builders::{TableBuilder, ColumnBuilder, table};
use ignis_db::schema::ColumnType;
// Basic table
let users_table = TableBuilder::new("users")
.column(ColumnBuilder::new("id", ColumnType::Int4).primary_key())
.column(ColumnBuilder::new("email", ColumnType::Varchar(Some(255))).unique())
.build()?;
// Advanced table with constraints and indexes
let posts_table = TableBuilder::new("posts")
.schema("blog")
.column(ColumnBuilder::new("id", ColumnType::Int4).primary_key())
.column(ColumnBuilder::new("user_id", ColumnType::Int4).not_null())
.column(ColumnBuilder::new("title", ColumnType::Varchar(Some(200))).not_null())
.column(ColumnBuilder::new("content", ColumnType::Text))
.column(ColumnBuilder::new("published", ColumnType::Bool).default("false"))
.column(ColumnBuilder::new("created_at", ColumnType::Timestamptz).default("NOW()"))
.comment("Blog posts table")
.build()?;
// Using convenience function
let simple_table = table("simple")
.column(ColumnBuilder::new("id", ColumnType::Int4).primary_key())
.build()?;Implementations§
Source§impl TableBuilder
impl TableBuilder
Sourcepub fn column(self, column: ColumnBuilder) -> Self
pub fn column(self, column: ColumnBuilder) -> Self
Sourcepub fn add_column(
self,
name: impl Into<String>,
definition: impl Into<String>,
) -> Self
pub fn add_column( self, name: impl Into<String>, definition: impl Into<String>, ) -> Self
Add a column with a simple string definition (convenience method)
§Parameters
name: The column namedefinition: The column definition (e.g., “UUID PRIMARY KEY DEFAULT gen_random_uuid()”)
§Examples
let table = TableBuilder::new("users")
.add_column("id", "UUID PRIMARY KEY DEFAULT gen_random_uuid()")
.add_column("email", "VARCHAR(255) UNIQUE NOT NULL")
.add_column("created_at", "TIMESTAMPTZ DEFAULT NOW()")
.build()?;Sourcepub fn columns(self, columns: Vec<ColumnBuilder>) -> Self
pub fn columns(self, columns: Vec<ColumnBuilder>) -> Self
Add multiple columns to the table
§Parameters
columns: Vector of column builders to add
§Examples
let columns = vec![
ColumnBuilder::new("id", ColumnType::Int4).primary_key(),
ColumnBuilder::new("email", ColumnType::Varchar(Some(255))),
ColumnBuilder::new("name", ColumnType::Varchar(Some(100))),
];
let table = TableBuilder::new("users")
.columns(columns)
.build()?;Sourcepub fn inherits_from(self, parent_table: impl Into<String>) -> Self
pub fn inherits_from(self, parent_table: impl Into<String>) -> Self
Sourcepub fn partition_by(self, strategy: PartitionStrategy) -> Self
pub fn partition_by(self, strategy: PartitionStrategy) -> Self
Sourcepub fn get_schema(&self) -> Option<&str>
pub fn get_schema(&self) -> Option<&str>
Get the schema name
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns
Sourcepub fn has_primary_key(&self) -> bool
pub fn has_primary_key(&self) -> bool
Check if the table has a primary key
Sourcepub fn primary_key_columns(&self) -> Vec<&str>
pub fn primary_key_columns(&self) -> Vec<&str>
Get the primary key column names
Sourcepub fn has_foreign_keys(&self) -> bool
pub fn has_foreign_keys(&self) -> bool
Check if the table has any foreign key references
Sourcepub fn storage_parameter_count(&self) -> usize
pub fn storage_parameter_count(&self) -> usize
Get the number of storage parameters
Sourcepub fn has_inheritance(&self) -> bool
pub fn has_inheritance(&self) -> bool
Check if the table inherits from other tables
Sourcepub fn is_partitioned(&self) -> bool
pub fn is_partitioned(&self) -> bool
Check if the table is partitioned
Source§impl TableBuilder
impl TableBuilder
Sourcepub fn enable_rls(self) -> Self
pub fn enable_rls(self) -> Self
Enable Row-Level Security on this table
§Examples
use ignis_db::builders::TableBuilder;
let table = TableBuilder::new("users")
.enable_rls()
.build()?;Sourcepub fn disable_rls(self) -> Self
pub fn disable_rls(self) -> Self
Disable Row-Level Security on this table
Sourcepub fn add_policy(self, policy: Policy) -> Self
pub fn add_policy(self, policy: Policy) -> Self
Add a policy to this table
§Examples
use ignis_db::builders::{TableBuilder, PolicyBuilder};
use ignis_db::schema::PolicyCommand;
let policy = PolicyBuilder::for_table("users")
.name("user_access_policy")
.allow_all()
.for_role("authenticated_user")
.using_expression("id = current_setting('jwt.claims.user_id')::UUID")
.build()?;
let table = TableBuilder::new("users")
.enable_rls()
.add_policy(policy)
.build()?;Sourcepub fn add_policies(self, policies: Vec<Policy>) -> Self
pub fn add_policies(self, policies: Vec<Policy>) -> Self
Add multiple policies to this table
Sourcepub fn is_rls_enabled(&self) -> bool
pub fn is_rls_enabled(&self) -> bool
Check if RLS is enabled
Trait Implementations§
Source§impl Clone for TableBuilder
impl Clone for TableBuilder
Source§fn clone(&self) -> TableBuilder
fn clone(&self) -> TableBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ConditionalBuilder for TableBuilder
impl ConditionalBuilder for TableBuilder
Source§impl Debug for TableBuilder
impl Debug for TableBuilder
Source§impl InspectableBuilder for TableBuilder
impl InspectableBuilder for TableBuilder
Source§impl SchemaBuilder for TableBuilder
impl SchemaBuilder for TableBuilder
Source§impl ValidatableBuilder for TableBuilder
impl ValidatableBuilder for TableBuilder
Auto Trait Implementations§
impl Freeze for TableBuilder
impl RefUnwindSafe for TableBuilder
impl Send for TableBuilder
impl Sync for TableBuilder
impl Unpin for TableBuilder
impl UnsafeUnpin for TableBuilder
impl UnwindSafe for TableBuilder
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more