taps 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 12
2
+ :patch: 13
3
3
  :major: 0
4
4
  :minor: 2
@@ -118,8 +118,7 @@ class ClientSession
118
118
  db.tables.each do |table_name|
119
119
  table = db[table_name]
120
120
  count = table.count
121
- primary_key = db.primary_key(table_name.to_sym)
122
- order = primary_key ? [primary_key.to_sym] : table.columns
121
+ order = Taps::Utils.order_by(db, table_name)
123
122
  chunksize = self.default_chunksize
124
123
 
125
124
  progress = ProgressBar.new(table_name.to_s, count)
@@ -117,8 +117,7 @@ class Server < Sinatra::Default
117
117
 
118
118
  db = session.connection
119
119
  table = db[params[:table].to_sym]
120
- primary_key = db.primary_key(params[:table].to_sym)
121
- order = primary_key ? [primary_key.to_sym] : table.columns
120
+ order = Taps::Utils.order_by(db, params[:table].to_sym)
122
121
  raw_data = Marshal.dump(Taps::Utils.format_data(table.order(*order).limit(chunk, offset).all))
123
122
  gzip_data = Taps::Utils.gzip(raw_data)
124
123
  response['Taps-Checksum'] = Taps::Utils.checksum(gzip_data).to_s
@@ -85,5 +85,22 @@ module Utils
85
85
  `#{File.dirname(__FILE__)}/../../bin/schema load_indexes #{database_url} #{tmp.path}`
86
86
  end
87
87
  end
88
+
89
+ def primary_key(db, table)
90
+ if db.respond_to?(:primary_key)
91
+ db.primary_key(table)
92
+ else
93
+ db.schema[table].select { |c| c[1][:primary_key] }.map { |c| c.first }.shift
94
+ end
95
+ end
96
+
97
+ def order_by(db, table)
98
+ pkey = primary_key(db, table)
99
+ if pkey
100
+ [pkey.to_sym]
101
+ else
102
+ db[table].columns
103
+ end
104
+ end
88
105
  end
89
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Chimal, Jr.
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-03-31 00:00:00 -07:00
13
+ date: 2009-04-02 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -90,8 +90,6 @@ files:
90
90
  - spec/utils_spec.rb
91
91
  - lib/taps/progress_bar.rb
92
92
  - lib/taps/client_session.rb
93
- - lib/taps/server.rb
94
- - lib/taps/utils.rb
95
93
  - lib/taps/adapter_hacks.rb
96
94
  - lib/taps/adapter_hacks/invalid_text_limit.rb
97
95
  - lib/taps/adapter_hacks/non_rails_schema_dump.rb
@@ -99,6 +97,8 @@ files:
99
97
  - lib/taps/config.rb
100
98
  - lib/taps/cli.rb
101
99
  - lib/taps/db_session.rb
100
+ - lib/taps/server.rb
101
+ - lib/taps/utils.rb
102
102
  - README.rdoc
103
103
  - LICENSE
104
104
  - VERSION.yml