activerecord-mysql2rgeo-adapter 1.0.5 → 2.0.1
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 +4 -4
- data/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +7 -3
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_expressions.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +10 -40
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +18 -21
- data/lib/active_record/type/spatial.rb +39 -29
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e104b5ca105eca258b3f33c14d39f9b91bce1c7
|
4
|
+
data.tar.gz: 0edc4678c578439e316521489d3efc06aa01b0e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60ac7b3f8914b1af31384ba388401a576e16f04a19dbb8d8d445db1836efbe10cd13b1f9bf8f2714ffc53e2e83ffc97da6fc6cfac272a2be3f16df87c2394050
|
7
|
+
data.tar.gz: 72a7672833e9ed25832df5aff7c2db1bc11b4f594e745cfcf601749459b9fde5057e2100c40829f3fc080917a7b9c29af8db9c205524872e68cd1fd17c541d0f
|
@@ -7,15 +7,19 @@ module ActiveRecord
|
|
7
7
|
SpatialColumn.new(*args)
|
8
8
|
end
|
9
9
|
|
10
|
-
def type_to_sql(type, limit
|
11
|
-
if (info =
|
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 =
|
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 =
|
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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
67
|
-
|
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
|
@@ -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
|
-
|
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 >=
|
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,
|
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(
|
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
|
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 =~ /
|
25
|
+
if sql_type =~ /[geography,geometry]\((.*)\)$/i
|
26
26
|
# geometry(Point,4326)
|
27
|
-
params = Regexp.last_match(
|
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
|
66
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
102
|
-
|
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:
|
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-
|
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.
|
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.
|
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: '
|
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: '
|
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.
|
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.
|