Module: Imparcial::Driver::AbstractExpression::Column
- Included in:
- Imparcial::Driver::AbstractExpression
- Defined in:
- lib/imparcial/driver/abstract/expression/column.rb
Instance Method Summary collapse
-
#add_columns(options = {}) ⇒ Object
Description Add some columns without dropping any table.
-
#drop_columns(options = {}) ⇒ Object
Description Drop some columns.
-
#get_column_information(options = {}) ⇒ Object
Description Get name,type and size from a column in a given table.
-
#get_columns_information(options = {}) ⇒ Object
Description Get name,type and size from every column in a given table.
-
#modify_columns(options = {}) ⇒ Object
Description Modify column type and size if needed.
-
#rename_column(options = {}) ⇒ Object
Description Rename a column.
-
#rename_columns(options = {}) ⇒ Object
Description Rename a bunch of columns.
Instance Method Details
#add_columns(options = {}) ⇒ Object
Description
Add some columns without dropping any table.
Usage
abstract_adapter.add_columns :table_name => ‘person’, :fields => [{:name => :age, :type => :integer]
Options
-
:table_name
-
:fields
Returning
nothing
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 81 def add_columns ( = {} ) , sql = sql_for_adding_columns( ) logger.warn sql if @column_logging query sql rescue adapter_specific_exception => ex raise ColumnCreateError.new(ex.) end |
#drop_columns(options = {}) ⇒ Object
Description
Drop some columns.
Usage
abstract_adapter.drop_columns :table_name => ‘person’, :fields => [‘id’,‘name’]
Options
-
:table_name
-
:fields
Returning
nothing
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 35 def drop_columns ( = {} ) , sql = sql_for_dropping_columns( ) logger.warn sql if @column_logging query sql rescue adapter_specific_exception => ex raise ColumnDropError.new(ex.) end |
#get_column_information(options = {}) ⇒ Object
Description
Get name,type and size from a column in a given table. See :get_columns_information
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 170 def get_column_information ( = {} ) , sql = sql_for_getting_column_information logger.warn sql if @column_logging query sql name, type, size = result.fetch_first_row column_to_field :name => name.value, :type => type.value, :size => size.value end |
#get_columns_information(options = {}) ⇒ Object
Description
Get name,type and size from every column in a given table.
Usage
abstract_adapter.get_columns_information :table_name => ‘person’
Options
-
:table_name
Returning
an array with hashes.
-
:name
-
:type
-
:size
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 128 def get_columns_information ( = {} ) , sql = sql_for_getting_columns_information( ) logger.warn sql if @column_logging query sql fields = [] result.fetch do |name, type, size| field = column_to_field :name => name.value, :type => type.value, :size => size.value fields << field end fields rescue adapter_specific_exception => ex raise ColumnListError.new(ex.) end |
#modify_columns(options = {}) ⇒ Object
Description
Modify column type and size if needed.
Usage
abstract_adapter.modify_columns :table_name => ‘person’, :fields => [=> :id, :type => :float]
Options
-
:table_name
-
:fields
Returning
nothing
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 294 def modify_columns ( = {} ) , sql = ( ) logger.warn sql if @column_logging query sql rescue adapter_specific_exception => ex raise ColumnUpdateError.new(ex.) end |
#rename_column(options = {}) ⇒ Object
Description
Rename a column.
Usage
abstract_adapter.rename_column :table_name => ‘person’, :field => => :super_id
Options
-
:table_name
-
:fields
Returning
nothing
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 215 def rename_column ( = {} ) , sql = sql_for_renaming_column( ) logger.warn sql if @column_logging query sql rescue adapter_specific_exception => ex raise ColumnRenameError.new(ex.) end |
#rename_columns(options = {}) ⇒ Object
Description
Rename a bunch of columns. See :rename_column for further info.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/imparcial/driver/abstract/expression/column.rb', line 244 def rename_columns ( = {} ) , [:fields].each do |old_field,new_field| sql = sql_for_renaming_column( :table_name => [:table_name], :field => {old_field => new_field}) logger.warn sql if @column_logging query sql end rescue adapter_specific_exception => ex raise ColumnRenameError.new(ex.) end |