module Sequel::SearchPath
Constants
- VERSION
Public Instance Methods
active_schema()
click to toggle source
The schema that new objects will be created in.
# File lib/sequel/extensions/search_path.rb, line 44 def active_schema schemas.first end
freeze()
click to toggle source
Calls superclass method
# File lib/sequel/extensions/search_path.rb, line 53 def freeze schemas_key super end
override_schema(*new_schemas) { || ... }
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 11 def override_schema(*new_schemas, &block) synchronize do previous_schemas = schemas begin self.schemas = new_schemas yield ensure self.schemas = previous_schemas end end end
schemas()
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 24 def schemas Thread.current[schemas_key] ||= parse_search_path end
schemas=(new_schemas)
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 28 def schemas=(new_schemas) new_schemas = new_schemas.map(&:to_sym).uniq return if schemas == new_schemas Thread.current[schemas_key] = new_schemas # Set the search_path in Postgres, unless it's in transaction rollback. # If it is, the search_path will be reset for us anyway, and the SQL # call will just raise another error. unless synchronize(&:transaction_status) == PG::PQTRANS_INERROR set_search_path(new_schemas) end end
search_path()
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 48 def search_path self["SHOW search_path"].get end
Also aliased as: show_search_path
use_schema(*new_schemas, &block)
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 7 def use_schema(*new_schemas, &block) synchronize { override_schema(*(new_schemas + schemas), &block) } end
Private Instance Methods
parse_search_path()
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 60 def parse_search_path search_path. split(/[\s,]+/). map{|s| s.gsub(/\A"|"\z/, '')}. reject{|s| s == '$user'}. map(&:to_sym) end
schemas_key()
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 74 def schemas_key @schemas_key ||= "sequel-search-path-#{object_id}".to_sym end
set_search_path(schemas)
click to toggle source
# File lib/sequel/extensions/search_path.rb, line 68 def set_search_path(schemas) placeholders = schemas.map{'?'}.join(', ') placeholders = "''" if placeholders.empty? self["SET search_path TO #{placeholders}", *schemas].get end