Module: Sequel::SearchPath
- Defined in:
- lib/sequel/extensions/search_path.rb,
lib/sequel/extensions/search_path/version.rb
Constant Summary collapse
- VERSION =
'0.0.1'.freeze
Instance Method Summary collapse
-
#active_schema ⇒ Object
The schema that new objects will be created in.
- #get_search_path ⇒ Object (also: #show_search_path)
- #override_schema(*new_schemas, &block) ⇒ Object
- #schemas ⇒ Object
- #schemas=(schemas) ⇒ Object
- #use_schema(*new_schemas, &block) ⇒ Object
Instance Method Details
#active_schema ⇒ Object
The schema that new objects will be created in.
43 44 45 |
# File 'lib/sequel/extensions/search_path.rb', line 43 def active_schema schemas.first end |
#get_search_path ⇒ Object Also known as: show_search_path
47 48 49 |
# File 'lib/sequel/extensions/search_path.rb', line 47 def get_search_path self["SHOW search_path"].get end |
#override_schema(*new_schemas, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sequel/extensions/search_path.rb', line 9 def override_schema(*new_schemas, &block) synchronize do previous_schemas = schemas.dup begin schemas.replace new_schemas.map(&:to_sym).uniq set_search_path yield ensure schemas.replace previous_schemas begin set_search_path rescue Sequel::DatabaseError # This command will fail if we're in a transaction that the DB # is rolling back due to an error, but in that case, there's no # need to run it anyway (Postgres will reset the search_path for # us). Since there's no way to know whether it will fail until # we try it, and there's nothing to be done with the error it # throws, just ignore it. end end end end |
#schemas ⇒ Object
34 35 36 |
# File 'lib/sequel/extensions/search_path.rb', line 34 def schemas Thread.current[schemas_key] ||= [:public] end |
#schemas=(schemas) ⇒ Object
38 39 40 |
# File 'lib/sequel/extensions/search_path.rb', line 38 def schemas=(schemas) Thread.current[schemas_key] = schemas end |
#use_schema(*new_schemas, &block) ⇒ Object
5 6 7 |
# File 'lib/sequel/extensions/search_path.rb', line 5 def use_schema(*new_schemas, &block) synchronize { override_schema(*(new_schemas + schemas), &block) } end |