Module: Schema

Included in:
BlocRecord::Base
Defined in:
lib/bloc_record/schema.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



13
14
15
# File 'lib/bloc_record/schema.rb', line 13

def attributes
  columns - ["id"]
end

#columnsObject



9
10
11
# File 'lib/bloc_record/schema.rb', line 9

def columns
  schema.keys
end

#countObject



27
28
29
30
31
# File 'lib/bloc_record/schema.rb', line 27

def count
  connection.execute(<<-SQL)[0][0]
    SELECT COUNT(*) FROM #{table}
  SQL
end

#schemaObject



17
18
19
20
21
22
23
24
25
# File 'lib/bloc_record/schema.rb', line 17

def schema
  unless @schema
    @schema = {}
    connection.table_info(table) do |col|
      @schema[col["name"]] = col["type"]
    end
  end
  @schema
end

#tableObject



5
6
7
# File 'lib/bloc_record/schema.rb', line 5

def table
  BlocRecord::Utility.underscore(name)
end