Class: ActiveRecord::ConnectionAdapters::Duckdb::TableDefinition

Inherits:
TableDefinition
  • Object
show all
Includes:
ColumnMethods
Defined in:
lib/active_record/connection_adapters/duckdb/schema_definitions.rb

Overview

DuckDB-specific table definition for CREATE TABLE statements Extends Rails' TableDefinition with DuckDB column types and features

Instance Method Summary collapse

Methods included from ColumnMethods

#enum, #list, #map, #struct

Constructor Details

#initialize(conn, name, temporary: false, if_not_exists: false, options: nil, as: nil, comment: nil, **table_options) ⇒ TableDefinition

Initialize a new DuckDB table definition

Parameters:

  • conn (ActiveRecord::ConnectionAdapters::DuckdbAdapter)

    The database adapter

  • name (String, Symbol)

    The table name

  • temporary (Boolean) (defaults to: false)

    Whether this is a temporary table

  • if_not_exists (Boolean) (defaults to: false)

    Whether to use IF NOT EXISTS clause

  • options (Hash, nil) (defaults to: nil)

    Additional table options

  • as (String, nil) (defaults to: nil)

    SELECT statement for CREATE TABLE AS

  • comment (String, nil) (defaults to: nil)

    Table comment

  • table_options (Hash)

    Additional keyword table options



107
108
109
110
111
112
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 107

def initialize(conn, name, temporary: false, if_not_exists: false,
               options: nil, as: nil, comment: nil, **table_options)
  super
  @conn = conn
  @table_name = name
end

Instance Method Details

#column(name, type, index: nil, **options) ⇒ void

This method returns an undefined value.

Creates a column definition for the table Note: sequence defaults are handled by ALTER TABLE after table creation

Parameters:

  • name (String, Symbol)

    The column name

  • type (Symbol)

    The column type

  • index (Boolean, Hash, nil) (defaults to: nil)

    Whether to create an index on this column

  • options (Hash)

    Additional column options



121
122
123
124
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 121

def column(name, type, index: nil, **options)
  # Don't set sequence defaults here - they're handled in create_table via ALTER TABLE
  super
end

#primary_key(name, type = :primary_key, **options) ⇒ void

This method returns an undefined value.

Creates a primary key column definition Note: sequence defaults are handled by ALTER TABLE after table creation

Parameters:

  • name (String, Symbol)

    The primary key column name

  • type (Symbol) (defaults to: :primary_key)

    The primary key column type (default: :primary_key)

  • options (Hash)

    Additional column options



132
133
134
135
# File 'lib/active_record/connection_adapters/duckdb/schema_definitions.rb', line 132

def primary_key(name, type = :primary_key, **options)
  # Don't set sequence defaults here - they're handled in create_table via ALTER TABLE
  super
end