Class: InsertSelect::Adapters::BaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/insert_select/adapters/base_adapter.rb

Direct Known Subclasses

MysqlAdapter, PostgresqlAdapter, SqliteAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, connection) ⇒ BaseAdapter

Returns a new instance of BaseAdapter.



7
8
9
10
# File 'lib/insert_select/adapters/base_adapter.rb', line 7

def initialize(table_name, connection)
  @table_name = table_name
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/insert_select/adapters/base_adapter.rb', line 6

def connection
  @connection
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/insert_select/adapters/base_adapter.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#build_sql(builder) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/insert_select/adapters/base_adapter.rb', line 12

def build_sql(builder)
  into = builder.into

  if into.present?
    builder.reselect_relation!

    stmt = "INSERT #{into}"
    stmt += " #{builder.relation_sql}"
  else
    quoted_table_name = @connection.quote_table_name(table_name)
    stmt = "INSERT INTO #{quoted_table_name} #{builder.relation_sql}"
  end

  stmt
end