Module: Fx::Statements::Function
- Defined in:
- lib/fx/statements/function.rb
Overview
Methods that are made available in migrations for managing Fx functions.
Instance Method Summary collapse
-
#create_function(name, on: '', version: 1, sql_definition: nil) ⇒ Object
Create a new database function.
-
#drop_function(name, *_opts, revert_to_version: nil, **_options) ⇒ Object
Drop a database function by name.
-
#update_function(name, version: nil, sql_definition: nil, revert_to_version: nil) ⇒ Object
Update a database function.
Instance Method Details
#create_function(name, on: '', version: 1, sql_definition: nil) ⇒ Object
Create a new database function.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fx/statements/function.rb', line 34 def create_function(name, on: '', version: 1, sql_definition: nil) if version.nil? && sql_definition.nil? raise( ArgumentError, 'version or sql_definition must be specified' ) end sql_definition = sql_definition.strip_heredoc if sql_definition sql_definition ||= Fx::Definition.new(name: name, version: version).to_sql Fx.database.create_function(sql_definition) end |
#drop_function(name, *_opts, revert_to_version: nil, **_options) ⇒ Object
Drop a database function by name.
58 59 60 |
# File 'lib/fx/statements/function.rb', line 58 def drop_function(name, *_opts, revert_to_version: nil, **) Fx.database.drop_function(name) end |
#update_function(name, version: nil, sql_definition: nil, revert_to_version: nil) ⇒ Object
Update a database function.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fx/statements/function.rb', line 91 def update_function(name, version: nil, sql_definition: nil, revert_to_version: nil) if version.nil? && sql_definition.nil? raise( ArgumentError, 'version or sql_definition must be specified' ) end sql_definition = sql_definition.strip_heredoc if sql_definition sql_definition ||= Fx::Definition.new( name: name, version: version, ).to_sql Fx.database.update_function(name, sql_definition) end |