module Arql::Extension

Public Instance Methods

dump(filename, batch_size=500) click to toggle source
# File lib/arql/definition.rb, line 38
def dump(filename, batch_size=500)
  [self].dump(filename, batch_size)
end
t() click to toggle source
# File lib/arql/definition.rb, line 6
def t
  puts Terminal::Table.new { |t|
    v.each { |row| t << (row || :separator) }
  }
end
to_create_sql() click to toggle source
# File lib/arql/definition.rb, line 70
def to_create_sql
  ActiveRecord::Base.connection.exec_query("show create table #{table_name}").rows.last.last
end
to_insert_sql() click to toggle source
# File lib/arql/definition.rb, line 22
def to_insert_sql
  self.class.to_insert_sql([self])
end
to_sql(records, on_duplicate, batch_size) click to toggle source
# File lib/arql/definition.rb, line 64
def to_sql(records, on_duplicate, batch_size)
  records.in_groups_of(batch_size, false).map do |group|
    ActiveRecord::InsertAll.new(self, group.map(&:attributes), on_duplicate: on_duplicate).send(:to_sql) + ';'
  end.join("\n")
end
to_upsert_sql() click to toggle source
# File lib/arql/definition.rb, line 26
def to_upsert_sql
  self.class.to_upsert_sql([self])
end
v() click to toggle source
# File lib/arql/definition.rb, line 12
def v
  t = []
  t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
  t << nil
  self.class.connection.columns(self.class.table_name).each do |column|
    t << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
  end
  t
end
write_csv(filename, *fields, **options) click to toggle source
# File lib/arql/definition.rb, line 30
def write_csv(filename, *fields, **options)
  [self].write_csv(filename, *fields, **options)
end
write_excel(filename, *fields, **options) click to toggle source
# File lib/arql/definition.rb, line 34
def write_excel(filename, *fields, **options)
  [self].write_excel(filename, *fields, **options)
end