Skip to content
This repository was archived by the owner on Apr 26, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/enum_table/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def enum_map(name, options)
map = {}
table_name = table || "#{self.table_name.singularize}_#{name.to_s.pluralize}"
return {} if EnumTable.missing_tables_allowed? && !connection.tables.include?(table_name)
connection.execute("SELECT id, value FROM #{connection.quote_table_name table_name}").each do |row|
connection.select_rows("SELECT id, value FROM #{connection.quote_table_name table_name}").each do |row|
map[row[1]] = row[0]
end
map
Expand Down
2 changes: 1 addition & 1 deletion lib/enum_table/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def tables_with_enum_table(stream)
table_names.each do |table_name|
stream.puts " create_enum_table #{table_name.inspect}, force: true do |t|"
enum_table_column(stream, table_name, 'value', SchemaStatements::DEFAULT_VALUE_ATTRIBUTES)
@connection.execute("SELECT id, value FROM #{@connection.quote_table_name table_name} ORDER BY id").each do |row|
@connection.select_rows("SELECT id, value FROM #{@connection.quote_table_name table_name} ORDER BY id").each do |row|
stream.puts " t.add #{row[1].to_s.inspect}, #{row[0]}"
end
stream.puts " end"
Expand Down
5 changes: 2 additions & 3 deletions lib/enum_table/schema_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def drop_enum_table(table_name)

def enum_tables
return [] if !table_exists?('enum_tables')
@enum_tables ||= execute("SELECT table_name FROM enum_tables").
map { |row| row[0] }.sort
@enum_tables ||= select_values("SELECT table_name FROM enum_tables").sort
end

def enum_tables_updated
Expand Down Expand Up @@ -67,7 +66,7 @@ class Table
def initialize(connection, name, max_id=nil)
@connection = connection
@name = name
@max_id = @connection.execute("SELECT max(id) FROM #{@connection.quote_table_name @name}").to_a[0][0] || 0
@max_id = @connection.select_rows("SELECT max(id) FROM #{@connection.quote_table_name @name}").to_a[0][0] || 0
end

def add(value, id=nil)
Expand Down