Class: Tablature::Adapters::Postgres::Handlers::List Private
- Defined in:
- lib/tablature/adapters/postgres/handlers/list.rb
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.
Instance Method Summary collapse
- #create_list_partition(table_name, options, &block) ⇒ Object private
- #create_list_partition_of(parent_table, options) ⇒ Object private
-
#initialize(connection) ⇒ List
constructor
private
A new instance of List.
Methods included from UUID
Methods included from Quoting
#quote_collection, #quote_partition_key
Constructor Details
#initialize(connection) ⇒ List
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.
Returns a new instance of List.
9 10 11 |
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 9 def initialize(connection) @connection = connection end |
Instance Method Details
#create_list_partition(table_name, options, &block) ⇒ Object
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.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 13 def create_list_partition(table_name, , &block) raise_unless_list_partition_supported # Postgres 10 does not handle indexes and therefore primary keys. # Therefore we manually create an `id` column. # TODO: Either make the library Postgres 11 only, or two code paths between Postgres 10 # and Postgres 11. = .except(:id, :primary_key, :partition_key) = extract_primary_key!(.slice(:id, :primary_key)) partition_key = .fetch(:partition_key) [:id] = false [:options] = "PARTITION BY LIST (#{quote_partition_key(partition_key)})" create_partition(table_name, , , &block) end |
#create_list_partition_of(parent_table, options) ⇒ Object
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tablature/adapters/postgres/handlers/list.rb', line 30 def create_list_partition_of(parent_table, ) values = .fetch(:values, []) raise MissingListPartitionValuesError if values.blank? name = .fetch(:name, partition_name(parent_table, values)) # TODO: Call `create_table` here instead of running the query. # TODO: Pass the options to `create_table` to allow further configuration of the table, # e.g. sub-partitioning the table. query = <<~SQL.strip CREATE TABLE #{quote_table_name(name)} PARTITION OF #{quote_table_name(parent_table)} FOR VALUES IN (#{quote_collection(values)}) SQL execute(query) end |