Module: FxAggregate::Adapters::Postgres

Defined in:
lib/fx-aggregate/adapters/postgres.rb

Instance Method Summary collapse

Instance Method Details

#aggregatesArray<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.

Returns:



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.

Parameters:

  • sql_definition

    The SQL schema for the 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.

Parameters:

  • name

    The name of the aggregate to drop



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.

Parameters:

  • name

    The name of the aggregate.

  • sql_definition

    The SQL schema for the 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