Class: Jackcess::Database::TableBuilderDSL Private
- Inherits:
-
Object
- Object
- Jackcess::Database::TableBuilderDSL
- Defined in:
- lib/jackcess/database.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
DSL (Domain-Specific Language) for building table schemas.
This class provides a fluent interface for defining table columns and indexes when creating new tables. It’s used internally by #create_table.
Instance Method Summary collapse
-
#column(name, type, options = {}) ⇒ void
private
Defines a column in the table.
-
#initialize(builder) ⇒ TableBuilderDSL
constructor
private
Creates a new table builder DSL instance.
-
#primary_key(column_name) ⇒ void
private
Defines the primary key for the table.
Constructor Details
#initialize(builder) ⇒ TableBuilderDSL
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new table builder DSL instance.
372 373 374 375 |
# File 'lib/jackcess/database.rb', line 372 def initialize(builder) @builder = builder @primary_key_column = nil end |
Instance Method Details
#column(name, type, options = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines a column in the table.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/jackcess/database.rb', line 399 def column(name, type, = {}) raise ArgumentError, "Column name cannot be nil" if name.nil? raise ArgumentError, "Column name must be a String or Symbol" unless name.is_a?(String) || name.is_a?(Symbol) raise ArgumentError, "Column name cannot be empty" if name.to_s.empty? raise ArgumentError, "Column type cannot be nil" if type.nil? data_type = TypeConverter.ruby_type_to_data_type(type) col_builder = ColumnBuilder.new(name, data_type) col_builder.set_length([:length]) if [:length] col_builder.set_auto_number([:auto_number]) if [:auto_number] @builder.add_column(col_builder.to_column) end |
#primary_key(column_name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines the primary key for the table.
428 429 430 431 432 433 434 435 436 437 |
# File 'lib/jackcess/database.rb', line 428 def primary_key(column_name) raise ArgumentError, "Primary key column name cannot be nil" if column_name.nil? index_builder = com.healthmarketscience.jackcess.IndexBuilder.new( com.healthmarketscience.jackcess.IndexBuilder::PRIMARY_KEY_NAME ) index_builder.add_columns(column_name) index_builder.set_primary_key @builder.add_index(index_builder) end |