Class: Rooq::DSL::InsertQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/rooq/dsl/insert_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ InsertQuery

Returns a new instance of InsertQuery.



8
9
10
11
12
13
# File 'lib/rooq/dsl/insert_query.rb', line 8

def initialize(table)
  @table = table
  @column_list = []
  @insert_values = []
  @returning_fields = []
end

Instance Attribute Details

#column_listObject (readonly)

Returns the value of attribute column_list.



6
7
8
# File 'lib/rooq/dsl/insert_query.rb', line 6

def column_list
  @column_list
end

#insert_valuesObject (readonly)

Returns the value of attribute insert_values.



6
7
8
# File 'lib/rooq/dsl/insert_query.rb', line 6

def insert_values
  @insert_values
end

#returning_fieldsObject (readonly)

Returns the value of attribute returning_fields.



6
7
8
# File 'lib/rooq/dsl/insert_query.rb', line 6

def returning_fields
  @returning_fields
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/rooq/dsl/insert_query.rb', line 6

def table
  @table
end

Instance Method Details

#columns(*cols) ⇒ Object



15
16
17
# File 'lib/rooq/dsl/insert_query.rb', line 15

def columns(*cols)
  dup_with(column_list: cols.flatten)
end

#returning(*fields) ⇒ Object



23
24
25
# File 'lib/rooq/dsl/insert_query.rb', line 23

def returning(*fields)
  dup_with(returning_fields: fields.flatten)
end

#to_sql(dialect = Rooq::Dialect::PostgreSQL.new) ⇒ Object



27
28
29
# File 'lib/rooq/dsl/insert_query.rb', line 27

def to_sql(dialect = Rooq::Dialect::PostgreSQL.new)
  dialect.render_insert(self)
end

#values(*vals) ⇒ Object



19
20
21
# File 'lib/rooq/dsl/insert_query.rb', line 19

def values(*vals)
  dup_with(insert_values: @insert_values + [vals.flatten])
end