Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sequel::Database::<Adapter> doesn't always have the primary_key metho…

…d, hack around it when it's not available.
  • Loading branch information...
commit 1807ebc8ab72817bcf98edbe95d825af1b39d664 1 parent 76ba024
@ricardochimal ricardochimal authored
View
3  lib/taps/client_session.rb
@@ -118,8 +118,7 @@ def cmd_send_data
db.tables.each do |table_name|
table = db[table_name]
count = table.count
- primary_key = db.primary_key(table_name.to_sym)
- order = primary_key ? [primary_key.to_sym] : table.columns
+ order = Taps::Utils.order_by(db, table_name)
chunksize = self.default_chunksize
progress = ProgressBar.new(table_name.to_s, count)
View
3  lib/taps/server.rb
@@ -117,8 +117,7 @@ class Server < Sinatra::Default
db = session.connection
table = db[params[:table].to_sym]
- primary_key = db.primary_key(params[:table].to_sym)
- order = primary_key ? [primary_key.to_sym] : table.columns
+ order = Taps::Utils.order_by(db, params[:table].to_sym)
raw_data = Marshal.dump(Taps::Utils.format_data(table.order(*order).limit(chunk, offset).all))
gzip_data = Taps::Utils.gzip(raw_data)
response['Taps-Checksum'] = Taps::Utils.checksum(gzip_data).to_s
View
17 lib/taps/utils.rb
@@ -85,5 +85,22 @@ def load_indexes(database_url, index_data)
`#{File.dirname(__FILE__)}/../../bin/schema load_indexes #{database_url} #{tmp.path}`
end
end
+
+ def primary_key(db, table)
+ if db.respond_to?(:primary_key)
+ db.primary_key(table)
+ else
+ db.schema[table].select { |c| c[1][:primary_key] }.map { |c| c.first }.shift
+ end
+ end
+
+ def order_by(db, table)
+ pkey = primary_key(db, table)
+ if pkey
+ [pkey.to_sym]
+ else
+ db[table].columns
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.