activerecord4-redshift-adapter 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_record/connection_adapters/redshift/array_parser.rb +35 -39
  3. data/lib/active_record/connection_adapters/redshift/column.rb +10 -0
  4. data/lib/active_record/connection_adapters/redshift/database_statements.rb +37 -47
  5. data/lib/active_record/connection_adapters/redshift/oid.rb +14 -359
  6. data/lib/active_record/connection_adapters/redshift/oid/date.rb +11 -0
  7. data/lib/active_record/connection_adapters/redshift/oid/date_time.rb +36 -0
  8. data/lib/active_record/connection_adapters/redshift/oid/decimal.rb +13 -0
  9. data/lib/active_record/connection_adapters/redshift/oid/float.rb +21 -0
  10. data/lib/active_record/connection_adapters/redshift/oid/infinity.rb +13 -0
  11. data/lib/active_record/connection_adapters/redshift/oid/integer.rb +11 -0
  12. data/lib/active_record/connection_adapters/redshift/oid/json.rb +35 -0
  13. data/lib/active_record/connection_adapters/redshift/oid/jsonb.rb +23 -0
  14. data/lib/active_record/connection_adapters/redshift/oid/time.rb +11 -0
  15. data/lib/active_record/connection_adapters/redshift/oid/type_map_initializer.rb +63 -0
  16. data/lib/active_record/connection_adapters/redshift/quoting.rb +45 -119
  17. data/lib/active_record/connection_adapters/redshift/referential_integrity.rb +4 -19
  18. data/lib/active_record/connection_adapters/redshift/schema_definitions.rb +73 -0
  19. data/lib/active_record/connection_adapters/redshift/schema_statements.rb +141 -76
  20. data/lib/active_record/connection_adapters/redshift/utils.rb +77 -0
  21. data/lib/active_record/connection_adapters/redshift_adapter.rb +252 -496
  22. metadata +17 -11
  23. data/lib/active_record/connection_adapters/redshift/cast.rb +0 -156
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord4-redshift-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -28,20 +28,14 @@ dependencies:
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 4.0.0
34
- - - "<"
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
33
  version: 4.2.0
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 4.0.0
44
- - - "<"
38
+ - - "~>"
45
39
  - !ruby/object:Gem::Version
46
40
  version: 4.2.0
47
41
  description: Amazon Redshift _makeshift_ adapter for ActiveRecord 4.
@@ -53,12 +47,24 @@ files:
53
47
  - LICENSE
54
48
  - README.md
55
49
  - lib/active_record/connection_adapters/redshift/array_parser.rb
56
- - lib/active_record/connection_adapters/redshift/cast.rb
50
+ - lib/active_record/connection_adapters/redshift/column.rb
57
51
  - lib/active_record/connection_adapters/redshift/database_statements.rb
58
52
  - lib/active_record/connection_adapters/redshift/oid.rb
53
+ - lib/active_record/connection_adapters/redshift/oid/date.rb
54
+ - lib/active_record/connection_adapters/redshift/oid/date_time.rb
55
+ - lib/active_record/connection_adapters/redshift/oid/decimal.rb
56
+ - lib/active_record/connection_adapters/redshift/oid/float.rb
57
+ - lib/active_record/connection_adapters/redshift/oid/infinity.rb
58
+ - lib/active_record/connection_adapters/redshift/oid/integer.rb
59
+ - lib/active_record/connection_adapters/redshift/oid/json.rb
60
+ - lib/active_record/connection_adapters/redshift/oid/jsonb.rb
61
+ - lib/active_record/connection_adapters/redshift/oid/time.rb
62
+ - lib/active_record/connection_adapters/redshift/oid/type_map_initializer.rb
59
63
  - lib/active_record/connection_adapters/redshift/quoting.rb
60
64
  - lib/active_record/connection_adapters/redshift/referential_integrity.rb
65
+ - lib/active_record/connection_adapters/redshift/schema_definitions.rb
61
66
  - lib/active_record/connection_adapters/redshift/schema_statements.rb
67
+ - lib/active_record/connection_adapters/redshift/utils.rb
62
68
  - lib/active_record/connection_adapters/redshift_adapter.rb
63
69
  homepage: http://github.com/aamine/activerecord4-redshift-adapter
64
70
  licenses:
@@ -1,156 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- class RedshiftColumn < Column
4
- module Cast
5
- def point_to_string(point)
6
- "(#{point[0]},#{point[1]})"
7
- end
8
-
9
- def string_to_point(string)
10
- if string[0] == '(' && string[-1] == ')'
11
- string = string[1...-1]
12
- end
13
- string.split(',').map{ |v| Float(v) }
14
- end
15
-
16
- def string_to_time(string)
17
- return string unless String === string
18
-
19
- case string
20
- when 'infinity'; 1.0 / 0.0
21
- when '-infinity'; -1.0 / 0.0
22
- when / BC$/
23
- super("-" + string.sub(/ BC$/, ""))
24
- else
25
- super
26
- end
27
- end
28
-
29
- def string_to_bit(value)
30
- case value
31
- when /^0x/i
32
- value[2..-1].hex.to_s(2) # Hexadecimal notation
33
- else
34
- value # Bit-string notation
35
- end
36
- end
37
-
38
- def hstore_to_string(object)
39
- if Hash === object
40
- object.map { |k,v|
41
- "#{escape_hstore(k)}=>#{escape_hstore(v)}"
42
- }.join ','
43
- else
44
- object
45
- end
46
- end
47
-
48
- def string_to_hstore(string)
49
- if string.nil?
50
- nil
51
- elsif String === string
52
- Hash[string.scan(HstorePair).map { |k,v|
53
- v = v.upcase == 'NULL' ? nil : v.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
54
- k = k.gsub(/\A"(.*)"\Z/m,'\1').gsub(/\\(.)/, '\1')
55
- [k,v]
56
- }]
57
- else
58
- string
59
- end
60
- end
61
-
62
- def json_to_string(object)
63
- if Hash === object
64
- ActiveSupport::JSON.encode(object)
65
- else
66
- object
67
- end
68
- end
69
-
70
- def array_to_string(value, column, adapter, should_be_quoted = false)
71
- casted_values = value.map do |val|
72
- if String === val
73
- if val == "NULL"
74
- "\"#{val}\""
75
- else
76
- quote_and_escape(adapter.type_cast(val, column, true))
77
- end
78
- else
79
- adapter.type_cast(val, column, true)
80
- end
81
- end
82
- "{#{casted_values.join(',')}}"
83
- end
84
-
85
- def range_to_string(object)
86
- from = object.begin.respond_to?(:infinite?) && object.begin.infinite? ? '' : object.begin
87
- to = object.end.respond_to?(:infinite?) && object.end.infinite? ? '' : object.end
88
- "[#{from},#{to}#{object.exclude_end? ? ')' : ']'}"
89
- end
90
-
91
- def string_to_json(string)
92
- if String === string
93
- ActiveSupport::JSON.decode(string)
94
- else
95
- string
96
- end
97
- end
98
-
99
- def string_to_cidr(string)
100
- if string.nil?
101
- nil
102
- elsif String === string
103
- IPAddr.new(string)
104
- else
105
- string
106
- end
107
- end
108
-
109
- def cidr_to_string(object)
110
- if IPAddr === object
111
- "#{object.to_s}/#{object.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
112
- else
113
- object
114
- end
115
- end
116
-
117
- def string_to_array(string, oid)
118
- parse_pg_array(string).map{|val| oid.type_cast val}
119
- end
120
-
121
- private
122
-
123
- HstorePair = begin
124
- quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
125
- unquoted_string = /(?:\\.|[^\s,])[^\s=,\\]*(?:\\.[^\s=,\\]*|=[^,>])*/
126
- /(#{quoted_string}|#{unquoted_string})\s*=>\s*(#{quoted_string}|#{unquoted_string})/
127
- end
128
-
129
- def escape_hstore(value)
130
- if value.nil?
131
- 'NULL'
132
- else
133
- if value == ""
134
- '""'
135
- else
136
- '"%s"' % value.to_s.gsub(/(["\\])/, '\\\\\1')
137
- end
138
- end
139
- end
140
-
141
- ARRAY_ESCAPE = "\\" * 2 * 2 # escape the backslash twice for PG arrays
142
-
143
- def quote_and_escape(value)
144
- case value
145
- when "NULL"
146
- value
147
- else
148
- value = value.gsub(/\\/, ARRAY_ESCAPE)
149
- value.gsub!(/"/,"\\\"")
150
- "\"#{value}\""
151
- end
152
- end
153
- end
154
- end
155
- end
156
- end