postgres_upsert 2.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +57 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +20 -0
  7. data/Gemfile +1 -2
  8. data/Gemfile.lock +175 -85
  9. data/README.md +117 -41
  10. data/Rakefile +4 -16
  11. data/app/assets/config/manifest.js +0 -0
  12. data/bin/bundle +3 -0
  13. data/bin/rails +4 -0
  14. data/bin/rake +4 -0
  15. data/bin/setup +56 -0
  16. data/config.ru +4 -0
  17. data/config/application.rb +21 -0
  18. data/config/boot.rb +3 -0
  19. data/config/database.yml +24 -0
  20. data/config/database.yml.travis +23 -0
  21. data/config/environment.rb +5 -0
  22. data/config/environments/development.rb +41 -0
  23. data/config/environments/production.rb +79 -0
  24. data/config/environments/test.rb +42 -0
  25. data/config/locales/en.yml +23 -0
  26. data/config/routes.rb +56 -0
  27. data/config/secrets.yml +22 -0
  28. data/db/migrate/20150214192135_create_test_tables.rb +24 -0
  29. data/db/migrate/20150710162236_create_composite_models_table.rb +9 -0
  30. data/db/schema.rb +48 -0
  31. data/db/seeds.rb +7 -0
  32. data/lib/postgres_upsert.rb +38 -6
  33. data/lib/postgres_upsert/model_to_model_adapter.rb +37 -0
  34. data/lib/postgres_upsert/read_adapters/active_record_adapter.rb +37 -0
  35. data/lib/postgres_upsert/read_adapters/file_adapter.rb +42 -0
  36. data/lib/postgres_upsert/read_adapters/io_adapter.rb +42 -0
  37. data/lib/postgres_upsert/result.rb +23 -0
  38. data/lib/postgres_upsert/table_writer.rb +48 -0
  39. data/lib/postgres_upsert/write_adapters/active_record_adapter.rb +36 -0
  40. data/lib/postgres_upsert/write_adapters/table_adapter.rb +56 -0
  41. data/lib/postgres_upsert/writer.rb +130 -92
  42. data/postgres_upsert.gemspec +7 -4
  43. data/spec/composite_key_spec.rb +50 -0
  44. data/spec/fixtures/comma_with_header_duplicate.csv +3 -0
  45. data/spec/fixtures/composite_key_model.rb +4 -0
  46. data/spec/fixtures/composite_key_with_header.csv +3 -0
  47. data/spec/fixtures/composite_nonkey_with_header.csv +3 -0
  48. data/spec/fixtures/test_model_copy.rb +4 -0
  49. data/spec/from_table_spec.rb +40 -0
  50. data/spec/pg_upsert_csv_spec.rb +93 -35
  51. data/spec/rails_helper.rb +1 -0
  52. data/spec/spec_helper.rb +9 -37
  53. metadata +106 -37
  54. data/VERSION +0 -1
  55. data/lib/postgres_upsert/active_record.rb +0 -13
  56. data/spec/fixtures/2_col_binary_data.dat +0 -0
  57. data/spec/pg_upsert_binary_spec.rb +0 -35
  58. 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