Class: Peegee::Index
- Inherits:
-
Object
- Object
- Peegee::Index
- Defined in:
- lib/peegee/index.rb
Instance Attribute Summary collapse
-
#columns_or_expressions ⇒ Object
Returns the value of attribute columns_or_expressions.
-
#index_name ⇒ Object
writeonly
Sets the attribute index_name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
-
#uniqueness ⇒ Object
writeonly
Sets the attribute uniqueness.
Instance Method Summary collapse
- #column(name, *args) ⇒ Object
- #column=(column) ⇒ Object
- #create_sql ⇒ Object
- #expression(expr, *args) ⇒ Object
-
#initialize(options = {}) ⇒ Index
constructor
A new instance of Index.
- #run_outside_transaction? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Index
Returns a new instance of Index.
7 8 9 10 11 |
# File 'lib/peegee/index.rb', line 7 def initialize( = {}) self.table_name = [:table_name] self.columns_or_expressions = .key?(:column) ? [[:column, [:column], []]] : [] self. = [:options] end |
Instance Attribute Details
#columns_or_expressions ⇒ Object
Returns the value of attribute columns_or_expressions.
5 6 7 |
# File 'lib/peegee/index.rb', line 5 def columns_or_expressions @columns_or_expressions end |
#index_name=(value) ⇒ Object
Sets the attribute index_name
4 5 6 |
# File 'lib/peegee/index.rb', line 4 def index_name=(value) @index_name = value end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/peegee/index.rb', line 4 def @options end |
#table_name ⇒ Object
Returns the value of attribute table_name.
4 5 6 |
# File 'lib/peegee/index.rb', line 4 def table_name @table_name end |
#uniqueness=(value) ⇒ Object
Sets the attribute uniqueness
4 5 6 |
# File 'lib/peegee/index.rb', line 4 def uniqueness=(value) @uniqueness = value end |
Instance Method Details
#column(name, *args) ⇒ Object
24 25 26 |
# File 'lib/peegee/index.rb', line 24 def column(name, *args) columns_or_expressions << [:column, name, args] end |
#column=(column) ⇒ Object
32 33 34 |
# File 'lib/peegee/index.rb', line 32 def column=(column) columns_or_expressions << [:column, column, []] end |
#create_sql ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/peegee/index.rb', line 13 def create_sql check_index_name_length sql = "CREATE #{uniqueness} INDEX #{concurrentliness} #{adapter.quote_column_name(index_name)} ON #{adapter.quote_table_name(table_name)} (#{columns_or_expressions_sql}) #{tablespace_sql}" if @options.key?(:where) sql += " WHERE #{[:where]}" end sql end |
#expression(expr, *args) ⇒ Object
28 29 30 |
# File 'lib/peegee/index.rb', line 28 def expression(expr, *args) columns_or_expressions << [:expression, expr, args] end |
#run_outside_transaction? ⇒ Boolean
36 37 38 |
# File 'lib/peegee/index.rb', line 36 def run_outside_transaction? [:concurrently] end |