Class: Fx::Adapters::MySQL
- Inherits:
-
Object
- Object
- Fx::Adapters::MySQL
- Defined in:
- lib/fx/adapters/mysql.rb,
lib/fx/adapters/mysql/triggers.rb,
lib/fx/adapters/mysql/functions.rb
Overview
Creates an instance of the F(x) MySQL adapter.
Defined Under Namespace
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: nil) ⇒ void
Drops the trigger from the database.
-
#functions ⇒ Array<Fx::Function>
Returns an array of functions in the database.
-
#initialize(connectable = ActiveRecord::Base) ⇒ MySQL
constructor
Creates an instance of the F(x) MySQL 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) ⇒ MySQL
Creates an instance of the F(x) MySQL 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.
34 35 36 |
# File 'lib/fx/adapters/mysql.rb', line 34 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.
66 67 68 |
# File 'lib/fx/adapters/mysql.rb', line 66 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.
78 79 80 |
# File 'lib/fx/adapters/mysql.rb', line 78 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.
122 123 124 |
# File 'lib/fx/adapters/mysql.rb', line 122 def drop_function(name) execute "DROP FUNCTION #{name};" end |
#drop_trigger(name, on: nil) ⇒ 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.
135 136 137 |
# File 'lib/fx/adapters/mysql.rb', line 135 def drop_trigger(name, on: nil) execute "DROP TRIGGER #{name};" 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.
44 45 46 |
# File 'lib/fx/adapters/mysql.rb', line 44 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.
54 55 56 |
# File 'lib/fx/adapters/mysql.rb', line 54 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.
91 92 93 94 |
# File 'lib/fx/adapters/mysql.rb', line 91 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.
109 110 111 112 |
# File 'lib/fx/adapters/mysql.rb', line 109 def update_trigger(name, on:, sql_definition:) drop_trigger(name, on: on) create_trigger(sql_definition) end |