activerecord-postgis-adapter 8.0.0 → 11.0.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 +4 -4
- data/lib/active_record/connection_adapters/postgis/column_methods.rb +6 -0
- data/lib/active_record/connection_adapters/postgis/oid/date_time.rb +20 -0
- data/lib/active_record/connection_adapters/postgis/oid/spatial.rb +4 -1
- data/lib/active_record/connection_adapters/postgis/quoting.rb +18 -0
- data/lib/active_record/connection_adapters/postgis/schema_statements.rb +14 -47
- data/lib/active_record/connection_adapters/postgis/spatial_column.rb +2 -2
- data/lib/active_record/connection_adapters/postgis/spatial_table_definition.rb +12 -6
- data/lib/active_record/connection_adapters/postgis/version.rb +1 -1
- data/lib/active_record/connection_adapters/postgis_adapter.rb +32 -33
- data/lib/activerecord-postgis-adapter.rb +5 -1
- metadata +44 -14
- data/lib/active_record/connection_adapters/postgis/create_connection.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 211dbd4d62d434508e3f25601d469c70c5fcb4ffa5e75b5a1a197577df4b34cf
|
4
|
+
data.tar.gz: bb37b037a9acd972649f8ebdc47b9d041a8623ddf25d04cfa98c50c5f81fa2d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7b2327ef909bf8917b38b829c6e8d6eea280ff552aa2926ec546f932dfd9eb0774ba79298fa8c72b5c43d67c7f1fb321d4006d986067ec9eb3299257eb9c578
|
7
|
+
data.tar.gz: 68df2184e5dc4e8dcc975dfa94e12a7b71ce6677a7d5462799e76c53c1737927e6c68f026eacc6aca54199df2b786b1aa97df2a45dfc68d7de540a879771bf72
|
@@ -4,6 +4,7 @@ module ActiveRecord
|
|
4
4
|
module ConnectionAdapters
|
5
5
|
module PostGIS
|
6
6
|
module ColumnMethods
|
7
|
+
|
7
8
|
def spatial(name, options = {})
|
8
9
|
raise "You must set a type. For example: 't.spatial type: :st_point'" unless options[:type]
|
9
10
|
column(name, options[:type], **options)
|
@@ -44,6 +45,11 @@ module ActiveRecord
|
|
44
45
|
def st_polygon(name, options = {})
|
45
46
|
column(name, :st_polygon, **options)
|
46
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def valid_column_definition_options
|
51
|
+
super + [:srid, :has_z, :has_m, :geographic, :spatial_type]
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module PostGIS
|
6
|
+
module OID
|
7
|
+
module DateTime
|
8
|
+
protected
|
9
|
+
|
10
|
+
# Uses PostGIS instead of PostgreSQLAdapter
|
11
|
+
def real_type_unless_aliased(real_type)
|
12
|
+
ActiveRecord::ConnectionAdapters::PostGISAdapter.datetime_type == real_type ? :datetime : real_type
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
PostgreSQL::OID::DateTime.prepend(DateTime)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -25,7 +25,10 @@ module ActiveRecord
|
|
25
25
|
# has_z: false
|
26
26
|
# has_m: false
|
27
27
|
def self.parse_sql_type(sql_type)
|
28
|
-
geo_type
|
28
|
+
geo_type = nil
|
29
|
+
srid = 0
|
30
|
+
has_z = false
|
31
|
+
has_m = false
|
29
32
|
|
30
33
|
if sql_type =~ /(geography|geometry)\((.*)\)$/i
|
31
34
|
# geometry(Point)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module PostGIS
|
6
|
+
module Quoting
|
7
|
+
def type_cast(value)
|
8
|
+
case value
|
9
|
+
when RGeo::Feature::Instance
|
10
|
+
value.to_s
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -5,18 +5,22 @@ module ActiveRecord
|
|
5
5
|
module PostGIS
|
6
6
|
module SchemaStatements
|
7
7
|
# override
|
8
|
-
# https://github.com/rails/rails/blob/
|
8
|
+
# https://github.com/rails/rails/blob/7-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L662
|
9
9
|
# Create a SpatialColumn instead of a PostgreSQL::Column
|
10
|
-
def new_column_from_field(table_name, field)
|
11
|
-
column_name, type, default, notnull, oid, fmod, collation, comment = field
|
10
|
+
def new_column_from_field(table_name, field, _definitions)
|
11
|
+
column_name, type, default, notnull, oid, fmod, collation, comment, identity, attgenerated = field
|
12
12
|
type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
|
13
13
|
default_value = extract_value_from_default(default)
|
14
|
-
default_function = extract_default_function(default_value, default)
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
if attgenerated.present?
|
16
|
+
default_function = default
|
17
|
+
else
|
18
|
+
default_function = extract_default_function(default_value, default)
|
19
|
+
end
|
20
|
+
|
21
|
+
if (match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/))
|
22
|
+
serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
|
23
|
+
end
|
20
24
|
|
21
25
|
# {:dimension=>2, :has_m=>false, :has_z=>false, :name=>"latlon", :srid=>0, :type=>"GEOMETRY"}
|
22
26
|
spatial = spatial_column_info(table_name).get(column_name, type_metadata.sql_type)
|
@@ -30,49 +34,12 @@ module ActiveRecord
|
|
30
34
|
collation: collation,
|
31
35
|
comment: comment.presence,
|
32
36
|
serial: serial,
|
37
|
+
generated: attgenerated,
|
38
|
+
identity: identity.presence,
|
33
39
|
spatial: spatial
|
34
40
|
)
|
35
41
|
end
|
36
42
|
|
37
|
-
# override
|
38
|
-
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L544
|
39
|
-
#
|
40
|
-
# returns Postgresql sql type string
|
41
|
-
# examples:
|
42
|
-
# "geometry(Point,4326)"
|
43
|
-
# "geography(Point,4326)"
|
44
|
-
#
|
45
|
-
# note: type alone is not enough to detect the sql type,
|
46
|
-
# so `limit` is used to pass the additional information. :(
|
47
|
-
#
|
48
|
-
# type_to_sql(:geography, limit: "Point,4326")
|
49
|
-
# => "geography(Point,4326)"
|
50
|
-
def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **)
|
51
|
-
case type.to_s
|
52
|
-
when "geometry", "geography"
|
53
|
-
"#{type}(#{limit})"
|
54
|
-
else
|
55
|
-
super
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# override
|
60
|
-
def native_database_types
|
61
|
-
# Add spatial types
|
62
|
-
super.merge(
|
63
|
-
geography: { name: "geography" },
|
64
|
-
geometry: { name: "geometry" },
|
65
|
-
geometry_collection: { name: "geometry_collection" },
|
66
|
-
line_string: { name: "line_string" },
|
67
|
-
multi_line_string: { name: "multi_line_string" },
|
68
|
-
multi_point: { name: "multi_point" },
|
69
|
-
multi_polygon: { name: "multi_polygon" },
|
70
|
-
spatial: { name: "geometry" },
|
71
|
-
st_point: { name: "st_point" },
|
72
|
-
st_polygon: { name: "st_polygon" }
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
43
|
# override
|
77
44
|
def create_table_definition(*args, **kwargs)
|
78
45
|
PostGIS::TableDefinition.new(self, *args, **kwargs)
|
@@ -9,7 +9,7 @@ module ActiveRecord # :nodoc:
|
|
9
9
|
# "Geography(Point,4326)"
|
10
10
|
def initialize(name, default, sql_type_metadata = nil, null = true,
|
11
11
|
default_function = nil, collation: nil, comment: nil,
|
12
|
-
serial: nil, spatial: nil)
|
12
|
+
serial: nil, generated: nil, spatial: nil, identity: nil)
|
13
13
|
@sql_type_metadata = sql_type_metadata
|
14
14
|
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
15
15
|
if spatial
|
@@ -31,7 +31,7 @@ module ActiveRecord # :nodoc:
|
|
31
31
|
build_from_sql_type(sql_type_metadata.sql_type)
|
32
32
|
end
|
33
33
|
super(name, default, sql_type_metadata, null, default_function,
|
34
|
-
collation: collation, comment: comment, serial: serial)
|
34
|
+
collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
|
35
35
|
if spatial? && @srid
|
36
36
|
@limit = { srid: @srid, type: to_type_name(geometric_type) }
|
37
37
|
@limit[:has_z] = true if @has_z
|
@@ -8,7 +8,13 @@ module ActiveRecord # :nodoc:
|
|
8
8
|
|
9
9
|
# super: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
|
10
10
|
def new_column_definition(name, type, **options)
|
11
|
-
|
11
|
+
col_type = if type.to_sym == :virtual
|
12
|
+
options[:type]
|
13
|
+
else
|
14
|
+
type
|
15
|
+
end
|
16
|
+
|
17
|
+
if (info = PostGISAdapter.spatial_column_options(col_type))
|
12
18
|
if (limit = options.delete(:limit)) && limit.is_a?(::Hash)
|
13
19
|
options.merge!(limit)
|
14
20
|
end
|
@@ -37,11 +43,11 @@ module ActiveRecord # :nodoc:
|
|
37
43
|
end
|
38
44
|
|
39
45
|
def limit_from_options(type, options = {})
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
has_z = options[:has_z] ? 'Z' : ''
|
47
|
+
has_m = options[:has_m] ? 'M' : ''
|
48
|
+
srid = options[:srid] || default_srid(options)
|
49
|
+
field_type = [geo_type(type), has_z, has_m].compact.join
|
50
|
+
"#{field_type},#{srid}"
|
45
51
|
end
|
46
52
|
|
47
53
|
def default_srid(options)
|
@@ -5,24 +5,23 @@
|
|
5
5
|
|
6
6
|
# :stopdoc:
|
7
7
|
|
8
|
-
require "rgeo/active_record"
|
9
|
-
|
10
|
-
require "active_record/connection_adapters"
|
11
8
|
require "active_record/connection_adapters/postgresql_adapter"
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
require_relative "postgis/version"
|
10
|
+
require_relative "postgis/column_methods"
|
11
|
+
require_relative "postgis/schema_statements"
|
12
|
+
require_relative "postgis/database_statements"
|
13
|
+
require_relative "postgis/spatial_column_info"
|
14
|
+
require_relative "postgis/spatial_table_definition"
|
15
|
+
require_relative "postgis/spatial_column"
|
16
|
+
require_relative "postgis/arel_tosql"
|
17
|
+
require_relative "postgis/oid/spatial"
|
18
|
+
require_relative "postgis/oid/date_time"
|
19
|
+
require_relative "postgis/quoting"
|
20
|
+
require_relative "postgis/type" # has to be after oid/*
|
23
21
|
# :startdoc:
|
24
22
|
|
25
23
|
module ActiveRecord
|
24
|
+
|
26
25
|
module ConnectionAdapters
|
27
26
|
class PostGISAdapter < PostgreSQLAdapter
|
28
27
|
ADAPTER_NAME = 'PostGIS'
|
@@ -44,6 +43,7 @@ module ActiveRecord
|
|
44
43
|
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
|
45
44
|
DEFAULT_SRID = 0
|
46
45
|
|
46
|
+
include PostGIS::Quoting
|
47
47
|
include PostGIS::SchemaStatements
|
48
48
|
include PostGIS::DatabaseStatements
|
49
49
|
|
@@ -90,6 +90,24 @@ module ActiveRecord
|
|
90
90
|
|
91
91
|
super
|
92
92
|
end
|
93
|
+
|
94
|
+
def native_database_types
|
95
|
+
@native_database_types ||= begin
|
96
|
+
default_types = PostgreSQLAdapter.native_database_types
|
97
|
+
default_types.merge({
|
98
|
+
geography: { name: "geography" },
|
99
|
+
geometry: { name: "geometry" },
|
100
|
+
geometry_collection: { name: "geometry_collection" },
|
101
|
+
line_string: { name: "line_string" },
|
102
|
+
multi_line_string: { name: "multi_line_string" },
|
103
|
+
multi_point: { name: "multi_point" },
|
104
|
+
multi_polygon: { name: "multi_polygon" },
|
105
|
+
spatial: { name: "geometry" },
|
106
|
+
st_point: { name: "st_point" },
|
107
|
+
st_polygon: { name: "st_polygon" }
|
108
|
+
})
|
109
|
+
end
|
110
|
+
end
|
93
111
|
end
|
94
112
|
|
95
113
|
def srs_database_columns
|
@@ -144,23 +162,4 @@ module ActiveRecord
|
|
144
162
|
spatial_ref_sys
|
145
163
|
topology
|
146
164
|
]
|
147
|
-
Tasks::DatabaseTasks.register_task(/postgis/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
|
148
|
-
end
|
149
|
-
|
150
|
-
# if using JRUBY, create ArJdbc::PostGIS module
|
151
|
-
# and prepend it to the PostgreSQL adapter since
|
152
|
-
# it is the default adapter_spec.
|
153
|
-
# see: https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/adapter.rb#27
|
154
|
-
if RUBY_ENGINE == "jruby"
|
155
|
-
module ArJdbc
|
156
|
-
module PostGIS
|
157
|
-
ADAPTER_NAME = 'PostGIS'
|
158
|
-
|
159
|
-
def adapter_name
|
160
|
-
ADAPTER_NAME
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
ArJdbc::PostgreSQL.prepend(ArJdbc::PostGIS)
|
166
165
|
end
|
@@ -1,3 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_record
|
3
|
+
require "active_record"
|
4
|
+
require "active_record/connection_adapters"
|
5
|
+
require "rgeo/active_record"
|
6
|
+
ActiveRecord::ConnectionAdapters.register("postgis", "ActiveRecord::ConnectionAdapters::PostGISAdapter", "active_record/connection_adapters/postgis_adapter")
|
7
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-postgis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 11.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 8.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 8.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rgeo-activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 8.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 8.0.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,26 +68,54 @@ dependencies:
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '5.4'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: minitest-excludes
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '2.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '2.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: benchmark-ips
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2.12'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.12'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '1.50'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1.50'
|
84
112
|
description: ActiveRecord connection adapter for PostGIS. It is based on the stock
|
85
113
|
PostgreSQL adapter, and adds built-in support for the spatial extensions provided
|
86
114
|
by PostGIS. It uses the RGeo library to represent spatial data in Ruby.
|
87
115
|
email:
|
88
|
-
- dazuma@gmail.com
|
89
|
-
- parhameter@gmail.com
|
90
116
|
- kfdoggett@gmail.com
|
117
|
+
- buonomo.ulysse@gmail.com
|
118
|
+
- terminale@gmail.com
|
91
119
|
executables: []
|
92
120
|
extensions: []
|
93
121
|
extra_rdoc_files: []
|
@@ -95,9 +123,10 @@ files:
|
|
95
123
|
- LICENSE.txt
|
96
124
|
- lib/active_record/connection_adapters/postgis/arel_tosql.rb
|
97
125
|
- lib/active_record/connection_adapters/postgis/column_methods.rb
|
98
|
-
- lib/active_record/connection_adapters/postgis/create_connection.rb
|
99
126
|
- lib/active_record/connection_adapters/postgis/database_statements.rb
|
127
|
+
- lib/active_record/connection_adapters/postgis/oid/date_time.rb
|
100
128
|
- lib/active_record/connection_adapters/postgis/oid/spatial.rb
|
129
|
+
- lib/active_record/connection_adapters/postgis/quoting.rb
|
101
130
|
- lib/active_record/connection_adapters/postgis/schema_statements.rb
|
102
131
|
- lib/active_record/connection_adapters/postgis/spatial_column.rb
|
103
132
|
- lib/active_record/connection_adapters/postgis/spatial_column_info.rb
|
@@ -110,6 +139,7 @@ homepage: http://github.com/rgeo/activerecord-postgis-adapter
|
|
110
139
|
licenses:
|
111
140
|
- BSD-3-Clause
|
112
141
|
metadata:
|
142
|
+
funding_uri: https://opencollective.com/rgeo
|
113
143
|
rubygems_mfa_required: 'true'
|
114
144
|
post_install_message:
|
115
145
|
rdoc_options: []
|
@@ -119,14 +149,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
149
|
requirements:
|
120
150
|
- - ">="
|
121
151
|
- !ruby/object:Gem::Version
|
122
|
-
version: 2.
|
152
|
+
version: 3.2.0
|
123
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
154
|
requirements:
|
125
155
|
- - ">="
|
126
156
|
- !ruby/object:Gem::Version
|
127
157
|
version: '0'
|
128
158
|
requirements: []
|
129
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.5.22
|
130
160
|
signing_key:
|
131
161
|
specification_version: 4
|
132
162
|
summary: ActiveRecord adapter for PostGIS, based on RGeo.
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if RUBY_ENGINE == "jruby"
|
4
|
-
require "active_record/connection_adapters/jdbcpostgresql_adapter"
|
5
|
-
else
|
6
|
-
require "pg"
|
7
|
-
end
|
8
|
-
|
9
|
-
module ActiveRecord # :nodoc:
|
10
|
-
module ConnectionHandling # :nodoc:
|
11
|
-
if RUBY_ENGINE == "jruby"
|
12
|
-
|
13
|
-
# modified from https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/postgresql/connection_methods.rb#L3
|
14
|
-
def postgis_connection(config)
|
15
|
-
config = config.deep_dup
|
16
|
-
config = symbolize_keys_if_necessary(config)
|
17
|
-
|
18
|
-
config[:adapter_class] = ConnectionAdapters::PostGISAdapter
|
19
|
-
postgresql_connection(config)
|
20
|
-
end
|
21
|
-
|
22
|
-
alias_method :jdbcpostgis_connection, :postgis_connection
|
23
|
-
|
24
|
-
else
|
25
|
-
|
26
|
-
# Based on the default <tt>postgresql_connection</tt> definition from ActiveRecord.
|
27
|
-
# https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
|
28
|
-
# FULL REPLACEMENT because we need to create a different class.
|
29
|
-
def postgis_connection(config)
|
30
|
-
conn_params = config.symbolize_keys.compact
|
31
|
-
|
32
|
-
# Map ActiveRecords param names to PGs.
|
33
|
-
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
34
|
-
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
35
|
-
|
36
|
-
# Forward only valid config params to PG.connect
|
37
|
-
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
|
38
|
-
conn_params.slice!(*valid_conn_param_keys)
|
39
|
-
|
40
|
-
ConnectionAdapters::PostGISAdapter.new(
|
41
|
-
ConnectionAdapters::PostGISAdapter.new_client(conn_params),
|
42
|
-
logger,
|
43
|
-
conn_params,
|
44
|
-
config
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|