picky 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,8 @@ module Sources
28
28
  #
29
29
  attr_reader :connection_options
30
30
 
31
+ @@traversal_id = :__picky_id
32
+
31
33
  def initialize select_statement, options = { file: 'app/db.yml' }
32
34
  @select_statement = select_statement
33
35
  @database = create_database_adapter
@@ -86,11 +88,9 @@ module Sources
86
88
  # TODO Use rename_column ASAP.
87
89
  #
88
90
  if on_database.adapter_name == "PostgreSQL"
89
- on_database.execute "ALTER TABLE #{origin} RENAME COLUMN id TO indexed_id"
90
- on_database.execute "ALTER TABLE #{origin} ADD COLUMN id SERIAL PRIMARY KEY"
91
+ on_database.execute "ALTER TABLE #{origin} ADD COLUMN #{@@traversal_id} SERIAL PRIMARY KEY"
91
92
  else
92
- on_database.execute "ALTER TABLE #{origin} CHANGE COLUMN id indexed_id INTEGER"
93
- on_database.execute "ALTER TABLE #{origin} ADD COLUMN id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT"
93
+ on_database.execute "ALTER TABLE #{origin} ADD COLUMN #{@@traversal_id} INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT"
94
94
  end
95
95
 
96
96
  # Execute any special queries this type needs executed.
@@ -103,7 +103,7 @@ module Sources
103
103
  def count type # :nodoc:
104
104
  connect_backend
105
105
 
106
- database.connection.select_value("SELECT COUNT(id) FROM #{snapshot_table_name(type)}").to_i
106
+ database.connection.select_value("SELECT COUNT(#{@@traversal_id}) FROM #{snapshot_table_name(type)}").to_i
107
107
  end
108
108
 
109
109
  #
@@ -130,19 +130,19 @@ module Sources
130
130
  # TODO Rewrite ASAP.
131
131
  #
132
132
  if database.connection.adapter_name == "PostgreSQL"
133
- id_key = 'indexed_id'
133
+ id_key = 'id'
134
134
  text_key = category.from.to_s
135
135
  database.connection.execute(select_statement).each do |hash|
136
- indexed_id, text = hash.values_at id_key, text_key
136
+ id, text = hash.values_at id_key, text_key
137
137
  next unless text
138
138
  text.force_encoding 'utf-8' # TODO Still needed? Or move to backend?
139
- yield indexed_id, text
139
+ yield id, text
140
140
  end
141
141
  else
142
- database.connection.execute(select_statement).each do |indexed_id, text|
142
+ database.connection.execute(select_statement).each do |id, text|
143
143
  next unless text
144
144
  text.force_encoding 'utf-8' # TODO Still needed? Or move to backend?
145
- yield indexed_id, text
145
+ yield id, text
146
146
  end
147
147
  end
148
148
  end
@@ -156,13 +156,13 @@ module Sources
156
156
 
157
157
  statement += statement.include?('WHERE') ? ' AND' : ' WHERE'
158
158
 
159
- "#{statement} st.id > #{offset} LIMIT #{chunksize}"
159
+ "#{statement} st.#{@@traversal_id} > #{offset} LIMIT #{chunksize}"
160
160
  end
161
161
 
162
162
  # The harvest statement used to pull data from the snapshot table.
163
163
  #
164
164
  def harvest_statement type, category # :nodoc:
165
- "SELECT indexed_id, #{category.from} FROM #{snapshot_table_name(type)} st"
165
+ "SELECT id, #{category.from} FROM #{snapshot_table_name(type)} st"
166
166
  end
167
167
 
168
168
  # The amount of records that are loaded each chunk.
@@ -30,7 +30,7 @@ describe Sources::DB do
30
30
 
31
31
  @connection.should_receive(:execute).
32
32
  once.
33
- with('SELECT indexed_id, some_category FROM some_type_type_index st WHERE st.id > some_offset LIMIT 25000').
33
+ with('SELECT id, some_category FROM some_type_type_index st WHERE st.__picky_id > some_offset LIMIT 25000').
34
34
  and_return []
35
35
 
36
36
  @source.get_data @type, @category, :some_offset
@@ -40,7 +40,7 @@ describe Sources::DB do
40
40
  it 'yields to the caller' do
41
41
  @connection.should_receive(:execute).
42
42
  any_number_of_times.
43
- with('SELECT indexed_id, some_category FROM some_type_type_index st WHERE st.id > some_offset LIMIT 25000').
43
+ with('SELECT id, some_category FROM some_type_type_index st WHERE st.__picky_id > some_offset LIMIT 25000').
44
44
  and_return [[1, 'text']]
45
45
 
46
46
  @source.get_data @type, @category, :some_offset do |id, text|
@@ -86,7 +86,7 @@ describe Sources::DB do
86
86
  end
87
87
  it "should get the id count" do
88
88
  result = stub(:result, :to_i => 12_345)
89
- @connection.should_receive(:select_value).once.with("SELECT COUNT(id) FROM some_type_name_type_index")
89
+ @connection.should_receive(:select_value).once.with("SELECT COUNT(__picky_id) FROM some_type_name_type_index")
90
90
 
91
91
  @source.count @type
92
92
  end
@@ -120,11 +120,11 @@ describe Sources::DB do
120
120
  end
121
121
  it "should add an AND if it already contains a WHERE statement" do
122
122
  @source.should_receive(:harvest_statement).and_return 'WHERE'
123
- @source.harvest_statement_with_offset(@type, @category, :some_offset).should == "WHERE AND st.id > some_offset LIMIT 25000"
123
+ @source.harvest_statement_with_offset(@type, @category, :some_offset).should == "WHERE AND st.__picky_id > some_offset LIMIT 25000"
124
124
  end
125
125
  it "should add a WHERE if it doesn't already contain one" do
126
126
  @source.should_receive(:harvest_statement).and_return 'some_statement'
127
- @source.harvest_statement_with_offset(@type, @category, :some_offset).should == "some_statement WHERE st.id > some_offset LIMIT 25000"
127
+ @source.harvest_statement_with_offset(@type, @category, :some_offset).should == "some_statement WHERE st.__picky_id > some_offset LIMIT 25000"
128
128
  end
129
129
  end
130
130
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.5.0
5
+ version: 1.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-03 00:00:00 +01:00
13
+ date: 2011-03-04 00:00:00 +01:00
14
14
  default_executable: picky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency