Module: ActiveRecord::ConnectionAdapters::Duckdb::ColumnMethods
- Extended by:
- ActiveSupport::Concern, ConnectionAdapters::ColumnMethods::ClassMethods
- Included in:
- Table, TableDefinition
- Defined in:
- lib/active_record/connection_adapters/duckdb/schema_definitions.rb
Overview
DuckDB-specific column method definitions for table creation Provides both standard Rails column types and DuckDB-specific data types
Instance Method Summary collapse
-
#enum(name, values: []) ⇒ void
Creates an ENUM column with predefined values.
-
#list(name, element_type: :string) ⇒ void
Creates a LIST column with specified element type.
-
#map(name, key_type: :string, value_type: :string) ⇒ void
Creates a MAP column with specified key and value types.
-
#struct(name, fields: {}) ⇒ void
Creates a STRUCT column with named fields.
Instance Method Details
#enum(name, values: []) ⇒ void
This method returns an undefined value.
Creates an ENUM column with predefined values
82 83 84 85 |
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 82 def enum(name, values: [], **) enum_values = values.map { |v| "'#{v}'" }.join(', ') column(name, "ENUM(#{enum_values})", **) end |
#list(name, element_type: :string) ⇒ void
This method returns an undefined value.
Creates a LIST column with specified element type
50 51 52 |
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 50 def list(name, element_type: :string, **) column(name, "#{element_type.to_s.upcase}[]", **) end |
#map(name, key_type: :string, value_type: :string) ⇒ void
This method returns an undefined value.
Creates a MAP column with specified key and value types
72 73 74 |
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 72 def map(name, key_type: :string, value_type: :string, **) column(name, "MAP(#{key_type.to_s.upcase}, #{value_type.to_s.upcase})", **) end |
#struct(name, fields: {}) ⇒ void
This method returns an undefined value.
Creates a STRUCT column with named fields
60 61 62 63 |
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 60 def struct(name, fields: {}, **) field_definitions = fields.map { |field_name, field_type| "#{field_name} #{field_type.to_s.upcase}" } column(name, "STRUCT(#{field_definitions.join(", ")})", **) end |