activerecord-mysql2rgeo-adapter 5.1.0 → 5.2.2
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/arel_tosql.rb +2 -0
- data/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +19 -17
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +10 -21
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +3 -1
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +10 -12
- data/lib/active_record/type/spatial.rb +37 -51
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff6faa5bd2d1fdbd11d39ae470198df22169779733a6a2edfb07bdb316cf8101
|
4
|
+
data.tar.gz: 1466bc545f7d632a47934022ec1ee16755b3d32d92d7b9fb5e470abefd4858ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 923e9ea973d64cf7503114ce25a88dca5fb1419d9fddad878579a124270a26a7fca55e02364bae8c5822a8d8160635a581539d2b525c3d90bd6bce417f9e8681
|
7
|
+
data.tar.gz: 7fa56cefbadc3afeeb5558f86b6a349adf725eca130bba822a7012e8bd95da0c04ba849501ae950cb34788dab52d9933b096099bc4ba414435b4f0712a0ad176
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module Mysql2Rgeo
|
@@ -11,38 +13,38 @@ module ActiveRecord
|
|
11
13
|
column(name, :geometry, options)
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
16
|
+
def geometry_collection(name, options = {})
|
15
17
|
column(name, :geometrycollection, options)
|
16
18
|
end
|
17
|
-
alias geometry_collection
|
19
|
+
alias geometrycollection geometry_collection
|
18
20
|
|
19
|
-
def
|
20
|
-
column(name, :
|
21
|
+
def line_string(name, options = {})
|
22
|
+
column(name, :linestring, options)
|
21
23
|
end
|
24
|
+
alias linestring line_string
|
22
25
|
|
23
|
-
def
|
26
|
+
def multi_line_string(name, options = {})
|
27
|
+
column(name, :multilinestring, options)
|
28
|
+
end
|
29
|
+
alias multilinestring multi_line_string
|
30
|
+
|
31
|
+
def multi_point(name, options = {})
|
24
32
|
column(name, :multipoint, options)
|
25
33
|
end
|
26
|
-
alias multi_point
|
34
|
+
alias multipoint multi_point
|
27
35
|
|
28
|
-
def
|
29
|
-
column(name, :
|
36
|
+
def multi_polygon(name, options = {})
|
37
|
+
column(name, :multipolygon, options)
|
30
38
|
end
|
31
|
-
alias
|
39
|
+
alias multipolygon multi_polygon
|
32
40
|
|
33
|
-
def
|
34
|
-
column(name, :
|
41
|
+
def point(name, options = {})
|
42
|
+
column(name, :point, options)
|
35
43
|
end
|
36
|
-
alias multi_line_string multilinestring
|
37
44
|
|
38
45
|
def polygon(name, options = {})
|
39
46
|
column(name, :polygon, options)
|
40
47
|
end
|
41
|
-
|
42
|
-
def multipolygon(name, options = {})
|
43
|
-
column(name, :multipolygon, options)
|
44
|
-
end
|
45
|
-
alias multi_polygon multipolygon
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -26,16 +26,15 @@ module ActiveRecord
|
|
26
26
|
# Add spatial types
|
27
27
|
# Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
|
28
28
|
super.merge(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
multi_polygon: { name: "multipolygon" }
|
29
|
+
geometry: { name: "geometry" },
|
30
|
+
geometrycollection: { name: "geometrycollection" },
|
31
|
+
linestring: { name: "linestring" },
|
32
|
+
multi_line_string: { name: "multilinestring" },
|
33
|
+
multi_point: { name: "multipoint" },
|
34
|
+
multi_polygon: { name: "multipolygon" },
|
35
|
+
spatial: { name: "geometry" },
|
36
|
+
point: { name: "point" },
|
37
|
+
polygon: { name: "polygon" }
|
39
38
|
)
|
40
39
|
end
|
41
40
|
|
@@ -72,7 +71,7 @@ module ActiveRecord
|
|
72
71
|
end
|
73
72
|
|
74
73
|
SpatialColumn.new(
|
75
|
-
|
74
|
+
field[:Field],
|
76
75
|
default,
|
77
76
|
type_metadata,
|
78
77
|
field[:Null] == "YES",
|
@@ -81,16 +80,6 @@ module ActiveRecord
|
|
81
80
|
field[:Collation],
|
82
81
|
comment: field[:Comment].presence
|
83
82
|
)
|
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
83
|
end
|
95
84
|
end
|
96
85
|
end
|
@@ -34,9 +34,9 @@ module ActiveRecord # :nodoc:
|
|
34
34
|
false
|
35
35
|
end
|
36
36
|
|
37
|
+
alias :geographic? :geographic
|
37
38
|
alias :has_z? :has_z
|
38
39
|
alias :has_m? :has_m
|
39
|
-
alias :geographic? :geographic
|
40
40
|
|
41
41
|
def limit
|
42
42
|
if spatial?
|
@@ -65,7 +65,7 @@ module ActiveRecord # :nodoc:
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def build_from_sql_type(sql_type)
|
68
|
-
geo_type, @srid
|
68
|
+
geo_type, @srid = Type::Spatial.parse_sql_type(sql_type)
|
69
69
|
set_geometric_type_from_name(geo_type)
|
70
70
|
end
|
71
71
|
end
|
@@ -27,7 +27,6 @@ require "active_record/connection_adapters/mysql2rgeo/create_connection"
|
|
27
27
|
|
28
28
|
# :startdoc:
|
29
29
|
|
30
|
-
# ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter
|
31
30
|
module ActiveRecord
|
32
31
|
module ConnectionAdapters
|
33
32
|
class Mysql2RgeoAdapter < Mysql2Adapter
|
@@ -35,16 +34,16 @@ module ActiveRecord
|
|
35
34
|
|
36
35
|
SPATIAL_COLUMN_OPTIONS =
|
37
36
|
{
|
38
|
-
geometry:
|
39
|
-
geometrycollection:
|
40
|
-
linestring:
|
41
|
-
multilinestring:
|
42
|
-
multipoint:
|
43
|
-
multipolygon:
|
44
|
-
spatial:
|
45
|
-
point:
|
46
|
-
polygon:
|
47
|
-
}
|
37
|
+
geometry: {},
|
38
|
+
geometrycollection: {},
|
39
|
+
linestring: {},
|
40
|
+
multilinestring: {},
|
41
|
+
multipoint: {},
|
42
|
+
multipolygon: {},
|
43
|
+
spatial: { type: "geometry" },
|
44
|
+
point: {},
|
45
|
+
polygon: {}
|
46
|
+
}
|
48
47
|
|
49
48
|
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
50
49
|
DEFAULT_SRID = 0
|
@@ -53,7 +52,6 @@ module ActiveRecord
|
|
53
52
|
super
|
54
53
|
|
55
54
|
@visitor = Arel::Visitors::Mysql2Rgeo.new(self)
|
56
|
-
# @visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
57
55
|
end
|
58
56
|
|
59
57
|
def adapter_name
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module Type
|
3
5
|
class Spatial < Value # :nodoc:
|
@@ -14,53 +16,49 @@ module ActiveRecord
|
|
14
16
|
|
15
17
|
# sql_type: geometry, geometry(Point), geometry(Point,4326), ...
|
16
18
|
#
|
17
|
-
# returns [geo_type, srid
|
19
|
+
# returns [geo_type, srid]
|
18
20
|
# geo_type: geography, geometry, point, line_string, polygon, ...
|
19
21
|
# srid: 1234
|
20
22
|
def self.parse_sql_type(sql_type)
|
21
23
|
geo_type, srid = nil, 0, false, false
|
22
24
|
|
23
25
|
if sql_type =~ /(geography|geometry)\((.*)\)$/i
|
26
|
+
# geometry(Point)
|
24
27
|
# geometry(Point,4326)
|
25
28
|
params = Regexp.last_match(2).split(",")
|
26
|
-
if params.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
srid = Regexp.last_match(1).to_i
|
32
|
-
end
|
33
|
-
else
|
34
|
-
# geometry(Point)
|
35
|
-
geo_type = params[0]
|
29
|
+
if params.first =~ /([a-z]+[^zm])(z?)(m?)/i
|
30
|
+
geo_type = Regexp.last_match(1)
|
31
|
+
end
|
32
|
+
if params.last =~ /(\d+)/
|
33
|
+
srid = Regexp.last_match(1).to_i
|
36
34
|
end
|
37
35
|
else
|
38
36
|
# geometry
|
37
|
+
# otherType(a,b)
|
39
38
|
geo_type = sql_type
|
40
39
|
end
|
41
40
|
[geo_type, srid]
|
42
41
|
end
|
43
42
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
43
|
+
def spatial_factory
|
44
|
+
@spatial_factory ||=
|
45
|
+
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
|
46
|
+
geo_type: @geo_type,
|
47
|
+
sql_type: @sql_type,
|
48
|
+
srid: @srid
|
49
|
+
)
|
47
50
|
end
|
48
51
|
|
49
|
-
def
|
50
|
-
:geometry
|
52
|
+
def klass
|
53
|
+
type == :geometry ? RGeo::Feature::Geometry : super
|
51
54
|
end
|
52
55
|
|
53
56
|
def spatial?
|
54
57
|
true
|
55
58
|
end
|
56
59
|
|
57
|
-
def
|
58
|
-
|
59
|
-
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
|
60
|
-
geo_type: @geo_type,
|
61
|
-
sql_type: @sql_type,
|
62
|
-
srid: @srid
|
63
|
-
)
|
60
|
+
def type
|
61
|
+
:geometry
|
64
62
|
end
|
65
63
|
|
66
64
|
# support setting an RGeo object or a WKT string
|
@@ -78,35 +76,23 @@ module ActiveRecord
|
|
78
76
|
|
79
77
|
def cast_value(value)
|
80
78
|
return if value.nil?
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
srid = value[0, 8].to_i(16)
|
96
|
-
srid = [srid].pack("V").unpack("N").first if value[9, 1] == "1"
|
97
|
-
begin
|
98
|
-
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(value[8..-1])
|
99
|
-
rescue
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
else
|
103
|
-
begin
|
104
|
-
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(value)
|
105
|
-
rescue
|
106
|
-
nil
|
107
|
-
end
|
108
|
-
end
|
79
|
+
::String === value ? parse_wkt(value) : value
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_wkt(string)
|
83
|
+
marker = string[4, 1]
|
84
|
+
if marker == "\x00" || marker == "\x01"
|
85
|
+
srid = string[0, 4].unpack(marker == "\x01" ? "V" : "N").first
|
86
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[4..-1])
|
87
|
+
elsif string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
|
88
|
+
srid = string[0, 8].to_i(16)
|
89
|
+
srid = [srid].pack("V").unpack("N").first if string[9, 1] == "1"
|
90
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[8..-1])
|
91
|
+
else
|
92
|
+
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
|
109
93
|
end
|
94
|
+
rescue RGeo::Error::ParseError
|
95
|
+
nil
|
110
96
|
end
|
111
97
|
end
|
112
98
|
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: 5.
|
4
|
+
version: 5.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yongdae Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|