Class: Fx::Adapters::MySQL

Inherits:
Object
  • Object
show all
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.

Examples:

Fx.configure do |config|
  config.database = Fx::Adapters::MySQL.new
end

Defined Under Namespace

Classes: Functions, Triggers

Instance Method Summary collapse

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.

Examples:

Fx.configure do |config|
  config.database = Fx::Adapters::MySQL.new
end

Parameters:

  • connectable (#connection) (defaults to: ActiveRecord::Base)

    An object that returns the connection for F(x) to use. Defaults to ‘ActiveRecord::Base`.



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.

Parameters:

  • sql_definition

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

Parameters:

  • sql_definition

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

Parameters:

  • name

    The name of the function to drop



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.

Parameters:

  • name

    The name of the trigger to drop

  • on (defaults to: nil)

    Unused in the MySQL adapter. Defaults to ‘nil` to support method signature.



135
136
137
# File 'lib/fx/adapters/mysql.rb', line 135

def drop_trigger(name, on: nil)
  execute "DROP TRIGGER #{name};"
end

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

Returns:

  • (Array<Fx::Function>)


44
45
46
# File 'lib/fx/adapters/mysql.rb', line 44

def functions
  Functions.all(connection)
end

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

Returns:

  • (Array<Fx::Trigger>)


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.

Parameters:

  • name

    The name of the function.

  • sql_definition

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

Parameters:

  • name

    The name of the trigger.

  • on

    The associated table for the trigger to drop

  • sql_definition

    The SQL schema for the function.



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