Class: Messaging::Adapters::Postgres::Categories
- Inherits:
-
Object
- Object
- Messaging::Adapters::Postgres::Categories
- Includes:
- Enumerable
- Defined in:
- lib/messaging/adapters/postgres/categories.rb
Instance Method Summary collapse
-
#[](name) ⇒ nil, Category
Get a category by name.
-
#create(name) ⇒ Category
Creates a table partition for the given category.
-
#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
18 19 20 21 22 23 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 18 def [](name) category = all_categories.select { |c| c == name } return unless category Category.new(category) end |
#create(name) ⇒ Category
Creates a table partition for the given category
29 30 31 32 33 34 35 36 37 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 29 def create(name) table_name = name.parameterize(separator: '_') sql = <<~SQL CREATE TABLE messaging.#{table_name} PARTITION OF messaging.messages FOR VALUES IN ('#{name}'); SQL connection.execute sql Category.new(name) end |
#drop(name) ⇒ Object
Drops the table partition (including all messages) for the given category
42 43 44 45 46 47 48 |
# File 'lib/messaging/adapters/postgres/categories.rb', line 42 def drop(name) table_name = name.parameterize(separator: '_') sql = <<~SQL drop TABLE messaging.#{table_name} SQL connection.execute sql end |