sequel-search-path 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sequel/extensions/search_path/version.rb +1 -1
- data/lib/sequel/extensions/search_path.rb +20 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 085c3c7649911aa5244ccd0600b6e0a66cc4e992
|
4
|
+
data.tar.gz: 7f90504ae2b1660dabab063e35d78e44c8662e40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea1cfbbb79cf053cf739640e2c0fa3b9a96950045acd8e2743712a50e66b859031e6aef8611bc2db4ac245724eb8404e9123c425344caed590a8f15a83ea9aa5
|
7
|
+
data.tar.gz: 721703c73bf2560fa49fdc4e4cd30801cd8cfdf4e5a72a11c3200fa1fe0b6cd8f524599be20c5ec20e7d00d24d5d3648253d7e01d1cf567b00263d41c1b5bc8e
|
@@ -10,25 +10,13 @@ module Sequel
|
|
10
10
|
|
11
11
|
def override_schema(*new_schemas, &block)
|
12
12
|
synchronize do
|
13
|
-
previous_schemas = schemas
|
13
|
+
previous_schemas = schemas
|
14
14
|
|
15
15
|
begin
|
16
|
-
schemas
|
17
|
-
set_search_path
|
16
|
+
self.schemas = new_schemas
|
18
17
|
yield
|
19
18
|
ensure
|
20
|
-
schemas
|
21
|
-
|
22
|
-
begin
|
23
|
-
set_search_path
|
24
|
-
rescue Sequel::DatabaseError
|
25
|
-
# This command will fail if we're in a transaction that the DB
|
26
|
-
# is rolling back due to an error, but in that case, there's no
|
27
|
-
# need to run it anyway (Postgres will reset the search_path for
|
28
|
-
# us). Since there's no way to know whether it will fail until
|
29
|
-
# we try it, and there's nothing to be done with the error it
|
30
|
-
# throws, just ignore it.
|
31
|
-
end
|
19
|
+
self.schemas = previous_schemas
|
32
20
|
end
|
33
21
|
end
|
34
22
|
end
|
@@ -38,7 +26,9 @@ module Sequel
|
|
38
26
|
end
|
39
27
|
|
40
28
|
def schemas=(schemas)
|
29
|
+
schemas = schemas.map(&:to_sym).uniq
|
41
30
|
Thread.current[schemas_key] = schemas
|
31
|
+
set_search_path(schemas)
|
42
32
|
end
|
43
33
|
|
44
34
|
# The schema that new objects will be created in.
|
@@ -46,19 +36,29 @@ module Sequel
|
|
46
36
|
schemas.first
|
47
37
|
end
|
48
38
|
|
49
|
-
def
|
39
|
+
def search_path
|
50
40
|
self["SHOW search_path"].get
|
51
41
|
end
|
52
|
-
alias :show_search_path :
|
42
|
+
alias :show_search_path :search_path
|
43
|
+
|
44
|
+
private
|
53
45
|
|
54
|
-
def set_search_path
|
46
|
+
def set_search_path(schemas)
|
55
47
|
placeholders = schemas.map{'?'}.join(', ')
|
56
48
|
placeholders = "''" if placeholders.empty?
|
57
49
|
self["SET search_path TO #{placeholders}", *schemas].get
|
50
|
+
rescue Sequel::DatabaseError => e
|
51
|
+
if e.wrapped_exception.is_a?(PG::InFailedSqlTransaction)
|
52
|
+
# This command will fail if we're in a transaction that the DB is
|
53
|
+
# rolling back due to an error, but in that case, there's no need to run
|
54
|
+
# it anyway (Postgres will reset the search_path for us). Since there's
|
55
|
+
# no way to know whether it will fail until we try it, and there's
|
56
|
+
# nothing to be done with the error it throws, just ignore it.
|
57
|
+
else
|
58
|
+
raise
|
59
|
+
end
|
58
60
|
end
|
59
61
|
|
60
|
-
private
|
61
|
-
|
62
62
|
def schemas_key
|
63
63
|
@schemas_key ||= "sequel-search-path-#{object_id}".to_sym
|
64
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-search-path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hanks
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|