activerecord-mysql2rgeo-adapter 2.2.0 → 5.1.0
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 +1 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +22 -22
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +3 -1
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +53 -13
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +2 -2
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +8 -34
- data/lib/active_record/type/spatial.rb +3 -6
- data/lib/activerecord-mysql2rgeo-adapter.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 15b85c3b96245dc0cda126756f7cfb2d1d4fc2a93baa86612e283277934d1d73
|
4
|
+
data.tar.gz: 15eb74772a5f2bea2fec482ef2165c23d7e1c195a8e2acfd7642c3cff4c81448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e391e6373d02448e9c4344c21f495fe190d0455fb1e9d5692add77291e03b476bfba666f32ec036284bc771a74cf3bb182c78dbcd40b6af84d0918aa83c3beb
|
7
|
+
data.tar.gz: 51c01a9e4d540bf2e5b3d58ccf06491fcc91b93df421e353691ff1698f653bbcc975a4f8c5aae587e03ede8457d27b43bb5c9b46720d3c942bc4856a2659f2dd
|
@@ -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 :
|
7
|
-
column(name, 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(
|
11
|
-
|
10
|
+
def geometry(name, options = {})
|
11
|
+
column(name, :geometry, options)
|
12
12
|
end
|
13
13
|
|
14
|
-
def geometrycollection(
|
15
|
-
|
14
|
+
def geometrycollection(name, options = {})
|
15
|
+
column(name, :geometrycollection, options)
|
16
16
|
end
|
17
|
+
alias geometry_collection geometrycollection
|
17
18
|
|
18
|
-
def point(
|
19
|
-
|
19
|
+
def point(name, options = {})
|
20
|
+
column(name, :point, options)
|
20
21
|
end
|
21
22
|
|
22
|
-
def multipoint(
|
23
|
-
|
23
|
+
def multipoint(name, options = {})
|
24
|
+
column(name, :multipoint, options)
|
24
25
|
end
|
26
|
+
alias multi_point multipoint
|
25
27
|
|
26
|
-
def linestring(
|
27
|
-
|
28
|
+
def linestring(name, options = {})
|
29
|
+
column(name, :linestring, options)
|
28
30
|
end
|
31
|
+
alias line_string linestring
|
29
32
|
|
30
|
-
def multilinestring(
|
31
|
-
|
33
|
+
def multilinestring(name, options = {})
|
34
|
+
column(name, :multilinestring, options)
|
32
35
|
end
|
36
|
+
alias multi_line_string multilinestring
|
33
37
|
|
34
|
-
def polygon(
|
35
|
-
|
38
|
+
def polygon(name, options = {})
|
39
|
+
column(name, :polygon, options)
|
36
40
|
end
|
37
41
|
|
38
|
-
def multipolygon(
|
39
|
-
|
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"
|
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
|
7
|
-
|
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
|
-
|
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
|
-
|
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,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"
|
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
|
-
|
104
|
-
|
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
|
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
|
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
|
|
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: 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:
|
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
|
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.
|