Class: Itiel::Script::SQLScript
- Inherits:
-
Object
- Object
- Itiel::Script::SQLScript
- Includes:
- DB::SQLConnectable, ChainedStep
- Defined in:
- lib/itiel/script/sql_script.rb
Overview
Executes a SQL script or command on the specified connection
Instance Attribute Summary collapse
-
#sql ⇒ Object
Returns the value of attribute sql.
Attributes included from DB::SQLConnectable
#connection, #connection_file_path
Attributes included from ChainedStep
Instance Method Summary collapse
- #execute(input_stream = nil) ⇒ Object
-
#initialize(sql = nil, &block) ⇒ SQLScript
constructor
A new instance of SQLScript.
Methods included from DB::SQLConnectable
Methods included from ChainedStep
Constructor Details
#initialize(sql = nil, &block) ⇒ SQLScript
Returns a new instance of SQLScript.
13 14 15 16 17 18 19 |
# File 'lib/itiel/script/sql_script.rb', line 13 def initialize(sql=nil, &block) if block_given? self.sql = block else self.sql = sql end end |
Instance Attribute Details
#sql ⇒ Object
Returns the value of attribute sql.
11 12 13 |
# File 'lib/itiel/script/sql_script.rb', line 11 def sql @sql end |
Instance Method Details
#execute(input_stream = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/itiel/script/sql_script.rb', line 21 def execute(input_stream=nil) db = self.class.sequel_connection(connection) if sql.respond_to?(:call) input_stream.each do |row| db << sql.call(row) end else db << sql end end |