Module: Sequel::Postgres::Schemata::DatabaseMethods
- Included in:
- DatabaseMethods
- Defined in:
- lib/sequel/postgres/schemata.rb
Instance Method Summary collapse
-
#current_schemata ⇒ Object
Returns the current schemata, as returned by current_schemas(false).
-
#rename_schema(from, to) ⇒ Object
Renames a schema.
-
#schemata ⇒ Object
List all existing schematas (including the system ones).
-
#search_path ⇒ Object
Returns a symbol list containing the current search path.
-
#search_path=(search_path) ⇒ Object
Sets the search path.
Instance Method Details
#current_schemata ⇒ Object
Returns the current schemata, as returned by current_schemas(false).
43 44 45 46 47 |
# File 'lib/sequel/postgres/schemata.rb', line 43 def current_schemata extension :pg_array .select(Sequel::function(:current_schemas, false). cast('varchar[]')).single_value.map(&:to_sym) end |
#rename_schema(from, to) ⇒ Object
Renames a schema
50 51 52 |
# File 'lib/sequel/postgres/schemata.rb', line 50 def rename_schema from, to self << RENAME_SCHEMA_SQL % [from.to_s.gsub('"', '""'), to.to_s.gsub('"', '""')] end |
#schemata ⇒ Object
List all existing schematas (including the system ones). Returns a symbol list.
12 13 14 |
# File 'lib/sequel/postgres/schemata.rb', line 12 def schemata .select(:nspname).from(:pg_namespace).map(:nspname).map(&:to_sym) end |
#search_path ⇒ Object
Returns a symbol list containing the current search path. Note that the search path can contain non-existent schematas.
18 19 20 21 22 |
# File 'lib/sequel/postgres/schemata.rb', line 18 def search_path .with_sql(SHOW_SEARCH_PATH). single_value.scan(SCHEMA_SCAN_RE).flatten. map{|s|s.sub(SCHEMA_SUB_RE, '\1').gsub('""', '"').to_sym} end |
#search_path=(search_path) ⇒ Object
Sets the search path. Starting with Postgres 9.2 it can contain non-existent schematas. Accepted formats include a single symbol, a single string (passed to the server verbatim) and lists of symbols or strings.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sequel/postgres/schemata.rb', line 28 def search_path= search_path case search_path when String search_path = search_path.split(",").map{|s| s.strip} when Symbol search_path = [search_path] when Array # nil else raise Error, "unrecognized value for search_path: #{search_path.inspect}" end self << "SET search_path = #{search_path.map{|s| "\"#{s.to_s.gsub('"', '""')}\""}.join(',')}" end |