class Baza::Table

Attributes

db[R]

Public Instance Methods

<=>(other) click to toggle source
# File lib/baza/table.rb, line 55
def <=>(other)
  return false unless other.is_a?(Baza::Table)
  return false unless other.db.opts.fetch(:db) == db.opts.fetch(:db)
  other.name <=> name
end
create_columns(col_arr) click to toggle source
# File lib/baza/table.rb, line 61
def create_columns(col_arr)
  col_arr.each do |col_data|
    sql = "ALTER TABLE #{db.quote_column(name)} ADD COLUMN #{@db.columns.data_sql(col_data)};"
    @db.query(sql)
  end
end
insert(data, args = {}) click to toggle source
# File lib/baza/table.rb, line 37
def insert(data, args = {})
  @db.insert(name, data, args)
end
inspect() click to toggle source
# File lib/baza/table.rb, line 11
def inspect
  to_s
end
row(id) click to toggle source
# File lib/baza/table.rb, line 27
def row(id)
  row = rows({id: id}, limit: 1).first
  raise Baza::Errors::RowNotFound unless row
  row
end
rows(*args) click to toggle source
# File lib/baza/table.rb, line 15
def rows(*args)
  ArrayEnumerator.new do |yielder|
    db.select(name, *args) do |data|
      yielder << Baza::Row.new(
        db: db,
        table: name,
        data: data
      )
    end
  end
end
rows_count() click to toggle source
# File lib/baza/table.rb, line 45
def rows_count
  sql = "SELECT COUNT(*) AS count FROM #{db.quote_table(name)}"
  @db.query(sql).fetch.fetch(:count).to_i
end
to_param() click to toggle source
# File lib/baza/table.rb, line 33
def to_param
  name
end
to_s() click to toggle source
# File lib/baza/table.rb, line 7
def to_s
  "#<#{self.class.name} name=\"#{name}\">"
end
truncate() click to toggle source
# File lib/baza/table.rb, line 50
def truncate
  @db.query("TRUNCATE #{@db.quote_table(name)}")
  self
end
upsert_duplicate_key(data, terms = {}, args = {}) click to toggle source
# File lib/baza/table.rb, line 41
def upsert_duplicate_key(data, terms = {}, args = {})
  @db.upsert_duplicate_key(name, data, terms, args)
end