primary_key_names(table)
click to toggle source
Returns an ordered list of primary key column names of the given table
# File lib/rubyrep/connection_extenders/mysql_extender.rb, line 10 def primary_key_names(table) row = self.select_one( select table_name from information_schema.tables where table_schema = database() and table_name = '#{table}') if row.nil? raise "table '#{table}' does not exist" end rows = self.select_all( select column_name from information_schema.key_column_usage where table_schema = database() and table_name = '#{table}' and constraint_name = 'PRIMARY' order by ordinal_position) columns = rows.map {|_row| _row['column_name']} columns end