Class: Fx::Adapters::Postgres
- Inherits:
-
Object
- Object
- Fx::Adapters::Postgres
- Defined in:
- lib/fx/adapters/postgres.rb,
lib/fx/adapters/postgres/triggers.rb,
lib/fx/adapters/postgres/functions.rb,
lib/fx/adapters/postgres/connection.rb
Overview
Creates an instance of the F(x) Postgres adapter.
This is the default adapter for F(x). Configuring it via Fx.configure is not required, but the example below shows how one would explicitly set it.
Instance Method Summary collapse
-
#create_function(sql_definition) ⇒ void
Creates a function in the database.
-
#create_trigger(sql_definition) ⇒ void
Creates a trigger in the database.
-
#drop_function(name) ⇒ void
Drops the function from the database.
-
#drop_trigger(name, on:) ⇒ void
Drops the trigger from the database.
-
#functions ⇒ Array<Fx::Function>
Returns an array of functions in the database.
-
#initialize(connectable = ActiveRecord::Base) ⇒ Postgres
constructor
Creates an instance of the F(x) Postgres adapter.
-
#triggers ⇒ Array<Fx::Trigger>
Returns an array of triggers in the database.
-
#update_function(name, sql_definition) ⇒ void
Updates a function in the database.
-
#update_trigger(name, on:, sql_definition:) ⇒ void
Updates a trigger in the database.
Constructor Details
#initialize(connectable = ActiveRecord::Base) ⇒ Postgres
Creates an instance of the F(x) Postgres adapter.
This is the default adapter for F(x). Configuring it via Fx.configure is not required, but the example below shows how one would explicitly set it.
39 40 41 |
# File 'lib/fx/adapters/postgres.rb', line 39 def initialize(connectable = ActiveRecord::Base) @connectable = connectable end |
Instance Method Details
#create_function(sql_definition) ⇒ void
This method returns an undefined value.
Creates a function in the database.
This is typically called in a migration via Statements::Function#create_function.
71 72 73 |
# File 'lib/fx/adapters/postgres.rb', line 71 def create_function(sql_definition) execute(sql_definition) end |
#create_trigger(sql_definition) ⇒ void
This method returns an undefined value.
Creates a trigger in the database.
This is typically called in a migration via Statements::Trigger#create_trigger.
83 84 85 |
# File 'lib/fx/adapters/postgres.rb', line 83 def create_trigger(sql_definition) execute(sql_definition) end |
#drop_function(name) ⇒ void
This method returns an undefined value.
Drops the function from the database
This is typically called in a migration via Statements::Function#drop_function.
127 128 129 130 131 132 133 |
# File 'lib/fx/adapters/postgres.rb', line 127 def drop_function(name) if connection.support_drop_function_without_args execute("DROP FUNCTION #{name};") else execute("DROP FUNCTION #{name}();") end end |
#drop_trigger(name, on:) ⇒ void
This method returns an undefined value.
Drops the trigger from the database
This is typically called in a migration via Statements::Trigger#drop_trigger.
144 145 146 |
# File 'lib/fx/adapters/postgres.rb', line 144 def drop_trigger(name, on:) execute("DROP TRIGGER #{name} ON #{on};") end |
#functions ⇒ Array<Fx::Function>
Returns an array of functions in the database.
This collection of functions is used by the [Fx::SchemaDumper] to
populate the schema.rb
file.
49 50 51 |
# File 'lib/fx/adapters/postgres.rb', line 49 def functions Functions.all(connection) end |
#triggers ⇒ Array<Fx::Trigger>
Returns an array of triggers in the database.
This collection of triggers is used by the [Fx::SchemaDumper] to
populate the schema.rb
file.
59 60 61 |
# File 'lib/fx/adapters/postgres.rb', line 59 def triggers Triggers.all(connection) end |
#update_function(name, sql_definition) ⇒ void
This method returns an undefined value.
Updates a function in the database.
This is typically called in a migration via Statements::Function#update_function.
96 97 98 99 |
# File 'lib/fx/adapters/postgres.rb', line 96 def update_function(name, sql_definition) drop_function(name) create_function(sql_definition) end |
#update_trigger(name, on:, sql_definition:) ⇒ void
This method returns an undefined value.
Updates a trigger in the database.
The existing trigger is dropped and recreated using the supplied on
and version
parameter.
This is typically called in a migration via Statements::Function#update_trigger.
114 115 116 117 |
# File 'lib/fx/adapters/postgres.rb', line 114 def update_trigger(name, on:, sql_definition:) drop_trigger(name, on: on) create_trigger(sql_definition) end |