citus-rails-4.2 0.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 +7 -0
- data/Gemfile +3 -0
- data/Rakefile +2 -0
- data/citus-rails-4.2.gemspec +15 -0
- data/lib/citus-rails-4.2.rb +5 -0
- data/lib/citus-rails-4.2/acts_as_distributed.rb +19 -0
- data/lib/citus-rails-4.2/belongs_to_association.rb +9 -0
- data/lib/citus-rails-4.2/copy_from_client.rb +27 -0
- data/pkg/citus-rails-0.1.0.gem +0 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ebaf017b2ff32e7772360cc2dbfaa6f75532eb3a
|
4
|
+
data.tar.gz: ba556315152420c85c50d7874bdd79821c56635e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70fe36468b73b832b22ba708e49bb818ee741b52d0005e9729fa826c75c7cb46bf4ff1c834beb1d95121b9c2d0f2aba7d9873e0752a251b64ad7f3c409d542e6
|
7
|
+
data.tar.gz: 95988812276e5c0dca1fcbebab1053dcb645bc9142e9d8d574f32d0e6edcad28dab1a5e93014de73b61ad8927fd790aaa22180dd9cd53cd466c48f799aedeb6d
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'citus-rails-4.2'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = Date.today
|
5
|
+
s.summary = "Citus Rails Integration (Rails 4.2)"
|
6
|
+
s.description = ""
|
7
|
+
s.authors = ["Citus Data"]
|
8
|
+
s.email = 'engage@citusdata.com'
|
9
|
+
s.files = `git ls-files -z`.split("\x0")
|
10
|
+
s.homepage = 'https://github.com/citusdata/citus-rails'
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.add_runtime_dependency 'activerecord', '~> 4.2'
|
14
|
+
s.add_runtime_dependency 'composite_primary_keys', '~> 8.0'
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
def self.acts_as_distributed(partition_column:)
|
3
|
+
check_citus_compatibility
|
4
|
+
@partition_column = partition_column
|
5
|
+
end
|
6
|
+
|
7
|
+
def partition_column
|
8
|
+
@partition_column
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.check_citus_compatibility
|
14
|
+
if primary_keys && primary_keys.include?('id')
|
15
|
+
suggested_name = name.underscore + '_id'
|
16
|
+
fail format("citus-rails currently does not support models with 'id' as one of multiple primary keys - please name your id column '%s'", suggested_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class ActiveRecord::Associations::BelongsToAssociation
|
2
|
+
alias_method :remove_keys_without_cpk, :remove_keys
|
3
|
+
def remove_keys
|
4
|
+
return remove_keys_without_cpk unless reflection.foreign_key.is_a?(Array)
|
5
|
+
|
6
|
+
fk = reflection.foreign_key - [owner.class.partition_column]
|
7
|
+
owner[fk] = nil
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
class CopyFromClientHelper
|
3
|
+
attr_reader :count
|
4
|
+
|
5
|
+
def initialize(conn, column_types)
|
6
|
+
@count = 0
|
7
|
+
@conn = conn
|
8
|
+
@column_types = column_types
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(row)
|
12
|
+
row = row.map.with_index { |val, idx| @column_types[idx].type_cast_for_database(val) }
|
13
|
+
@conn.put_copy_data(row)
|
14
|
+
@count += 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.copy_from_client(columns, &block)
|
19
|
+
conn = connection.raw_connection
|
20
|
+
column_types = columns.map { |c| columns_hash[c.to_s] }
|
21
|
+
helper = CopyFromClientHelper.new(conn, column_types)
|
22
|
+
conn.copy_data %{COPY #{quoted_table_name}("#{columns.join('","')}") FROM STDIN}, PG::TextEncoder::CopyRow.new do
|
23
|
+
block.call helper
|
24
|
+
end
|
25
|
+
helper.count
|
26
|
+
end
|
27
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: citus-rails-4.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Citus Data
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: composite_primary_keys
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '8.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '8.0'
|
41
|
+
description: ''
|
42
|
+
email: engage@citusdata.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Rakefile
|
49
|
+
- citus-rails-4.2.gemspec
|
50
|
+
- lib/citus-rails-4.2.rb
|
51
|
+
- lib/citus-rails-4.2/acts_as_distributed.rb
|
52
|
+
- lib/citus-rails-4.2/belongs_to_association.rb
|
53
|
+
- lib/citus-rails-4.2/copy_from_client.rb
|
54
|
+
- pkg/citus-rails-0.1.0.gem
|
55
|
+
homepage: https://github.com/citusdata/citus-rails
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.5.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Citus Rails Integration (Rails 4.2)
|
79
|
+
test_files: []
|