Class: Simmer::Externals::SqlWriters::SqlFixture
- Inherits:
-
Object
- Object
- Simmer::Externals::SqlWriters::SqlFixture
- Extended by:
- Forwardable
- Defined in:
- lib/simmer/externals/sql_writers/sql_fixture.rb
Overview
This class knows how to turn a fixture into sql.
Instance Method Summary collapse
-
#initialize(client, fixture) ⇒ SqlFixture
constructor
A new instance of SqlFixture.
- #to_sql ⇒ Object
Constructor Details
#initialize(client, fixture) ⇒ SqlFixture
Returns a new instance of SqlFixture.
21 22 23 24 25 26 27 28 |
# File 'lib/simmer/externals/sql_writers/sql_fixture.rb', line 21 def initialize(client, fixture) raise ArgumentError, 'fixture is required' unless fixture @client = client @fixture = fixture freeze end |
Instance Method Details
#to_sql ⇒ Object
30 31 32 33 34 35 |
# File 'lib/simmer/externals/sql_writers/sql_fixture.rb', line 30 def to_sql sql_columns = fields.keys.map { |k| "`#{k}`" }.join(',') sql_values = fields.values.map { |v| "'#{client.escape(v.to_s)}'" }.join(',') "INSERT INTO `#{table}` (#{sql_columns}) VALUES (#{sql_values})" end |