Sha256: 7d921956bdc306e8d35e1d79065784832b852cb5b345069473d09d249e299a2a

Contents?: true

Size: 455 Bytes

Versions: 8

Compression:

Stored size: 455 Bytes

Contents

require_relative 'environment'

class SQLRunner

  COMMANDS = ["create", "insert", "update", "delete"]

  def initialize(db)
    @db = db
  end

  def self.make_methods
    COMMANDS.each do |command|
      define_method("execute_sql_#{command}") do 
        sql = File.read("lib/#{command}.sql")
        execute_sql(sql)
      end
    end
  end

  def execute_sql(sql)
     sql.scan(/[^;]*;/m).each { |line| @db.execute(line) } unless sql.empty?
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
learn-generate-1.0.16 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.15 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.14 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.13 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.12 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.11 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.1 lib/templates/sql/bin/sql_runner.rb
learn-generate-1.0.0 lib/templates/sql/bin/sql_runner.rb