activerecord-mysql2rgeo-adapter 6.0.2 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_creation.rb +1 -3
- data/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +0 -36
- data/lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb +6 -14
- data/lib/active_record/connection_adapters/mysql2rgeo/version.rb +1 -1
- data/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +73 -12
- data/lib/active_record/type/spatial.rb +3 -1
- metadata +13 -15
- data/lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b51d6b8bbeef0f4003a744ff290caf196e9b244764e1dc0c213e686625f40c59
|
4
|
+
data.tar.gz: 0e8e02728246d292e72bb5dd248ffa47a06a601acbde684551a9c098a1a96286
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ffae8e8ff77dccdeff97ac7eaaa8167dd42bbc8fe3e51b0240973e729b453d5d99a4b56164bfc2538059e7ad9a0b5089dc8c14472c8469f8e21c3246986ce9b
|
7
|
+
data.tar.gz: 6eb7aacd144536fe15a7068f5731e1d0f00d44b7d6044f94ae83254df5b1a684c579d0ab455d2ad2a2fde715b4594e1893229e25c90beac3389b4de137fb8725
|
@@ -4,15 +4,13 @@ module ActiveRecord
|
|
4
4
|
module ConnectionAdapters
|
5
5
|
module Mysql2Rgeo
|
6
6
|
class SchemaCreation < MySQL::SchemaCreation # :nodoc:
|
7
|
-
delegate :supports_expression_index?, to: :@conn, private: true
|
8
|
-
|
9
7
|
private
|
10
8
|
|
11
9
|
def add_column_options!(sql, options)
|
12
10
|
# By default, TIMESTAMP columns are NOT NULL, cannot contain NULL values,
|
13
11
|
# and assigning NULL assigns the current timestamp. To permit a TIMESTAMP
|
14
12
|
# column to contain NULL, explicitly declare it with the NULL attribute.
|
15
|
-
# See https://dev.mysql.com/doc/refman/
|
13
|
+
# See https://dev.mysql.com/doc/refman/en/timestamp-initialization.html
|
16
14
|
if /\Atimestamp\b/.match?(options[:column].sql_type) && !options[:primary_key]
|
17
15
|
sql << " NULL" unless options[:null] == false || options_include_default?(options)
|
18
16
|
end
|
@@ -26,42 +26,6 @@ module ActiveRecord
|
|
26
26
|
super
|
27
27
|
end
|
28
28
|
|
29
|
-
# override
|
30
|
-
def native_database_types
|
31
|
-
# Add spatial types
|
32
|
-
# Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
|
33
|
-
super.merge(
|
34
|
-
geometry: { name: "geometry" },
|
35
|
-
geometrycollection: { name: "geometrycollection" },
|
36
|
-
linestring: { name: "linestring" },
|
37
|
-
multi_line_string: { name: "multilinestring" },
|
38
|
-
multi_point: { name: "multipoint" },
|
39
|
-
multi_polygon: { name: "multipolygon" },
|
40
|
-
spatial: { name: "geometry" },
|
41
|
-
point: { name: "point" },
|
42
|
-
polygon: { name: "polygon" }
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize_type_map(m = type_map)
|
47
|
-
super
|
48
|
-
|
49
|
-
%w[
|
50
|
-
geometry
|
51
|
-
geometrycollection
|
52
|
-
point
|
53
|
-
linestring
|
54
|
-
polygon
|
55
|
-
multipoint
|
56
|
-
multilinestring
|
57
|
-
multipolygon
|
58
|
-
].each do |geo_type|
|
59
|
-
m.register_type(geo_type) do |sql_type|
|
60
|
-
Type::Spatial.new(sql_type)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
29
|
private
|
66
30
|
|
67
31
|
# override
|
@@ -20,7 +20,7 @@ module ActiveRecord # :nodoc:
|
|
20
20
|
super(name, default, sql_type_metadata, null, default_function, collation: collation, comment: comment)
|
21
21
|
if spatial?
|
22
22
|
if @srid
|
23
|
-
@limit = { type:
|
23
|
+
@limit = { type: geometric_type.type_name.underscore, srid: @srid }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -43,24 +43,16 @@ module ActiveRecord # :nodoc:
|
|
43
43
|
alias has_z? has_z
|
44
44
|
alias has_m? has_m
|
45
45
|
|
46
|
-
def
|
47
|
-
|
48
|
-
@limit
|
49
|
-
else
|
50
|
-
super
|
51
|
-
end
|
46
|
+
def multi?
|
47
|
+
/^(geometrycollection|multi)/i.match?(sql_type)
|
52
48
|
end
|
53
49
|
|
54
|
-
def
|
55
|
-
|
50
|
+
def limit
|
51
|
+
spatial? ? @limit : super
|
56
52
|
end
|
57
53
|
|
58
54
|
def spatial?
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def multi?
|
63
|
-
/^(geometrycollection|multi)/i.match?(sql_type)
|
55
|
+
%i[geometry geography].include?(@sql_type_metadata.type)
|
64
56
|
end
|
65
57
|
|
66
58
|
private
|
@@ -7,13 +7,7 @@
|
|
7
7
|
|
8
8
|
require "rgeo/active_record"
|
9
9
|
|
10
|
-
|
11
|
-
module ActiveRecord
|
12
|
-
module ConnectionAdapters
|
13
|
-
AbstractAdapter
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
10
|
+
require "active_record/connection_adapters"
|
17
11
|
require "active_record/connection_adapters/mysql2_adapter"
|
18
12
|
require "active_record/connection_adapters/mysql2rgeo/version"
|
19
13
|
require "active_record/connection_adapters/mysql2rgeo/column_methods"
|
@@ -25,13 +19,35 @@ require "active_record/connection_adapters/mysql2rgeo/spatial_column_info"
|
|
25
19
|
require "active_record/connection_adapters/mysql2rgeo/spatial_expressions"
|
26
20
|
require "active_record/connection_adapters/mysql2rgeo/arel_tosql"
|
27
21
|
require "active_record/type/spatial"
|
28
|
-
require "active_record/connection_adapters/mysql2rgeo/create_connection"
|
29
22
|
|
30
23
|
# :startdoc:
|
31
24
|
|
32
25
|
module ActiveRecord
|
26
|
+
module ConnectionHandling # :nodoc:
|
27
|
+
# Establishes a connection to the database that's used by all Active Record objects.
|
28
|
+
def mysql2rgeo_connection(config)
|
29
|
+
config = config.symbolize_keys
|
30
|
+
config[:flags] ||= 0
|
31
|
+
|
32
|
+
if config[:flags].kind_of? Array
|
33
|
+
config[:flags].push "FOUND_ROWS"
|
34
|
+
else
|
35
|
+
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
36
|
+
end
|
37
|
+
|
38
|
+
ConnectionAdapters::Mysql2RgeoAdapter.new(
|
39
|
+
ConnectionAdapters::Mysql2RgeoAdapter.new_client(config),
|
40
|
+
logger,
|
41
|
+
nil,
|
42
|
+
config,
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
33
47
|
module ConnectionAdapters
|
34
48
|
class Mysql2RgeoAdapter < Mysql2Adapter
|
49
|
+
ADAPTER_NAME = "Mysql2Rgeo"
|
50
|
+
|
35
51
|
include Mysql2Rgeo::SchemaStatements
|
36
52
|
|
37
53
|
SPATIAL_COLUMN_OPTIONS =
|
@@ -56,10 +72,6 @@ module ActiveRecord
|
|
56
72
|
@visitor = Arel::Visitors::Mysql2Rgeo.new(self)
|
57
73
|
end
|
58
74
|
|
59
|
-
def adapter_name
|
60
|
-
"Mysql2Rgeo"
|
61
|
-
end
|
62
|
-
|
63
75
|
def self.spatial_column_options(key)
|
64
76
|
SPATIAL_COLUMN_OPTIONS[key]
|
65
77
|
end
|
@@ -68,6 +80,50 @@ module ActiveRecord
|
|
68
80
|
DEFAULT_SRID
|
69
81
|
end
|
70
82
|
|
83
|
+
def native_database_types
|
84
|
+
# Add spatial types
|
85
|
+
# Reference: https://dev.mysql.com/doc/refman/5.6/en/spatial-type-overview.html
|
86
|
+
super.merge(
|
87
|
+
geometry: { name: "geometry" },
|
88
|
+
geometrycollection: { name: "geometrycollection" },
|
89
|
+
linestring: { name: "linestring" },
|
90
|
+
multi_line_string: { name: "multilinestring" },
|
91
|
+
multi_point: { name: "multipoint" },
|
92
|
+
multi_polygon: { name: "multipolygon" },
|
93
|
+
spatial: { name: "geometry" },
|
94
|
+
point: { name: "point" },
|
95
|
+
polygon: { name: "polygon" }
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
class << self
|
100
|
+
|
101
|
+
private
|
102
|
+
def initialize_type_map(m)
|
103
|
+
super
|
104
|
+
|
105
|
+
%w[
|
106
|
+
geometry
|
107
|
+
geometrycollection
|
108
|
+
point
|
109
|
+
linestring
|
110
|
+
polygon
|
111
|
+
multipoint
|
112
|
+
multilinestring
|
113
|
+
multipolygon
|
114
|
+
].each do |geo_type|
|
115
|
+
m.register_type(geo_type) do |sql_type|
|
116
|
+
Type::Spatial.new(sql_type.to_s)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }
|
123
|
+
TYPE_MAP_WITH_BOOLEAN = Type::TypeMap.new(TYPE_MAP).tap do |m|
|
124
|
+
m.register_type %r(^tinyint\(1\))i, Type::Boolean.new
|
125
|
+
end
|
126
|
+
|
71
127
|
def supports_spatial?
|
72
128
|
!mariadb? && version >= "5.7.6"
|
73
129
|
end
|
@@ -80,6 +136,11 @@ module ActiveRecord
|
|
80
136
|
super
|
81
137
|
end
|
82
138
|
end
|
139
|
+
|
140
|
+
private
|
141
|
+
def type_map
|
142
|
+
emulate_booleans ? TYPE_MAP_WITH_BOOLEAN : TYPE_MAP
|
143
|
+
end
|
83
144
|
end
|
84
145
|
end
|
85
146
|
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: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yongdae Hwang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.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: 7.0.0
|
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: 7.0.0
|
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: 7.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12.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: '12.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- LICENSE.txt
|
106
106
|
- lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb
|
107
107
|
- lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb
|
108
|
-
- lib/active_record/connection_adapters/mysql2rgeo/create_connection.rb
|
109
108
|
- lib/active_record/connection_adapters/mysql2rgeo/schema_creation.rb
|
110
109
|
- lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb
|
111
110
|
- lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb
|
@@ -120,7 +119,7 @@ homepage: http://github.com/stadia/activerecord-mysql2rgeo-adapter
|
|
120
119
|
licenses:
|
121
120
|
- BSD-3-Clause
|
122
121
|
metadata: {}
|
123
|
-
post_install_message:
|
122
|
+
post_install_message:
|
124
123
|
rdoc_options: []
|
125
124
|
require_paths:
|
126
125
|
- lib
|
@@ -128,16 +127,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
127
|
requirements:
|
129
128
|
- - ">="
|
130
129
|
- !ruby/object:Gem::Version
|
131
|
-
version: 2.
|
130
|
+
version: 2.7.0
|
132
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
132
|
requirements:
|
134
133
|
- - ">="
|
135
134
|
- !ruby/object:Gem::Version
|
136
135
|
version: '0'
|
137
136
|
requirements: []
|
138
|
-
|
139
|
-
|
140
|
-
signing_key:
|
137
|
+
rubygems_version: 3.2.33
|
138
|
+
signing_key:
|
141
139
|
specification_version: 4
|
142
140
|
summary: ActiveRecord adapter for MySQL, based on RGeo.
|
143
141
|
test_files: []
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if RUBY_ENGINE == "jruby"
|
4
|
-
require "active_record/connection_adapters/jdbcmysql_adapter"
|
5
|
-
else
|
6
|
-
require "mysql2"
|
7
|
-
end
|
8
|
-
|
9
|
-
module ActiveRecord # :nodoc:
|
10
|
-
module ConnectionHandling # :nodoc:
|
11
|
-
if RUBY_ENGINE == "jruby"
|
12
|
-
|
13
|
-
def jdbcmysql2rgeo_connection(config)
|
14
|
-
config[:adapter_class] = ConnectionAdapters::Mysql2RgeoAdapter
|
15
|
-
mysql2_connection(config)
|
16
|
-
end
|
17
|
-
|
18
|
-
alias jdbcmysql2rgeo_connection mysql2rgeo_connection
|
19
|
-
|
20
|
-
else
|
21
|
-
|
22
|
-
# Based on the default <tt>mysql2_connection</tt> definition from ActiveRecord.
|
23
|
-
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
|
24
|
-
# FULL REPLACEMENT because we need to create a different class.
|
25
|
-
|
26
|
-
def mysql2rgeo_connection(config)
|
27
|
-
config = config.symbolize_keys
|
28
|
-
|
29
|
-
config[:username] = "root" if config[:username].nil?
|
30
|
-
config[:flags] ||= 0
|
31
|
-
|
32
|
-
if Mysql2::Client.const_defined? :FOUND_ROWS
|
33
|
-
if config[:flags].is_a? Array
|
34
|
-
config[:flags].push "FOUND_ROWS"
|
35
|
-
else
|
36
|
-
config[:flags] |= Mysql2::Client::FOUND_ROWS
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
client = Mysql2::Client.new(config)
|
41
|
-
ConnectionAdapters::Mysql2RgeoAdapter.new(client, logger, nil, config)
|
42
|
-
rescue Mysql2::Error => e
|
43
|
-
if e.message.include?("Unknown database")
|
44
|
-
raise ActiveRecord::NoDatabaseError
|
45
|
-
else
|
46
|
-
raise
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|