Module: FxAggregate::Adapters::Postgres
- Defined in:
- lib/fx-aggregate/adapters/postgres.rb
Instance Method Summary collapse
-
#aggregates ⇒ Array<Fx::Aggregate>
Returns an array of aggregates in the database.
-
#create_aggregate(sql_definition) ⇒ void
Creates an aggregate in the database.
-
#drop_aggregate(name) ⇒ void
Drops the aggregate from the database.
-
#update_aggregate(name, sql_definition) ⇒ void
Updates an aggregate in the database.
Instance Method Details
#aggregates ⇒ Array<Fx::Aggregate>
Returns an array of aggregates in the database.
This collection of aggregates is used by the [Fx::SchemaDumper] to
populate the schema.rb file.
12 13 14 |
# File 'lib/fx-aggregate/adapters/postgres.rb', line 12 def aggregates ::Fx::Adapters::Postgres::Aggregates.all(connection) end |
#create_aggregate(sql_definition) ⇒ void
This method returns an undefined value.
Creates an aggregate in the database.
This is typically called in a migration via Fx::Statements::Aggregate#create_aggregate.
24 25 26 |
# File 'lib/fx-aggregate/adapters/postgres.rb', line 24 def create_aggregate(sql_definition) execute(sql_definition) end |
#drop_aggregate(name) ⇒ void
This method returns an undefined value.
Drops the aggregate from the database
This is typically called in a migration via Fx::Statements::Aggregate#drop_aggregate.
50 51 52 53 54 55 56 57 |
# File 'lib/fx-aggregate/adapters/postgres.rb', line 50 def drop_aggregate(name) defs = aggregates.select { |aggregate| aggregate.name == name.to_s } defs.each do |aggregate| execute "DROP AGGREGATE #{name}(#{aggregate.arguments});" end # execute "DROP AGGREGATE #{name}();" end |
#update_aggregate(name, sql_definition) ⇒ void
This method returns an undefined value.
Updates an aggregate in the database.
This is typically called in a migration via Fx::Statements::Aggregate#update_aggregate.
37 38 39 40 |
# File 'lib/fx-aggregate/adapters/postgres.rb', line 37 def update_aggregate(name, sql_definition) drop_aggregate(name) create_aggregate(sql_definition) end |