activerecord-mysql2rgeo-adapter 1.0.5 → 2.0.1

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: 3a35cacf27708b88079361795afb35a4673ceb7c
4
- data.tar.gz: af091d82862dabd35ebeaf824402ff41549d0250
3
+ metadata.gz: 4e104b5ca105eca258b3f33c14d39f9b91bce1c7
4
+ data.tar.gz: 0edc4678c578439e316521489d3efc06aa01b0e3
5
5
  SHA512:
6
- metadata.gz: 6a3c6341b3d00589d31a4fddb8a8cbbbbfa0f20a411fedf02f48953f8cdb81fcc7b90617e1f4e00a38440927208f76487d5758138c2994fac2a751340cf767a4
7
- data.tar.gz: 30c1d75c52971c065ff6f39c37dd015cd40781a7638bba5eb5ee86607d5fd3c2da73b3bceded05a681ca966922d11d2516d766834904d1f11cf0b94bb2522d54
6
+ metadata.gz: 60ac7b3f8914b1af31384ba388401a576e16f04a19dbb8d8d445db1836efbe10cd13b1f9bf8f2714ffc53e2e83ffc97da6fc6cfac272a2be3f16df87c2394050
7
+ data.tar.gz: 72a7672833e9ed25832df5aff7c2db1bc11b4f594e745cfcf601749459b9fde5057e2100c40829f3fc080917a7b9c29af8db9c205524872e68cd1fd17c541d0f
@@ -44,8 +44,8 @@ module ActiveRecord
44
44
  alias multi_linestring multilinestring
45
45
  alias multi_polygon multipolygon
46
46
  end
47
- end
48
47
 
49
- MySQL::Table.include Mysql2Rgeo::ColumnMethods
48
+ MySQL::Table.send(:include, ColumnMethods)
49
+ end
50
50
  end
51
51
  end
@@ -4,8 +4,8 @@ else
4
4
  require "mysql2"
5
5
  end
6
6
 
7
- module ActiveRecord # :nodoc:
8
- module ConnectionHandling # :nodoc:
7
+ module ActiveRecord # :nodoc:
8
+ module ConnectionHandling # :nodoc:
9
9
  if RUBY_ENGINE == "jruby"
10
10
 
11
11
  def jdbcmysql2rgeo_connection(config)
@@ -7,15 +7,19 @@ module ActiveRecord
7
7
  SpatialColumn.new(*args)
8
8
  end
9
9
 
10
- def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil)
11
- if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
10
+ def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
11
+ if (info = spatial_column_constructor(type.to_sym))
12
12
  type = limit[:type] || type if limit.is_a?(::Hash)
13
- type = "geometry" if type.to_s == "spatial"
13
+ type = 'geometry' if type.to_s.eql? 'spatial'
14
14
  type = type.to_s.delete("_").upcase
15
15
  end
16
16
  super
17
17
  end
18
18
 
19
+ def spatial_column_constructor(name)
20
+ RGeo::ActiveRecord::DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS[name]
21
+ end
22
+
19
23
  # override
20
24
  def native_database_types
21
25
  # Add spatial types
@@ -15,4 +15,4 @@ end
15
15
  # Allow chaining of spatial expressions from attributes
16
16
  Arel::Attribute.send :include, RGeo::ActiveRecord::Mysql2Rgeo::SpatialExpressions
17
17
  RGeo::ActiveRecord::SpatialConstantNode.send :include, RGeo::ActiveRecord::Mysql2Rgeo::SpatialExpressions
18
- RGeo::ActiveRecord::SpatialNamedFunction.send :include, RGeo::ActiveRecord::Mysql2Rgeo::SpatialExpressions
18
+ RGeo::ActiveRecord::SpatialNamedFunction.send :include, RGeo::ActiveRecord::Mysql2Rgeo::SpatialExpressions
@@ -11,64 +11,34 @@ module ActiveRecord # :nodoc:
11
11
  options.merge!(limit) if limit.is_a?(::Hash)
12
12
  end
13
13
 
14
- geo_type = ColumnDefinition.geo_type(options[:type] || type || info[:type])
14
+ geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
15
15
  base_type = info[:type] || :geometry
16
16
 
17
17
  # puts name.dup << " - " << type.to_s << " - " << options.to_s << " :: " << geo_type.to_s << " - " << base_type.to_s
18
18
 
19
+ options[:spatial_type] = geo_type
19
20
  column = super(name, geo_type.downcase.to_sym, options)
20
- column.spatial_type = geo_type
21
- column.srid = options[:srid]
22
21
  else
23
22
  column = super(name, type, options)
24
23
  end
25
24
 
26
25
  column
27
26
  end
28
-
29
- private
30
-
31
- def create_column_definition(name, type)
32
- if Mysql2RgeoAdapter.spatial_column_options(type.to_sym)
33
- Mysql2Rgeo::ColumnDefinition.new(name, type)
34
- else
35
- super
36
- end
37
- end
38
27
  end
39
28
 
40
- class ColumnDefinition < MySQL::ColumnDefinition
41
- # needs to accept the spatial type? or figure out from limit ?
42
-
43
- def self.geo_type(type = "GEOMETRY")
44
- g_type = type.to_s.delete("_").upcase
45
- return "POINT" if g_type == "POINT"
46
- return "POLYGON" if g_type == "POLYGON"
47
- g_type
48
- end
49
-
50
- def spatial_type
51
- @spatial_type
52
- end
53
-
54
- def spatial_type=(value)
55
- @spatial_type = value.to_s
56
- end
29
+ SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial)
57
30
 
58
- def srid
59
- if @srid
60
- @srid.to_i
61
- else
62
- Mysql2RgeoAdapter::DEFAULT_SRID
31
+ module ColumnDefinitionUtils
32
+ class << self
33
+ def geo_type(type = "GEOMETRY")
34
+ type.to_s.delete('_').upcase
63
35
  end
64
- end
65
36
 
66
- def srid=(value)
67
- @srid = value
37
+ def default_srid(options)
38
+ options[:geographic] ? 4326 : Mysql2RgeoAdapter::DEFAULT_SRID
39
+ end
68
40
  end
69
41
  end
70
-
71
- SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial)
72
42
  end
73
43
  end
74
44
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module Mysql2Rgeo
4
- VERSION = "1.0.5".freeze
4
+ VERSION = "2.0.1".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -3,22 +3,15 @@
3
3
 
4
4
  # :stopdoc:
5
5
 
6
- require "rgeo/active_record"
7
-
8
- # autoload AbstractAdapter to avoid circular require and void context warnings
9
- module ActiveRecord
10
- module ConnectionAdapters
11
- AbstractAdapter
12
- end
13
- end
14
-
15
6
  require "active_record/connection_adapters/mysql2_adapter"
7
+ require "rgeo/active_record"
16
8
  require "active_record/connection_adapters/mysql2rgeo/version"
17
9
  require "active_record/connection_adapters/mysql2rgeo/column_methods"
18
10
  require "active_record/connection_adapters/mysql2rgeo/schema_statements"
19
11
  require "active_record/connection_adapters/mysql2rgeo/spatial_table_definition"
20
12
  require "active_record/connection_adapters/mysql2rgeo/spatial_column"
21
13
  require "active_record/connection_adapters/mysql2rgeo/spatial_expressions"
14
+ require "arel/visitors/bind_visitor"
22
15
  require "active_record/connection_adapters/mysql2rgeo/arel_tosql"
23
16
  require "active_record/type/spatial"
24
17
  require "active_record/connection_adapters/mysql2rgeo/create_connection"
@@ -35,17 +28,19 @@ module ActiveRecord
35
28
  geometry: {},
36
29
  geometrycollection: {},
37
30
  linestring: {},
38
- spatial: { type: "geometry" }.freeze,
39
- point: {},
40
- polygon: {},
41
31
  multilinestring: {},
42
32
  multipoint: {},
43
33
  multipolygon: {},
44
- }.freeze
34
+ spatial: { type: "geometry" },
35
+ point: {},
36
+ polygon: {}
37
+ }
45
38
 
46
39
  # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
47
40
  DEFAULT_SRID = 0
48
41
 
42
+ ADAPTER_NAME = "Mysql2Rgeo".freeze
43
+
49
44
  def initialize(connection, logger, connection_options, config)
50
45
  super
51
46
 
@@ -53,10 +48,6 @@ module ActiveRecord
53
48
  @visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
54
49
  end
55
50
 
56
- def adapter_name
57
- "Mysql2Rgeo".freeze
58
- end
59
-
60
51
  def self.spatial_column_options(key)
61
52
  SPATIAL_COLUMN_OPTIONS[key]
62
53
  end
@@ -66,11 +57,17 @@ module ActiveRecord
66
57
  end
67
58
 
68
59
  def supports_spatial?
69
- !mariadb? && version >= '5.7.6'
60
+ !mariadb? && version >= "5.7.6"
70
61
  end
71
62
 
72
63
  # Returns an array of indexes for the given table.
73
- def indexes(table_name, _name = nil) #:nodoc:
64
+ def indexes(table_name, name = nil) #:nodoc:
65
+ if name
66
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
67
+ Passing name to #indexes is deprecated without replacement.
68
+ MSG
69
+ end
70
+
74
71
  indexes = []
75
72
  current_index = nil
76
73
  execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
@@ -87,7 +84,7 @@ module ActiveRecord
87
84
  options.push(true)
88
85
  Mysql2Rgeo::SpatialIndexDefinition.new(*options)
89
86
  else
90
- IndexDefinition.new(*options)
87
+ IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)
91
88
  end
92
89
  end
93
90
 
@@ -99,7 +96,7 @@ module ActiveRecord
99
96
  indexes
100
97
  end
101
98
 
102
- def quote(value, column = nil)
99
+ def quote(value)
103
100
  if RGeo::Feature::Geometry.check_type(value)
104
101
  "ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(value)},#{value.srid})"
105
102
  else
@@ -22,9 +22,9 @@ module ActiveRecord
22
22
  def self.parse_sql_type(sql_type)
23
23
  geo_type, srid, has_z, has_m = nil, 0, false, false
24
24
 
25
- if sql_type =~ /(geography|geometry)\((.*)\)$/i
25
+ if sql_type =~ /[geography,geometry]\((.*)\)$/i
26
26
  # geometry(Point,4326)
27
- params = Regexp.last_match(2).split(",")
27
+ params = Regexp.last_match(1).split(",")
28
28
  if params.size > 1
29
29
  if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
30
30
  has_z = !Regexp.last_match(2).empty?
@@ -45,25 +45,25 @@ module ActiveRecord
45
45
  [geo_type, srid, has_z, has_m]
46
46
  end
47
47
 
48
- def spatial_factory
49
- @spatial_factory ||=
50
- RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
51
- geo_type: @geo_type,
52
- sql_type: @sql_type,
53
- srid: @srid
54
- )
55
- end
56
-
57
48
  def klass
58
49
  type == :geometry ? RGeo::Feature::Geometry : super
59
50
  end
60
51
 
52
+ def type
53
+ :geometry
54
+ end
55
+
61
56
  def spatial?
62
57
  true
63
58
  end
64
59
 
65
- def type
66
- :geometry
60
+ def spatial_factory
61
+ @spatial_factory ||=
62
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
63
+ geo_type: @geo_type,
64
+ sql_type: @sql_type,
65
+ srid: @srid
66
+ )
67
67
  end
68
68
 
69
69
  # support setting an RGeo object or a WKT string
@@ -82,24 +82,34 @@ module ActiveRecord
82
82
  def cast_value(value)
83
83
  return if value.nil?
84
84
  case value
85
- when ::RGeo::Feature::Geometry
86
- value
87
- # RGeo::Feature.cast(value, spatial_factory) rescue nil
88
- when ::String
89
- marker = value[4, 1]
90
- if marker == "\x00" || marker == "\x01"
91
- srid = value[0, 4].unpack(marker == "\x01" ? 'V' : 'N').first
92
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[4..-1]) rescue nil
93
- elsif value[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
94
- srid = value[0, 8].to_i(16)
95
- srid = [srid].pack('V').unpack('N').first if value[9, 1] == '1'
96
- RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[8..-1]) rescue nil
97
- else
98
- RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(value) rescue nil
85
+ when ::RGeo::Feature::Geometry
86
+ value
87
+ # RGeo::Feature.cast(value, spatial_factory) rescue nil
88
+ when ::String
89
+ marker = value[4, 1]
90
+ if marker == "\x00" || marker == "\x01"
91
+ srid = value[0, 4].unpack(marker == "\x01" ? "V" : "N").first
92
+ begin
93
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[4..-1])
94
+ rescue
95
+ nil
96
+ end
97
+ elsif value[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
98
+ srid = value[0, 8].to_i(16)
99
+ srid = [srid].pack("V").unpack("N").first if value[9, 1] == "1"
100
+ begin
101
+ RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[8..-1])
102
+ rescue
103
+ nil
99
104
  end
100
105
  else
101
- nil
102
- end
106
+ begin
107
+ RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(value)
108
+ rescue
109
+ nil
110
+ end
111
+ end
112
+ end
103
113
  end
104
114
  end
105
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-mysql2rgeo-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yongdae Hwang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-05-31 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: 5.0.0
19
+ version: '5.1'
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: 5.0.0
26
+ version: '5.1'
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: '6.0'
33
+ version: '5.1'
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: '6.0'
40
+ version: '5.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.6.13
137
+ rubygems_version: 2.6.11
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: ActiveRecord adapter for MySQL, based on RGeo.