Module: Imparcial::Driver::AbstractExpression::Constraint

Included in:
Imparcial::Driver::AbstractExpression
Defined in:
lib/imparcial/driver/abstract/expression/constraint.rb

Instance Method Summary collapse

Instance Method Details

#add_auto_increment(options = {}) ⇒ Object

Description

Make a bunch of fields auto increment.

Usage

abstract_adapter.add_auto_increment :table_name => ‘person’, :fields => [‘id’,‘name’]

Options

  • :table_name

  • :fields

Returning

nothing



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/imparcial/driver/abstract/expression/constraint.rb', line 82

def add_auto_increment ( options = {} )
  
  check_options expected_options_for_adding_auto_increment, options

  add_primary_key :table_name => options[:table_name], :fields => [options[:field]]
  sql = sql_for_adding_auto_increment( options )          
  
  logger.warn sql if @column_logging
  
  query sql
  
rescue adapter_specific_exception => ex

  raise ColumnConstraintError.new(ex.message)
  
end

#add_default_value(options = {}) ⇒ Object

Description

Add default value for some fields.

Usage

abstract_adapter.add_default_value :table_name => ‘person’, :fields => => 1, :name => ‘jota’

Options

  • :table_name

  • :fields

Returning

nothing



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/imparcial/driver/abstract/expression/constraint.rb', line 129

def add_default_value ( options = {} )
  
  check_options expected_options_for_adding_default_value, options

  sql = sql_for_adding_default_value( options ) 
  
  logger.warn sql if @column_logging
  
  query sql
  
rescue adapter_specific_exception => ex

  raise ColumnConstraintError.new(ex.message)
  
end

#add_primary_key(options = {}) ⇒ Object

Description

Make a bunch of fields primary key.

Usage

abstract_adapter.primary_key :table_name => ‘person’, :fields => [‘id’,‘name’]

Options

  • :table_name

  • :fields

Returning

nothing



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/imparcial/driver/abstract/expression/constraint.rb', line 36

def add_primary_key ( options = {} )
  
  check_options expected_options_for_adding_primary_key, options

  sql = sql_for_adding_primary_key( options )
  
  logger.warn sql if @column_logging
  
  query sql
  
rescue adapter_specific_exception => ex

  raise ColumnConstraintError.new(ex.message)
  
end