postgres_upsert 2.0.0 → 5.1.0
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.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rubocop.yml +57 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +20 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +175 -85
- data/README.md +117 -41
- data/Rakefile +4 -16
- data/app/assets/config/manifest.js +0 -0
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +56 -0
- data/config.ru +4 -0
- data/config/application.rb +21 -0
- data/config/boot.rb +3 -0
- data/config/database.yml +24 -0
- data/config/database.yml.travis +23 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +41 -0
- data/config/environments/production.rb +79 -0
- data/config/environments/test.rb +42 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +56 -0
- data/config/secrets.yml +22 -0
- data/db/migrate/20150214192135_create_test_tables.rb +24 -0
- data/db/migrate/20150710162236_create_composite_models_table.rb +9 -0
- data/db/schema.rb +48 -0
- data/db/seeds.rb +7 -0
- data/lib/postgres_upsert.rb +38 -6
- data/lib/postgres_upsert/model_to_model_adapter.rb +37 -0
- data/lib/postgres_upsert/read_adapters/active_record_adapter.rb +37 -0
- data/lib/postgres_upsert/read_adapters/file_adapter.rb +42 -0
- data/lib/postgres_upsert/read_adapters/io_adapter.rb +42 -0
- data/lib/postgres_upsert/result.rb +23 -0
- data/lib/postgres_upsert/table_writer.rb +48 -0
- data/lib/postgres_upsert/write_adapters/active_record_adapter.rb +36 -0
- data/lib/postgres_upsert/write_adapters/table_adapter.rb +56 -0
- data/lib/postgres_upsert/writer.rb +130 -92
- data/postgres_upsert.gemspec +7 -4
- data/spec/composite_key_spec.rb +50 -0
- data/spec/fixtures/comma_with_header_duplicate.csv +3 -0
- data/spec/fixtures/composite_key_model.rb +4 -0
- data/spec/fixtures/composite_key_with_header.csv +3 -0
- data/spec/fixtures/composite_nonkey_with_header.csv +3 -0
- data/spec/fixtures/test_model_copy.rb +4 -0
- data/spec/from_table_spec.rb +40 -0
- data/spec/pg_upsert_csv_spec.rb +93 -35
- data/spec/rails_helper.rb +1 -0
- data/spec/spec_helper.rb +9 -37
- metadata +106 -37
- data/VERSION +0 -1
- data/lib/postgres_upsert/active_record.rb +0 -13
- data/spec/fixtures/2_col_binary_data.dat +0 -0
- data/spec/pg_upsert_binary_spec.rb +0 -35
- data/spec/spec.opts +0 -1
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
# Copy data to a file passed as a string (the file path) or to lines that are passed to a block
|
4
|
-
|
5
|
-
# Copy data from a CSV that can be passed as a string (the file path) or as an IO object.
|
6
|
-
# * You can change the default delimiter passing delimiter: '' in the options hash
|
7
|
-
# * You can map fields from the file to different fields in the table using a map in the options hash
|
8
|
-
# * For further details on usage take a look at the README.md
|
9
|
-
def self.pg_upsert path_or_io, options = {}
|
10
|
-
PostgresUpsert::Writer.new(self, path_or_io, options).write
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
Binary file
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "pg_upsert from file with binary data" do
|
4
|
-
before(:each) do
|
5
|
-
ActiveRecord::Base.connection.execute %{
|
6
|
-
TRUNCATE TABLE test_models;
|
7
|
-
SELECT setval('test_models_id_seq', 1, false);
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
before do
|
12
|
-
DateTime.stub(:now).and_return (DateTime.parse("2012-01-01").utc)
|
13
|
-
end
|
14
|
-
|
15
|
-
def timestamp
|
16
|
-
DateTime.now.utc.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
it "imports from file if path is passed without field_map" do
|
20
|
-
TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary, columns: [:id, :data]
|
21
|
-
|
22
|
-
expect(
|
23
|
-
TestModel.first.attributes
|
24
|
-
).to include('data' => 'text', 'created_at' => timestamp, 'updated_at' => timestamp)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "throws an error when importing binary file without columns list" do
|
28
|
-
# Since binary data never has a header row, we'll require explicit columns list
|
29
|
-
expect{
|
30
|
-
TestModel.pg_upsert File.expand_path('spec/fixtures/2_col_binary_data.dat'), :format => :binary
|
31
|
-
}.to raise_error "Either the :columns option or :header => true are required"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|