activerecord-mysql2rgeo-adapter 2.2.0 → 6.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 +5 -5
- data/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb +3 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +26 -23
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +4 -2
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +48 -19
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb +7 -4
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_expressions.rb +2 -0
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +5 -4
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +4 -2
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +16 -44
- data/lib/active_record/type/spatial.rb +42 -56
- data/lib/activerecord-mysql2rgeo-adapter.rb +2 -0
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46398dbc631a7df55cb3a6364227d7d7aff3bed23e1a442bed6a72394e5f86a6
|
4
|
+
data.tar.gz: 0dcdf66fd2fcaba12c67c2fc6611c935251f131b183df82c25cd5b246e7b89a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 072f382d883353b35f83a9b3463d554696ee6732131aceebfc34aa837d25b0ed04efa38f65427c8bb51132cfc27e74d0e5cbf5992582ada3f2e15a8543d83f34
|
7
|
+
data.tar.gz: a72920ef741fa5c5220fec549a9ce393aee044e81611a70f062fb76011a264d4c8bc5029e20d0d927293c60fe5c7956a2f0ed6bbfb654fd62da94f5cebda94fe
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Arel # :nodoc:
|
2
4
|
module Visitors # :nodoc:
|
3
5
|
# Different super-class under JRuby JDBC adapter.
|
@@ -5,7 +7,7 @@ module Arel # :nodoc:
|
|
5
7
|
::ArJdbc::MySQL::BindSubstitution
|
6
8
|
else
|
7
9
|
MySQL
|
8
|
-
|
10
|
+
end
|
9
11
|
|
10
12
|
class Mysql2Rgeo < MySQLSuperclass # :nodoc:
|
11
13
|
include RGeo::ActiveRecord::SpatialToSql
|
@@ -1,48 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module Mysql2Rgeo
|
4
6
|
module ColumnMethods
|
5
7
|
def spatial(name, options = {})
|
6
|
-
raise "You must set a type. For example: 't.spatial :
|
7
|
-
column(name, options[:limit][:type], options)
|
8
|
-
end
|
8
|
+
raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
|
9
9
|
|
10
|
-
|
11
|
-
multi ? multi_geometry(*args, **options) : args.each { |name| column(name, :geometry, options) }
|
10
|
+
column(name, options[:type], **options)
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
|
13
|
+
def geometry(name, options = {})
|
14
|
+
column(name, :geometry, **options)
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def geometry_collection(name, options = {})
|
18
|
+
column(name, :geometrycollection, **options)
|
20
19
|
end
|
20
|
+
alias geometrycollection geometry_collection
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def line_string(name, options = {})
|
23
|
+
column(name, :linestring, **options)
|
24
24
|
end
|
25
|
+
alias linestring line_string
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def multi_line_string(name, options = {})
|
28
|
+
column(name, :multilinestring, **options)
|
28
29
|
end
|
30
|
+
alias multilinestring multi_line_string
|
29
31
|
|
30
|
-
def
|
31
|
-
|
32
|
+
def multi_point(name, options = {})
|
33
|
+
column(name, :multipoint, **options)
|
32
34
|
end
|
35
|
+
alias multipoint multi_point
|
33
36
|
|
34
|
-
def
|
35
|
-
|
37
|
+
def multi_polygon(name, options = {})
|
38
|
+
column(name, :multipolygon, **options)
|
36
39
|
end
|
40
|
+
alias multipolygon multi_polygon
|
37
41
|
|
38
|
-
def
|
39
|
-
|
42
|
+
def point(name, options = {})
|
43
|
+
column(name, :point, **options)
|
40
44
|
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
alias multi_polygon multipolygon
|
46
|
+
def polygon(name, options = {})
|
47
|
+
column(name, :polygon, **options)
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -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
|
@@ -13,7 +15,7 @@ module ActiveRecord # :nodoc:
|
|
13
15
|
mysql2_connection(config)
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
alias_method :jdbcmysql2rgeo_connection, :mysql2rgeo_connection
|
17
19
|
|
18
20
|
else
|
19
21
|
|
@@ -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"
|
34
|
+
config[:flags].push "FOUND_ROWS"
|
33
35
|
else
|
34
36
|
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
35
37
|
end
|
@@ -1,16 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module Mysql2Rgeo
|
4
6
|
module SchemaStatements
|
7
|
+
# super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb
|
8
|
+
|
5
9
|
# override
|
6
|
-
def
|
7
|
-
|
10
|
+
def indexes(table_name) #:nodoc:
|
11
|
+
indexes = super
|
12
|
+
# HACK(aleks, 06/15/18): MySQL 5 does not support prefix lengths for spatial indexes
|
13
|
+
# https://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
14
|
+
indexes.select { |idx| idx.type == :spatial }.each { |idx| idx.is_a?(Struct) ? idx.lengths = {} : idx.instance_variable_set(:@lengths, {}) }
|
15
|
+
indexes
|
8
16
|
end
|
9
17
|
|
10
18
|
def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc:
|
11
19
|
if (info = RGeo::ActiveRecord.geometric_type_from_name(type.to_s.delete("_")))
|
12
20
|
type = limit[:type] || type if limit.is_a?(::Hash)
|
13
|
-
type = :geometry if type.eql? :spatial
|
14
21
|
type = type.to_s.delete("_").upcase
|
15
22
|
end
|
16
23
|
super
|
@@ -19,32 +26,28 @@ module ActiveRecord
|
|
19
26
|
# override
|
20
27
|
def native_database_types
|
21
28
|
# Add spatial types
|
29
|
+
# Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
|
22
30
|
super.merge(
|
23
|
-
geometry:
|
24
|
-
|
25
|
-
linestring:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
geometry: { name: "geometry" },
|
32
|
+
geometrycollection: { name: "geometrycollection" },
|
33
|
+
linestring: { name: "linestring" },
|
34
|
+
multi_line_string: { name: "multilinestring" },
|
35
|
+
multi_point: { name: "multipoint" },
|
36
|
+
multi_polygon: { name: "multipolygon" },
|
37
|
+
spatial: { name: "geometry" },
|
38
|
+
point: { name: "point" },
|
39
|
+
polygon: { name: "polygon" }
|
32
40
|
)
|
33
41
|
end
|
34
42
|
|
35
|
-
|
36
|
-
def create_table_definition(*args)
|
37
|
-
Mysql2Rgeo::TableDefinition.new(*args)
|
38
|
-
end
|
39
|
-
|
40
|
-
def initialize_type_map(m)
|
43
|
+
def initialize_type_map(m = type_map)
|
41
44
|
super
|
42
45
|
%w(
|
43
46
|
geometry
|
47
|
+
geometrycollection
|
44
48
|
point
|
45
49
|
linestring
|
46
50
|
polygon
|
47
|
-
geometrycollection
|
48
51
|
multipoint
|
49
52
|
multilinestring
|
50
53
|
multipolygon
|
@@ -52,6 +55,32 @@ module ActiveRecord
|
|
52
55
|
m.register_type(geo_type, Type::Spatial.new(geo_type))
|
53
56
|
end
|
54
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
# override
|
61
|
+
def create_table_definition(*args, **options)
|
62
|
+
Mysql2Rgeo::TableDefinition.new(self, *args, **options)
|
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
|
+
default_function,
|
80
|
+
collation: field[:Collation],
|
81
|
+
comment: field[:Comment].presence
|
82
|
+
)
|
83
|
+
end
|
55
84
|
end
|
56
85
|
end
|
57
86
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord # :nodoc:
|
2
4
|
module ConnectionAdapters # :nodoc:
|
3
5
|
module Mysql2Rgeo # :nodoc:
|
4
6
|
class SpatialColumn < ConnectionAdapters::MySQL::Column # :nodoc:
|
5
|
-
|
7
|
+
|
8
|
+
def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, **)
|
6
9
|
@geometric_type = nil
|
7
10
|
if sql_type =~ /geometry|point|linestring|polygon/i
|
8
11
|
build_from_sql_type(sql_type_metadata.sql_type)
|
@@ -11,7 +14,7 @@ module ActiveRecord # :nodoc:
|
|
11
14
|
# @geometric_type = geo_type_from_sql_type(sql_type)
|
12
15
|
build_from_sql_type(sql_type_metadata.sql_type)
|
13
16
|
end
|
14
|
-
super(name, default, sql_type_metadata, null,
|
17
|
+
super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
|
15
18
|
if spatial?
|
16
19
|
if @srid
|
17
20
|
@limit = { type: @geometric_type.type_name.underscore }
|
@@ -34,9 +37,9 @@ module ActiveRecord # :nodoc:
|
|
34
37
|
false
|
35
38
|
end
|
36
39
|
|
40
|
+
alias :geographic? :geographic
|
37
41
|
alias :has_z? :has_z
|
38
42
|
alias :has_m? :has_m
|
39
|
-
alias :geographic? :geographic
|
40
43
|
|
41
44
|
def limit
|
42
45
|
if spatial?
|
@@ -65,7 +68,7 @@ module ActiveRecord # :nodoc:
|
|
65
68
|
end
|
66
69
|
|
67
70
|
def build_from_sql_type(sql_type)
|
68
|
-
geo_type, @srid
|
71
|
+
geo_type, @srid = Type::Spatial.parse_sql_type(sql_type)
|
69
72
|
set_geometric_type_from_name(geo_type)
|
70
73
|
end
|
71
74
|
end
|
@@ -1,11 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveRecord # :nodoc:
|
2
4
|
module ConnectionAdapters # :nodoc:
|
3
5
|
module Mysql2Rgeo # :nodoc:
|
4
6
|
class TableDefinition < MySQL::TableDefinition # :nodoc:
|
5
7
|
include ColumnMethods
|
6
|
-
|
7
8
|
# super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
|
8
|
-
def new_column_definition(name, type, options)
|
9
|
+
def new_column_definition(name, type, **options)
|
9
10
|
if (info = Mysql2RgeoAdapter.spatial_column_options(type.to_sym))
|
10
11
|
if (limit = options.delete(:limit))
|
11
12
|
options.merge!(limit) if limit.is_a?(::Hash)
|
@@ -14,9 +15,9 @@ module ActiveRecord # :nodoc:
|
|
14
15
|
geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
|
15
16
|
|
16
17
|
options[:spatial_type] = geo_type
|
17
|
-
column = super(name, geo_type.downcase.to_sym, options)
|
18
|
+
column = super(name, geo_type.downcase.to_sym, **options)
|
18
19
|
else
|
19
|
-
column = super(name, type, options)
|
20
|
+
column = super(name, type, **options)
|
20
21
|
end
|
21
22
|
|
22
23
|
column
|
@@ -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
|
|
@@ -32,16 +34,16 @@ module ActiveRecord
|
|
32
34
|
|
33
35
|
SPATIAL_COLUMN_OPTIONS =
|
34
36
|
{
|
35
|
-
geometry:
|
36
|
-
geometrycollection:
|
37
|
-
linestring:
|
38
|
-
multilinestring:
|
39
|
-
multipoint:
|
40
|
-
multipolygon:
|
41
|
-
spatial:
|
42
|
-
point:
|
43
|
-
polygon:
|
44
|
-
}
|
37
|
+
geometry: {},
|
38
|
+
geometrycollection: {},
|
39
|
+
linestring: {},
|
40
|
+
multilinestring: {},
|
41
|
+
multipoint: {},
|
42
|
+
multipolygon: {},
|
43
|
+
spatial: { type: "geometry" },
|
44
|
+
point: {},
|
45
|
+
polygon: {}
|
46
|
+
}
|
45
47
|
|
46
48
|
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
47
49
|
DEFAULT_SRID = 0
|
@@ -50,11 +52,10 @@ module ActiveRecord
|
|
50
52
|
super
|
51
53
|
|
52
54
|
@visitor = Arel::Visitors::Mysql2Rgeo.new(self)
|
53
|
-
@visitor.extend(DetermineIfPreparableVisitor) if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
|
54
55
|
end
|
55
56
|
|
56
57
|
def adapter_name
|
57
|
-
"Mysql2Rgeo"
|
58
|
+
"Mysql2Rgeo"
|
58
59
|
end
|
59
60
|
|
60
61
|
def self.spatial_column_options(key)
|
@@ -69,39 +70,10 @@ module ActiveRecord
|
|
69
70
|
!mariadb? && version >= "5.7.6"
|
70
71
|
end
|
71
72
|
|
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
73
|
def quote(value)
|
103
|
-
|
104
|
-
|
74
|
+
dbval = value.try(:value_for_database) || value
|
75
|
+
if RGeo::Feature::Geometry.check_type(dbval)
|
76
|
+
"ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(dbval)},#{dbval.srid})"
|
105
77
|
else
|
106
78
|
super
|
107
79
|
end
|
@@ -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,66 +16,61 @@ 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
|
-
# has_z: false
|
21
|
-
# has_m: false
|
22
22
|
def self.parse_sql_type(sql_type)
|
23
|
-
geo_type, srid
|
23
|
+
geo_type, srid = nil, 0, false, false
|
24
24
|
|
25
25
|
if sql_type =~ /(geography|geometry)\((.*)\)$/i
|
26
|
+
# geometry(Point)
|
26
27
|
# geometry(Point,4326)
|
27
28
|
params = Regexp.last_match(2).split(",")
|
28
|
-
if params.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
if params.last =~ /(\d+)/
|
35
|
-
srid = Regexp.last_match(1).to_i
|
36
|
-
end
|
37
|
-
else
|
38
|
-
# geometry(Point)
|
39
|
-
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
|
40
34
|
end
|
41
35
|
else
|
42
36
|
# geometry
|
37
|
+
# otherType(a,b)
|
43
38
|
geo_type = sql_type
|
44
39
|
end
|
45
|
-
[geo_type, srid
|
40
|
+
[geo_type, srid]
|
46
41
|
end
|
47
42
|
|
48
|
-
def
|
49
|
-
|
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
|
+
)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
:geometry
|
52
|
+
def klass
|
53
|
+
type == :geometry ? RGeo::Feature::Geometry : super
|
54
54
|
end
|
55
55
|
|
56
56
|
def spatial?
|
57
57
|
true
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
|
62
|
-
RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(
|
63
|
-
geo_type: @geo_type,
|
64
|
-
sql_type: @sql_type,
|
65
|
-
srid: @srid
|
66
|
-
)
|
60
|
+
def type
|
61
|
+
:geometry
|
67
62
|
end
|
68
63
|
|
69
64
|
# support setting an RGeo object or a WKT string
|
70
65
|
def serialize(value)
|
71
66
|
return if value.nil?
|
67
|
+
|
72
68
|
geo_value = cast_value(value)
|
73
69
|
|
74
70
|
# TODO - only valid types should be allowed
|
75
71
|
# e.g. linestring is not valid for point column
|
76
72
|
raise "maybe should raise" unless RGeo::Feature::Geometry.check_type(geo_value)
|
73
|
+
|
77
74
|
geo_value
|
78
75
|
end
|
79
76
|
|
@@ -81,35 +78,24 @@ module ActiveRecord
|
|
81
78
|
|
82
79
|
def cast_value(value)
|
83
80
|
return if value.nil?
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
104
|
-
end
|
105
|
-
else
|
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
|
81
|
+
|
82
|
+
::String === value ? parse_wkt(value) : value
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_wkt(string)
|
86
|
+
marker = string[4, 1]
|
87
|
+
if marker == "\x00" || marker == "\x01"
|
88
|
+
srid = string[0, 4].unpack(marker == "\x01" ? "V" : "N").first
|
89
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[4..-1])
|
90
|
+
elsif string[0, 10] =~ /[0-9a-fA-F]{8}0[01]/
|
91
|
+
srid = string[0, 8].to_i(16)
|
92
|
+
srid = [srid].pack("V").unpack("N").first if string[9, 1] == "1"
|
93
|
+
RGeo::WKRep::WKBParser.new(spatial_factory, support_ewkb: true, default_srid: srid).parse(string[8..-1])
|
94
|
+
else
|
95
|
+
RGeo::WKRep::WKTParser.new(spatial_factory, support_ewkt: true, default_srid: @srid).parse(string)
|
112
96
|
end
|
97
|
+
rescue RGeo::Error::ParseError, RGeo::Error::InvalidGeometry
|
98
|
+
nil
|
113
99
|
end
|
114
100
|
end
|
115
101
|
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: 6.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:
|
11
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
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:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rgeo-activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,7 @@ files:
|
|
116
116
|
- lib/activerecord-mysql2rgeo-adapter.rb
|
117
117
|
homepage: http://github.com/stadia/activerecord-mysql2rgeo-adapter
|
118
118
|
licenses:
|
119
|
-
- BSD
|
119
|
+
- BSD-3-Clause
|
120
120
|
metadata: {}
|
121
121
|
post_install_message:
|
122
122
|
rdoc_options: []
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.
|
129
|
+
version: 2.5.0
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
132
|
- - ">="
|
@@ -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.7.6
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: ActiveRecord adapter for MySQL, based on RGeo.
|