Module: Sequel::SearchPath

Defined in:
lib/sequel/extensions/search_path.rb,
lib/sequel/extensions/search_path/version.rb

Constant Summary collapse

VERSION =
'0.3.1'

Instance Method Summary collapse

Instance Method Details

#active_schemaObject

The schema that new objects will be created in.



44
45
46
# File 'lib/sequel/extensions/search_path.rb', line 44

def active_schema
  schemas.first
end

#freezeObject



53
54
55
56
# File 'lib/sequel/extensions/search_path.rb', line 53

def freeze
  schemas_key
  super
end

#override_schema(*new_schemas, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# 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

#schemasObject



24
25
26
# File 'lib/sequel/extensions/search_path.rb', line 24

def schemas
  Thread.current[schemas_key] ||= parse_search_path
end

#schemas=(new_schemas) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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_pathObject Also known as: show_search_path



48
49
50
# File 'lib/sequel/extensions/search_path.rb', line 48

def search_path
  self["SHOW search_path"].get
end

#use_schema(*new_schemas, &block) ⇒ Object



7
8
9
# File 'lib/sequel/extensions/search_path.rb', line 7

def use_schema(*new_schemas, &block)
  synchronize { override_schema(*(new_schemas + schemas), &block) }
end