activerecord-mysql2rgeo-adapter 2.2.0 → 5.1.0

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
- SHA1:
3
- metadata.gz: 916dd6c6a2f329f0476e864abd896923ff9703d5
4
- data.tar.gz: d223eee1c5f0985e9a22cccb2a1b3f16fb5b1111
2
+ SHA256:
3
+ metadata.gz: 15b85c3b96245dc0cda126756f7cfb2d1d4fc2a93baa86612e283277934d1d73
4
+ data.tar.gz: 15eb74772a5f2bea2fec482ef2165c23d7e1c195a8e2acfd7642c3cff4c81448
5
5
  SHA512:
6
- metadata.gz: 9fd772f34bf93e71654c74ce98716817faf2e67f353fa01cf92dd18714b8c9a218e4b4e648d32338c1f1546d60a1c940b8d31e8f6f758074cc7daada4d9fa76b
7
- data.tar.gz: c79130a963ea11b357dbb0c50f21c660299c0fed59c739e3bf35bb36b7a287fded05a0de3ab3122b5fd826b7ef237b73b8c532ae084f16be659bd359dd32f76b
6
+ metadata.gz: 3e391e6373d02448e9c4344c21f495fe190d0455fb1e9d5692add77291e03b476bfba666f32ec036284bc771a74cf3bb182c78dbcd40b6af84d0918aa83c3beb
7
+ data.tar.gz: 51c01a9e4d540bf2e5b3d58ccf06491fcc91b93df421e353691ff1698f653bbcc975a4f8c5aae587e03ede8457d27b43bb5c9b46720d3c942bc4856a2659f2dd
@@ -5,7 +5,7 @@ module Arel # :nodoc:
5
5
  ::ArJdbc::MySQL::BindSubstitution
6
6
  else
7
7
  MySQL
8
- end
8
+ end
9
9
 
10
10
  class Mysql2Rgeo < MySQLSuperclass # :nodoc:
11
11
  include RGeo::ActiveRecord::SpatialToSql
@@ -3,45 +3,45 @@ module ActiveRecord
3
3
  module Mysql2Rgeo
4
4
  module ColumnMethods
5
5
  def spatial(name, options = {})
6
- raise "You must set a type. For example: 't.spatial :object1, limit: { type: 'point' }'" if options[:limit].blank? || options[:limit][:type].blank?
7
- column(name, options[:limit][:type], options)
6
+ raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
7
+ column(name, options[:type], options)
8
8
  end
9
9
 
10
- def geometry(*args, multi: false, **options)
11
- multi ? multi_geometry(*args, **options) : args.each { |name| column(name, :geometry, options) }
10
+ def geometry(name, options = {})
11
+ column(name, :geometry, options)
12
12
  end
13
13
 
14
- def geometrycollection(*args, **options)
15
- args.each { |name| column(name, :geometrycollection, options) }
14
+ def geometrycollection(name, options = {})
15
+ column(name, :geometrycollection, options)
16
16
  end
17
+ alias geometry_collection geometrycollection
17
18
 
18
- def point(*args, multi: false, **options)
19
- multi ? multi_point(*args, **options) : args.each { |name| column(name, :point, options) }
19
+ def point(name, options = {})
20
+ column(name, :point, options)
20
21
  end
21
22
 
22
- def multipoint(*args, **options)
23
- args.each { |name| column(name, :multipoint, options) }
23
+ def multipoint(name, options = {})
24
+ column(name, :multipoint, options)
24
25
  end
26
+ alias multi_point multipoint
25
27
 
26
- def linestring(*args, multi: false, **options)
27
- multi ? multi_linestring(*args, **options) : args.each { |name| column(name, :linestring, options) }
28
+ def linestring(name, options = {})
29
+ column(name, :linestring, options)
28
30
  end
31
+ alias line_string linestring
29
32
 
30
- def multilinestring(*args, **options)
31
- args.each { |name| column(name, :multilinestring, options) }
33
+ def multilinestring(name, options = {})
34
+ column(name, :multilinestring, options)
32
35
  end
36
+ alias multi_line_string multilinestring
33
37
 
34
- def polygon(*args, multi: false, **options)
35
- multi ? multipolygon(*args, **options) : args.each { |name| column(name, :polygon, options) }
38
+ def polygon(name, options = {})
39
+ column(name, :polygon, options)
36
40
  end
37
41
 
38
- def multipolygon(*args, **options)
39
- args.each { |name| column(name, :multipolygon, options) }
42
+ def multipolygon(name, options = {})
43
+ column(name, :multipolygon, options)
40
44
  end
41
-
42
- alias multi_point multipoint
43
- alias multi_geometry geometrycollection
44
- alias multi_linestring multilinestring
45
45
  alias multi_polygon multipolygon
46
46
  end
47
47
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if RUBY_ENGINE == "jruby"
2
4
  require "active_record/connection_adapters/jdbcmysql_adapter"
3
5
  else
@@ -29,7 +31,7 @@ module ActiveRecord # :nodoc:
29
31
 
30
32
  if Mysql2::Client.const_defined? :FOUND_ROWS
31
33
  if config[:flags].is_a? Array
32
- config[:flags].push "FOUND_ROWS".freeze
34
+ config[:flags].push "FOUND_ROWS"
33
35
  else
34
36
  config[:flags] |= Mysql2::Client::FOUND_ROWS
35
37
  end
@@ -1,16 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module Mysql2Rgeo
4
6
  module SchemaStatements
5
7
  # override
6
- def new_column(*args)
7
- SpatialColumn.new(*args)
8
+ def indexes(table_name) #:nodoc:
9
+ indexes = super
10
+ # HACK(aleks, 06/15/18): MySQL 5 does not support prefix lengths for spatial indexes
11
+ # https://dev.mysql.com/doc/refman/5.6/en/create-index.html
12
+ indexes.select { |idx| idx.type == :spatial }.each { |idx| idx.is_a?(Struct) ? idx.lengths = {} : idx.instance_variable_set(:@lengths, {}) }
13
+ indexes
8
14
  end
9
15
 
10
16
  def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
11
17
  if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
12
18
  type = limit[:type] || type if limit.is_a?(::Hash)
13
- type = :geometry if type.eql? :spatial
14
19
  type = type.to_s.delete("_").upcase
15
20
  end
16
21
  super
@@ -19,32 +24,29 @@ module ActiveRecord
19
24
  # override
20
25
  def native_database_types
21
26
  # Add spatial types
27
+ # Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
22
28
  super.merge(
29
+ spatial: { name: "geometry" },
23
30
  geometry: { name: "geometry" },
31
+ geometrycollection: { name: "geometrycollection" },
24
32
  point: { name: "point" },
25
33
  linestring: { name: "linestring" },
26
34
  polygon: { name: "polygon" },
27
- multi_geometry: { name: "geometrycollection" },
35
+ multipoint: { name: "multipoint" },
28
36
  multi_point: { name: "multipoint" },
29
37
  multi_linestring: { name: "multilinestring" },
30
- multi_polygon: { name: "multipolygon" },
31
- spatial: { name: "geometry", limit: { type: :point } }
38
+ multi_polygon: { name: "multipolygon" }
32
39
  )
33
40
  end
34
41
 
35
- # override
36
- def create_table_definition(*args)
37
- Mysql2Rgeo::TableDefinition.new(*args)
38
- end
39
-
40
- def initialize_type_map(m)
42
+ def initialize_type_map(m = type_map)
41
43
  super
42
44
  %w(
43
45
  geometry
46
+ geometrycollection
44
47
  point
45
48
  linestring
46
49
  polygon
47
- geometrycollection
48
50
  multipoint
49
51
  multilinestring
50
52
  multipolygon
@@ -52,6 +54,44 @@ module ActiveRecord
52
54
  m.register_type(geo_type, Type::Spatial.new(geo_type))
53
55
  end
54
56
  end
57
+
58
+ private
59
+
60
+ # override
61
+ def create_table_definition(*args)
62
+ Mysql2Rgeo::TableDefinition.new(*args)
63
+ end
64
+
65
+ # override
66
+ def new_column_from_field(table_name, field)
67
+ type_metadata = fetch_type_metadata(field[:Type], field[:Extra])
68
+ if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default])
69
+ default, default_function = nil, field[:Default]
70
+ else
71
+ default, default_function = field[:Default], nil
72
+ end
73
+
74
+ SpatialColumn.new(
75
+ field[:Field],
76
+ default,
77
+ type_metadata,
78
+ field[:Null] == "YES",
79
+ table_name,
80
+ default_function,
81
+ field[:Collation],
82
+ comment: field[:Comment].presence
83
+ )
84
+ # MySQL::Column.new(
85
+ # field[:Field],
86
+ # default,
87
+ # type_metadata,
88
+ # field[:Null] == "YES",
89
+ # table_name,
90
+ # default_function,
91
+ # field[:Collation],
92
+ # comment: field[:Comment].presence
93
+ # )
94
+ end
55
95
  end
56
96
  end
57
97
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module Mysql2Rgeo
4
- VERSION = "2.2.0".freeze
4
+ VERSION = "5.1.0".freeze
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The activerecord-mysql2rgeo-adapter gem installs the *mysql2rgeo*
2
4
  # connection adapter into ActiveRecord.
3
5
 
@@ -25,6 +27,7 @@ require "active_record/connection_adapters/mysql2rgeo/create_connection"
25
27
 
26
28
  # :startdoc:
27
29
 
30
+ # ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter
28
31
  module ActiveRecord
29
32
  module ConnectionAdapters
30
33
  class Mysql2RgeoAdapter < Mysql2Adapter
@@ -50,11 +53,11 @@ module ActiveRecord
50
53
  super
51
54
 
52
55
  @visitor = Arel::Visitors::Mysql2Rgeo.new(self)
53
- @visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
56
+ # @visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
54
57
  end
55
58
 
56
59
  def adapter_name
57
- "Mysql2Rgeo".freeze
60
+ "Mysql2Rgeo"
58
61
  end
59
62
 
60
63
  def self.spatial_column_options(key)
@@ -69,39 +72,10 @@ module ActiveRecord
69
72
  !mariadb? && version >= "5.7.6"
70
73
  end
71
74
 
72
- # Returns an array of indexes for the given table.
73
- def indexes(table_name, name = nil) #:nodoc:
74
- if name
75
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
76
- Passing name to #indexes is deprecated without replacement.
77
- MSG
78
- end
79
-
80
- indexes = []
81
- current_index = nil
82
- execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
83
- each_hash(result) do |row|
84
- if current_index != row[:Key_name]
85
- next if row[:Key_name] == "PRIMARY" # skip the primary key
86
- current_index = row[:Key_name]
87
-
88
- mysql_index_type = row[:Index_type].downcase.to_sym
89
- index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
90
- index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
91
- indexes << IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence)
92
- end
93
-
94
- indexes.last.columns << row[:Column_name]
95
- indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part] && mysql_index_type != :spatial
96
- end
97
- end
98
-
99
- indexes
100
- end
101
-
102
75
  def quote(value)
103
- if RGeo::Feature::Geometry.check_type(value)
104
- "ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(value)},#{value.srid})"
76
+ dbval = value.try(:value_for_database) || value
77
+ if RGeo::Feature::Geometry.check_type(dbval)
78
+ "ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(dbval)},#{dbval.srid})"
105
79
  else
106
80
  super
107
81
  end
@@ -17,18 +17,14 @@ module ActiveRecord
17
17
  # returns [geo_type, srid, has_z, has_m]
18
18
  # geo_type: geography, geometry, point, line_string, polygon, ...
19
19
  # srid: 1234
20
- # has_z: false
21
- # has_m: false
22
20
  def self.parse_sql_type(sql_type)
23
- geo_type, srid, has_z, has_m = nil, 0, false, false
21
+ geo_type, srid = nil, 0, false, false
24
22
 
25
23
  if sql_type =~ /(geography|geometry)\((.*)\)$/i
26
24
  # geometry(Point,4326)
27
25
  params = Regexp.last_match(2).split(",")
28
26
  if params.size > 1
29
27
  if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
30
- has_z = !Regexp.last_match(2).empty?
31
- has_m = !Regexp.last_match(3).empty?
32
28
  geo_type = Regexp.last_match(1)
33
29
  end
34
30
  if params.last =~ /(\d+)/
@@ -42,10 +38,11 @@ module ActiveRecord
42
38
  # geometry
43
39
  geo_type = sql_type
44
40
  end
45
- [geo_type, srid, has_z, has_m]
41
+ [geo_type, srid]
46
42
  end
47
43
 
48
44
  def klass
45
+ puts type
49
46
  type == :geometry ? RGeo::Feature::Geometry : super
50
47
  end
51
48
 
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_record/connection_adapters/mysql2rgeo_adapter"
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: 2.2.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yongdae Hwang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-28 00:00:00.000000000 Z
11
+ date: 2019-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -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.14
137
+ rubygems_version: 2.7.6
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: ActiveRecord adapter for MySQL, based on RGeo.