Class: Messaging::Adapters::Postgres::Categories
- Inherits:
-
Object
- Object
- Messaging::Adapters::Postgres::Categories
- Includes:
- Enumerable
- Defined in:
- lib/messaging/adapters/postgres/categories.rb,
lib/messaging/adapters/postgres/categories/row.rb
Defined Under Namespace
Classes: Row
Instance Method Summary collapse
-
#[](name) ⇒ nil, Category
Get a category by name.
-
#create(name) ⇒ Category
Creates a table partition for the given category.
-
#create_and_partition_by_day(name) ⇒ CategoryWithPartitions
Creates a table partition for the given category that in turn is partitioned based on created_at.
-
#drop(name) ⇒ Object
Drops the table partition (including all messages) for the given category.
- #each ⇒ Object
Instance Method Details
#[](name) ⇒ nil, Category
Get a category by name
16 17 18 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 16 def [](name) all_categories.find { |c| c.name == name } end |
#create(name) ⇒ Category
Creates a table partition for the given category
24 25 26 27 28 29 30 31 32 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 24 def create(name) table_name = Category.table_name_for(name) sql = " CREATE TABLE IF NOT EXISTS messaging.\#{table_name}\n PARTITION OF messaging.messages FOR VALUES IN ('\#{name}');\n SQL\n connection.execute sql\n Category.new(name, table_name)\nend\n" |
#create_and_partition_by_day(name) ⇒ CategoryWithPartitions
Creates a table partition for the given category that in turn is partitioned based on created_at
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 39 def create_and_partition_by_day(name) table_name = Category.table_name_for(name) sql = " CREATE TABLE IF NOT EXISTS messaging.\#{table_name}\n PARTITION OF messaging.messages FOR VALUES IN ('\#{name}')\n PARTITION BY RANGE (created_at);\n SQL\n connection.execute sql\n CategoryWithPartitions.new(name, table_name)\nend\n" |
#drop(name) ⇒ Object
Drops the table partition (including all messages) for the given category
53 54 55 56 57 58 59 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 53 def drop(name) table_name = Category.table_name_for(name) sql = " drop TABLE messaging.\#{table_name}\n SQL\n connection.execute sql\nend\n" |
#each ⇒ Object
7 8 9 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 7 def each all_categories.each { |c| yield c } end |