activerecord-postgis-adapter 3.1.5 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fee81a4f105118b668eb878de411fd97b66d55d4
4
- data.tar.gz: 35b004a98e571fdfa144e09e0027112c72a19727
3
+ metadata.gz: 380360884a0395acaf0c5aef06a7629723fb626c
4
+ data.tar.gz: 946d727f1d802b68fdaa9cc699ddab13cca21366
5
5
  SHA512:
6
- metadata.gz: 731d5e563468a576fada2108b39ea1339d7b320eec1765075d39c2f4dd18f6108faa2103d4a4b831bb1c286fd2789a20b8be5feb605ed97ca9ea16d4f877c7d6
7
- data.tar.gz: 05441edb1a4b20d95afc7f6a67d0161e5ea5effd10251861dfb9db6efaee1b7cabe4754f5ae24391e803c964f7244dfe74f94189d995c6d5f40ffd0cd4810451
6
+ metadata.gz: 1b6e68a52ef70938e8b8299938049262c6acd45d1fe3df802f38f69d225034ee24a3ef66a19d8d4b2082dbea77fe0f804d8ac2b2d4b021b088b7ec2832b2e55e
7
+ data.tar.gz: 1fe70438744374e09787d1c9409976b85887eae506381384e3cc72b6b34de01314194106ead29b942f163c0a61b74e479011803ac4d138566f419812e4d24018
@@ -19,8 +19,8 @@ module ActiveRecord # :nodoc:
19
19
 
20
20
  # Based on the default <tt>postgresql_connection</tt> definition from ActiveRecord.
21
21
  # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
22
+ # FULL REPLACEMENT because we need to create a different class.
22
23
  def postgis_connection(config)
23
- # FULL REPLACEMENT because we need to create a different class.
24
24
  conn_params = config.symbolize_keys
25
25
 
26
26
  conn_params.delete_if { |_, v| v.nil? }
@@ -30,7 +30,8 @@ module ActiveRecord # :nodoc:
30
30
  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
31
31
 
32
32
  # Forward only valid config params to PGconn.connect.
33
- conn_params.keep_if { |k, _| VALID_CONN_PARAMS.include?(k) }
33
+ valid_conn_param_keys = PGconn.conndefaults_hash.keys + [:requiressl]
34
+ conn_params.slice!(*valid_conn_param_keys)
34
35
 
35
36
  # The postgres drivers don't allow the creation of an unconnected PGconn object,
36
37
  # so just pass a nil connection object for the time being.
@@ -54,7 +54,7 @@ module ActiveRecord
54
54
  has_m: @has_m,
55
55
  has_z: @has_z,
56
56
  sql_type: @sql_type,
57
- srid: @srid,
57
+ srid: @srid
58
58
  )
59
59
  end
60
60
 
@@ -71,30 +71,23 @@ module ActiveRecord
71
71
  end
72
72
 
73
73
  # support setting an RGeo object or a WKT string
74
- def type_cast_for_database(value)
74
+ def serialize(value)
75
75
  return if value.nil?
76
- geo_value = type_cast(value)
76
+ geo_value = cast_value(value)
77
77
 
78
78
  # TODO - only valid types should be allowed
79
79
  # e.g. linestring is not valid for point column
80
80
  # raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
81
81
 
82
82
  RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true)
83
- .generate(geo_value)
83
+ .generate(geo_value)
84
84
  end
85
85
 
86
86
  private
87
87
 
88
- def type_cast(value)
89
- return if value.nil?
90
- String === value ? parse_wkt(value) : value
91
- end
92
-
93
88
  def cast_value(value)
94
89
  return if value.nil?
95
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true).parse(value)
96
- rescue RGeo::Error::ParseError
97
- nil
90
+ String === value ? parse_wkt(value) : value
98
91
  end
99
92
 
100
93
  # convert WKT string into RGeo object
@@ -38,7 +38,7 @@ module ActiveRecord # :nodoc:
38
38
  "database" => "postgres",
39
39
  "password" => su_password,
40
40
  "schema_search_path" => "public",
41
- "username" => su_username,
41
+ "username" => su_username
42
42
  ))
43
43
  end
44
44
 
@@ -46,7 +46,7 @@ module ActiveRecord # :nodoc:
46
46
  establish_connection(configuration.merge(
47
47
  "password" => su_password,
48
48
  "schema_search_path" => "public",
49
- "username" => su_username,
49
+ "username" => su_username
50
50
  ))
51
51
  end
52
52
 
@@ -6,36 +6,39 @@ module ActiveRecord
6
6
  # pass table_name to #new_column
7
7
  def columns(table_name)
8
8
  # Limit, precision, and scale are all handled by the superclass.
9
- column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod|
10
- oid = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
11
- default_value = extract_value_from_default(oid, default)
9
+ column_definitions(table_name).map do |column_name, type, default, notnull, oid, fmod, collation|
10
+ oid = oid.to_i
11
+ fmod = fmod.to_i
12
+ type_metadata = fetch_type_metadata(column_name, type, oid, fmod)
13
+ cast_type = get_oid_type(oid.to_i, fmod.to_i, column_name, type)
14
+ default_value = extract_value_from_default(default)
15
+
12
16
  default_function = extract_default_function(default_value, default)
13
- notnull = notnull == "t" if notnull.is_a?(String) # JDBC gets true/false
14
- new_column(table_name, column_name, default_value, oid, type, !notnull, default_function)
17
+ new_column(table_name, column_name, default_value, cast_type, type_metadata, !notnull, default_function, collation)
15
18
  end
16
19
  end
17
20
 
18
21
  # override
19
- def new_column(table_name, column_name, default, cast_type, sql_type = nil, null = true, default_function = nil)
22
+ def new_column(table_name, column_name, default, cast_type, sql_type_metadata = nil, null = true, default_function = nil, collation = nil)
20
23
  # JDBC gets true/false in Rails 4, where other platforms get 't'/'f' strings.
21
24
  if null.is_a?(String)
22
25
  null = (null == "t")
23
26
  end
24
27
 
25
- column_info = spatial_column_info(table_name).get(column_name, sql_type)
28
+ column_info = spatial_column_info(table_name).get(column_name, sql_type_metadata.sql_type)
26
29
 
27
- SpatialColumn.new(table_name,
28
- column_name,
30
+ SpatialColumn.new(column_name,
29
31
  default,
30
- cast_type,
31
- sql_type,
32
+ sql_type_metadata,
32
33
  null,
33
34
  default_function,
35
+ collation,
36
+ cast_type,
34
37
  column_info)
35
38
  end
36
39
 
37
40
  # override
38
- # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L533
41
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L583
39
42
  #
40
43
  # returns Postgresql sql type string
41
44
  # examples:
@@ -47,7 +50,7 @@ module ActiveRecord
47
50
  #
48
51
  # type_to_sql(:geography, "Point,4326")
49
52
  # => "geography(Point,4326)"
50
- def type_to_sql(type, limit = nil, precision = nil, scale = nil)
53
+ def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
51
54
  case type
52
55
  when :geometry, :geography
53
56
  "#{type}(#{limit})"
@@ -60,22 +63,22 @@ module ActiveRecord
60
63
  def native_database_types
61
64
  # Add spatial types
62
65
  super.merge(
63
- geography: "geography",
64
- geometry: "geometry",
65
- geometry_collection: "geometry_collection",
66
- line_string: "line_string",
67
- multi_line_string: "multi_line_string",
68
- multi_point: "multi_point",
69
- multi_polygon: "multi_polygon",
70
- spatial: "geometry",
71
- st_point: "st_point",
72
- st_polygon: "st_polygon",
66
+ geography: { name: "geography" },
67
+ geometry: { name: "geometry" },
68
+ geometry_collection: { name: "geometry_collection" },
69
+ line_string: { name: "line_string" },
70
+ multi_line_string: { name: "multi_line_string" },
71
+ multi_point: { name: "multi_point" },
72
+ multi_polygon: { name: "multi_polygon" },
73
+ spatial: { name: "geometry" },
74
+ st_point: { name: "st_point" },
75
+ st_polygon: { name: "st_polygon" }
73
76
  )
74
77
  end
75
78
 
76
79
  # override
77
- def create_table_definition(name, temporary, options, as = nil)
78
- PostGIS::TableDefinition.new(native_database_types, name, temporary, options, as)
80
+ def create_table_definition(name, temporary = false, options = nil, as = nil)
81
+ PostGIS::TableDefinition.new(name, temporary, options, as)
79
82
  end
80
83
 
81
84
  # memoize hash of column infos for tables
@@ -8,9 +8,9 @@ module ActiveRecord # :nodoc:
8
8
  # cast_type example classes:
9
9
  # OID::Spatial
10
10
  # OID::Integer
11
- def initialize(table_name, name, default, cast_type, sql_type = nil, null = true, default_function = nil, opts = nil)
12
- @table_name = table_name
13
- @geographic = !!(sql_type =~ /geography\(/i)
11
+ def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation = nil, cast_type = nil, opts = nil)
12
+ @cast_type = cast_type
13
+ @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
14
14
  if opts
15
15
  # This case comes from an entry in the geometry_columns table
16
16
  set_geometric_type_from_name(opts[:type])
@@ -21,16 +21,18 @@ module ActiveRecord # :nodoc:
21
21
  # Geographic type information is embedded in the SQL type
22
22
  @srid = 4326
23
23
  @has_z = @has_m = false
24
- build_from_sql_type(sql_type)
24
+ build_from_sql_type(sql_type_metadata.sql_type)
25
25
  elsif sql_type =~ /geography|geometry|point|linestring|polygon/i
26
+ build_from_sql_type(sql_type_metadata.sql_type)
27
+ elsif sql_type_metadata.sql_type =~ /geography|geometry|point|linestring|polygon/i
26
28
  # A geometry column with no geometry_columns entry.
27
29
  # @geometric_type = geo_type_from_sql_type(sql_type)
28
- build_from_sql_type(sql_type)
30
+ build_from_sql_type(sql_type_metadata.sql_type)
29
31
  end
30
- super(name, default, cast_type, sql_type, null, default_function)
32
+ super(name, default, sql_type_metadata, null, default_function, collation)
31
33
  if spatial?
32
34
  if @srid
33
- @limit = { srid: @srid, type: to_type_name(geometric_type) }
35
+ @limit = { srid: @srid, type: geometric_type.type_name.underscore }
34
36
  @limit[:has_z] = true if @has_z
35
37
  @limit[:has_m] = true if @has_m
36
38
  @limit[:geographic] = true if @geographic
@@ -57,7 +59,7 @@ module ActiveRecord # :nodoc:
57
59
  end
58
60
 
59
61
  def spatial?
60
- cast_type.respond_to?(:spatial?) && cast_type.spatial?
62
+ @cast_type.respond_to?(:spatial?) && @cast_type.spatial?
61
63
  end
62
64
 
63
65
  private
@@ -70,17 +72,6 @@ module ActiveRecord # :nodoc:
70
72
  geo_type, @srid, @has_z, @has_m = OID::Spatial.parse_sql_type(sql_type)
71
73
  set_geometric_type_from_name(geo_type)
72
74
  end
73
-
74
- def to_type_name(geometric_type)
75
- name = geometric_type.type_name.underscore
76
- if name == "point"
77
- "st_point"
78
- elsif name == "polygon"
79
- "st_polygon"
80
- else
81
- name
82
- end
83
- end
84
75
  end
85
76
  end
86
77
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module PostGIS
4
- VERSION = "3.1.5".freeze
4
+ VERSION = "4.0.0.beta1"
5
5
  end
6
6
  end
7
7
  end
@@ -47,9 +47,18 @@ module ActiveRecord
47
47
  # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
48
48
  DEFAULT_SRID = 0
49
49
 
50
- def initialize(*args)
50
+ # def initialize(*args)
51
+ def initialize(connection, logger, connection_parameters, config)
51
52
  super
53
+
52
54
  @visitor = Arel::Visitors::PostGIS.new(self)
55
+ # copy from https://github.com/rails/rails/blob/6ece7df8d80c6d93db43878fa4c0278a0204072c/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L199
56
+ if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
57
+ @prepared_statements = true
58
+ @visitor.extend(DetermineIfPreparableVisitor)
59
+ else
60
+ @prepared_statements = false
61
+ end
53
62
  end
54
63
 
55
64
  def adapter_name
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgis-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 4.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma, Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: 5.0.0.beta
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: 5.0.0.beta
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rgeo-activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.4
33
+ version: 5.0.0.beta
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.4
40
+ version: 5.0.0.beta
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -130,16 +130,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 1.9.3
133
+ version: 2.2.2
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - ">"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 1.3.1
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.6.11
141
+ rubygems_version: 2.5.2
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: ActiveRecord adapter for PostGIS, based on RGeo.
145
145
  test_files: []
146
+ has_rdoc: