Class: Peegee::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/peegee/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  self.table_name             = options[:table_name]
  self.columns_or_expressions = options.key?(:column) ? [[:column, options[:column], []]] : []
  self.options                = options[:options]
end

Instance Attribute Details

#columns_or_expressionsObject

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

Parameters:

  • value

    the value to set the attribute index_name to.



4
5
6
# File 'lib/peegee/index.rb', line 4

def index_name=(value)
  @index_name = value
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/peegee/index.rb', line 4

def options
  @options
end

#table_nameObject

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

Parameters:

  • value

    the value to set the attribute uniqueness to.



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_sqlObject



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 #{options[: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

Returns:

  • (Boolean)


36
37
38
# File 'lib/peegee/index.rb', line 36

def run_outside_transaction?
  options[:concurrently]
end