Class TableSchema.Builder
java.lang.Object
group.worldstandard.pudel.api.database.TableSchema.Builder
- Enclosing class:
TableSchema
Builder class for constructing
TableSchema instances.
Provides a fluent API for defining table structure including columns and indexes.
Validates table and column names according to naming conventions.
Table names must start with a lowercase letter and contain only lowercase letters, numbers, and underscores.
Column names follow the same rules but cannot be reserved words like 'id', 'created_at', or 'updated_at'.-
Method Summary
Modifier and TypeMethodDescriptionbuild()column(String name, ColumnType type, boolean nullable) Add a column to the schema.column(String name, ColumnType type, boolean nullable, String defaultValue) Add a column with a default value.column(String name, ColumnType type, Integer size, boolean nullable) Add a column with a size constraint.column(String name, ColumnType type, Integer size, boolean nullable, String defaultValue) Add a column with all options.Add an index on one or more columns.uniqueIndex(String... columnNames) Add a unique index on one or more columns.
-
Method Details
-
column
Add a column to the schema.- Parameters:
name- column nametype- column typenullable- whether the column can be null- Returns:
- this builder
-
column
Add a column with a size constraint.- Parameters:
name- column nametype- column typesize- size/length for VARCHAR, etc.nullable- whether the column can be null- Returns:
- this builder
-
column
public TableSchema.Builder column(String name, ColumnType type, boolean nullable, String defaultValue) Add a column with a default value.- Parameters:
name- column nametype- column typenullable- whether the column can be nulldefaultValue- SQL default value expression- Returns:
- this builder
-
column
public TableSchema.Builder column(String name, ColumnType type, Integer size, boolean nullable, String defaultValue) Add a column with all options.- Parameters:
name- column nametype- column typesize- size/length (nullable)nullable- whether the column can be nulldefaultValue- SQL default value expression (nullable)- Returns:
- this builder
-
index
Add an index on one or more columns.- Parameters:
columnNames- the columns to index- Returns:
- this builder
-
uniqueIndex
Add a unique index on one or more columns.- Parameters:
columnNames- the columns for the unique constraint- Returns:
- this builder
-
build
-