imparcial 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +5 -0
  3. data/README.txt +48 -0
  4. data/Rakefile +51 -0
  5. data/lib/imparcial.rb +7 -0
  6. metadata +37 -81
  7. data/lib/imparcial/driver/abstract/expression/base.rb +0 -111
  8. data/lib/imparcial/driver/abstract/expression/column.rb +0 -313
  9. data/lib/imparcial/driver/abstract/expression/constraint.rb +0 -149
  10. data/lib/imparcial/driver/abstract/expression/delete.rb +0 -88
  11. data/lib/imparcial/driver/abstract/expression/index.rb +0 -206
  12. data/lib/imparcial/driver/abstract/expression/insert.rb +0 -49
  13. data/lib/imparcial/driver/abstract/expression/lock.rb +0 -11
  14. data/lib/imparcial/driver/abstract/expression/record.rb +0 -41
  15. data/lib/imparcial/driver/abstract/expression/select.rb +0 -38
  16. data/lib/imparcial/driver/abstract/expression/sequence.rb +0 -260
  17. data/lib/imparcial/driver/abstract/expression/statement.rb +0 -128
  18. data/lib/imparcial/driver/abstract/expression/table.rb +0 -416
  19. data/lib/imparcial/driver/abstract/expression/transaction.rb +0 -143
  20. data/lib/imparcial/driver/abstract/expression/update.rb +0 -50
  21. data/lib/imparcial/driver/abstract/expression.rb +0 -24
  22. data/lib/imparcial/driver/abstract/result.rb +0 -95
  23. data/lib/imparcial/driver/abstract/sql/column.rb +0 -103
  24. data/lib/imparcial/driver/abstract/sql/constraint.rb +0 -42
  25. data/lib/imparcial/driver/abstract/sql/delete.rb +0 -22
  26. data/lib/imparcial/driver/abstract/sql/index.rb +0 -45
  27. data/lib/imparcial/driver/abstract/sql/insert.rb +0 -63
  28. data/lib/imparcial/driver/abstract/sql/record.rb +0 -19
  29. data/lib/imparcial/driver/abstract/sql/select.rb +0 -101
  30. data/lib/imparcial/driver/abstract/sql/sequence.rb +0 -55
  31. data/lib/imparcial/driver/abstract/sql/table.rb +0 -42
  32. data/lib/imparcial/driver/abstract/sql/transaction.rb +0 -43
  33. data/lib/imparcial/driver/abstract/sql/update.rb +0 -29
  34. data/lib/imparcial/driver/abstract/sql.rb +0 -21
  35. data/lib/imparcial/driver/abstract/typemap.rb +0 -168
  36. data/lib/imparcial/driver/abstract/util.rb +0 -53
  37. data/lib/imparcial/driver/abstract.rb +0 -255
  38. data/lib/imparcial/driver/mysql/expression/table.rb +0 -17
  39. data/lib/imparcial/driver/mysql/expression.rb +0 -11
  40. data/lib/imparcial/driver/mysql/result.rb +0 -33
  41. data/lib/imparcial/driver/mysql/sql/column.rb +0 -59
  42. data/lib/imparcial/driver/mysql/sql/constraint.rb +0 -39
  43. data/lib/imparcial/driver/mysql/sql/index.rb +0 -42
  44. data/lib/imparcial/driver/mysql/sql/sequence.rb +0 -39
  45. data/lib/imparcial/driver/mysql/sql/table.rb +0 -67
  46. data/lib/imparcial/driver/mysql/sql.rb +0 -15
  47. data/lib/imparcial/driver/mysql/typemap.rb +0 -13
  48. data/lib/imparcial/driver/mysql/util.rb +0 -13
  49. data/lib/imparcial/driver/mysql.rb +0 -49
  50. data/lib/imparcial/driver/postgre/expression.rb +0 -32
  51. data/lib/imparcial/driver/postgre/result.rb +0 -35
  52. data/lib/imparcial/driver/postgre/sql/column.rb +0 -53
  53. data/lib/imparcial/driver/postgre/sql/constraint.rb +0 -37
  54. data/lib/imparcial/driver/postgre/sql/index.rb +0 -53
  55. data/lib/imparcial/driver/postgre/sql/sequence.rb +0 -30
  56. data/lib/imparcial/driver/postgre/sql/table.rb +0 -46
  57. data/lib/imparcial/driver/postgre/sql.rb +0 -15
  58. data/lib/imparcial/driver/postgre/typemap.rb +0 -29
  59. data/lib/imparcial/driver/postgre/util.rb +0 -19
  60. data/lib/imparcial/driver/postgre.rb +0 -43
  61. data/lib/imparcial/driver.rb +0 -1
  62. data/lib/imparcial/exception.rb +0 -71
  63. data/lib/imparcial/initializer.rb +0 -62
@@ -1,416 +0,0 @@
1
- module Imparcial
2
- module Driver
3
- module AbstractExpression
4
- module Table
5
-
6
- ###########################################
7
- # #
8
- # Dropping Table #
9
- # #
10
- ###########################################
11
-
12
- private
13
-
14
- def expected_options_for_dropping_table
15
-
16
- {:table_name => :required}
17
-
18
- end
19
-
20
- public
21
-
22
- # === Description
23
- # Drop a table raising an exception if necessary.
24
- #
25
- # === Usage
26
- # abstract_adapter.drop_table :table_name => 'person'
27
- #
28
- # === Options
29
- # :table_name
30
- #
31
- # === Returning
32
- # nothing
33
-
34
- def drop_table ( options = {} )
35
-
36
- check_options expected_options_for_dropping_table, options
37
-
38
- sql = sql_for_dropping_table( options )
39
-
40
- logger.warn sql if @table_logging
41
-
42
- query sql
43
-
44
- rescue adapter_specific_exception => ex
45
-
46
- raise TableDropError.new(ex.message)
47
-
48
- end
49
-
50
- # === Description
51
- # Drop a table by not raising any exception.
52
- #
53
- # === Usage
54
- # abstract_adapter.drop_table_if_necessary :table_name => 'person'
55
- #
56
- # === Option
57
- # :table_name
58
- #
59
- # === Returning
60
- # nothing
61
-
62
- def drop_table_if_necessary ( options = {} )
63
-
64
- drop_table options
65
-
66
- rescue TableDropError; end
67
-
68
- # === Description
69
- # Drop all tables raising an exception if necessary.
70
- #
71
- # === Usage
72
- # abstract_adapter.drop_all_tables
73
- #
74
- # === Option
75
- # No option
76
- #
77
- # === Returning
78
- # nothing
79
-
80
- def drop_all_tables
81
-
82
- for table_name in get_tables
83
-
84
- sql = sql_for_dropping_table( {:table_name => table_name} )
85
-
86
- logger.warn sql if @table_logging
87
-
88
- query sql
89
-
90
- end
91
-
92
- rescue adapter_specific_exception => ex
93
-
94
- raise TableDropError.new(ex.message)
95
-
96
- end
97
-
98
- ###########################################
99
- # #
100
- # Creating Table #
101
- # #
102
- ###########################################
103
-
104
- private
105
-
106
- def expected_options_for_creating_table
107
-
108
- {:table_name => :required, :fields => :required}
109
-
110
- end
111
-
112
- public
113
-
114
- # === Description
115
- # Create a table.
116
- #
117
- # === Usage
118
- # abstract_adapter.create_table :table_name => 'person', :fields =>
119
- # [{:name => 'id', :type => :integer},{:name => 'name', :type => :string}]
120
- #
121
- # === Option
122
- # * :table_name
123
- # * :fields = Having an array of hashes with information about columns.
124
- #
125
- # === Returning
126
- # nothing
127
- #
128
- # === Note
129
- # Some databases do override this method by adding up more options.
130
- # Please, check out the adapter specific's one.
131
-
132
- def create_table ( options = {} )
133
-
134
- check_options expected_options_for_creating_table, options
135
-
136
- sql = sql_for_creating_table( options )
137
-
138
- logger.warn sql if @table_logging
139
-
140
- query sql
141
-
142
- rescue adapter_specific_exception => ex
143
-
144
- raise TableCreateError.new(ex.message)
145
-
146
- end
147
-
148
- ###########################################
149
- # #
150
- # Table Listing #
151
- # #
152
- ###########################################
153
-
154
- private
155
-
156
- def expected_options_for_verifying_table_existence
157
-
158
- {:table_name => :required}
159
-
160
- end
161
-
162
- public
163
-
164
- # === Description
165
- # Check if a given table exists.
166
- #
167
- # === Usage
168
- # abstract_adapter.table_exists?(:table_name => 'person')
169
- #
170
- # === Option
171
- # No options
172
- #
173
- # === Returning
174
- # true or false
175
-
176
- def table_exists? ( options = {} )
177
-
178
- check_options expected_options_for_verifying_table_existence, options
179
-
180
- tables = get_tables
181
-
182
- tables.each do |name|
183
-
184
- return true if name == options[:table_name]
185
-
186
- end
187
-
188
- return false
189
-
190
- end
191
-
192
- def table_not_exists? ( options = {} )
193
-
194
- not table_exists? options
195
-
196
- end
197
-
198
- # === Description
199
- # Return all tables avaliable in the current schema by name.
200
- #
201
- # === Usage
202
- # abstract_adapter.get_tables
203
- #
204
- # === Option
205
- # No options
206
- #
207
- # === Returning
208
- # an array ['person','invoice',...]
209
-
210
- def get_tables
211
-
212
- sql = sql_for_getting_tables
213
-
214
- logger.warn sql if @table_logging
215
-
216
- query sql
217
-
218
- tables = []
219
-
220
- result.fetch do |table_name_column|
221
-
222
- tables << table_name_column.value
223
-
224
- end
225
-
226
- tables
227
-
228
- rescue adapter_specific_exception => ex
229
-
230
- raise TableRetrieveError.new(ex.message)
231
-
232
- end
233
-
234
- ###########################################
235
- # #
236
- # Table Diffing #
237
- # #
238
- ###########################################
239
-
240
- private
241
-
242
- def expected_options_for_reporting_tables
243
-
244
- {:table_name => :required, :fields => :required}
245
-
246
- end
247
-
248
- public
249
-
250
- def diff_columns ( options = {} )
251
-
252
- modified = report_modified_columns options
253
- new = report_new_columns options
254
- old = report_old_columns options
255
-
256
- [modified, new, old]
257
-
258
- end
259
-
260
- # === Description
261
- # Execute a diff by comparing incoming fields with existent ones.
262
- #
263
- # === Usage
264
- # abstract_adapter.report_modified_columns :table_name => 'person',
265
- # :fields => [{:name => :id, :type => :bigint}]
266
- #
267
- # === Option
268
- # * :table_name
269
- # * :fields => array of hashes
270
- #
271
- # === Returning
272
- # fields affected
273
-
274
- def report_modified_columns ( options = {} )
275
-
276
- check_options expected_options_for_reporting_tables, options
277
-
278
- modified_fields = options[:fields]
279
-
280
- modified_columns = []
281
- current_fields = get_columns_information :table_name => options[:table_name]
282
-
283
- parse_fields modified_fields do |modified_field|
284
-
285
- current_fields.each do |current_field|
286
-
287
- if modified_field[:name] == current_field[:name]
288
-
289
- # We gotta check every attribute to see if a modification can occur.
290
-
291
- if modified_field[:type] != current_field[:type]||modified_field[:size]!=current_field[:size]
292
-
293
- modified_columns << current_field
294
-
295
- end
296
-
297
- end
298
-
299
- end
300
-
301
- end #end of parse_fields
302
-
303
- modified_columns
304
-
305
- end
306
-
307
- # === Description
308
- # Execute a diff by comparing incoming fields with existent ones.
309
- #
310
- # === Usage
311
- # abstract_adapter.report_new_columns :table_name => 'person',
312
- # :fields => [{:name => :new_id, :type => :int}]
313
- #
314
- # === Option
315
- # * :table_name
316
- # * :fields => array of hashes
317
- #
318
- # === Returning
319
- # fields affected
320
-
321
- def report_new_columns ( options = {} )
322
-
323
- check_options expected_options_for_reporting_tables, options
324
-
325
- new_fields = options[:fields]
326
-
327
- new_columns = []
328
- no_new_field = false
329
-
330
- current_fields = get_columns_information :table_name => options[:table_name]
331
-
332
- parse_fields new_fields do |new_field|
333
-
334
- current_fields.each do |current_field|
335
-
336
- if new_field[:name] == current_field[:name]
337
-
338
- no_new_field = true
339
- break
340
-
341
- end
342
-
343
- end
344
-
345
- if no_new_field
346
-
347
- no_new_field = false
348
- next
349
-
350
- end
351
-
352
- new_columns << new_field
353
-
354
- end
355
-
356
- new_columns
357
-
358
- end
359
-
360
- # === Description
361
- # Execute a diff by comparing incoming fields with existent ones.
362
- #
363
- # === Usage
364
- # abstract_adapter.report_old_columns :table_name => 'person',
365
- # :fields => [{:name => :new_id, :type => :int}]
366
- #
367
- # === Option
368
- # * :table_name
369
- # * :fields => array of hashes
370
- #
371
- # === Returning
372
- # fields affected
373
-
374
- def report_old_columns ( options = {} )
375
-
376
- check_options expected_options_for_reporting_tables, options
377
-
378
- new_fields = options[:fields]
379
-
380
- legacy_fields = []
381
- no_old_field = false
382
-
383
- current_fields = get_columns_information :table_name => options[:table_name]
384
-
385
- current_fields.each do |current_field|
386
-
387
- parse_fields new_fields do |new_field|
388
-
389
- if new_field[:name] == current_field[:name]
390
-
391
- no_old_field = true
392
- break
393
-
394
- end
395
-
396
- if no_old_field == true
397
-
398
- no_old_field = false
399
- next
400
-
401
- end
402
-
403
- legacy_fields << current_field
404
-
405
- end #end of parse_fields
406
-
407
- end
408
-
409
- legacy_fields
410
-
411
- end
412
-
413
- end
414
- end
415
- end
416
- end
@@ -1,143 +0,0 @@
1
- module Imparcial
2
- module Driver
3
- module AbstractExpression
4
- module Transaction
5
-
6
- private
7
-
8
- def expected_options_for_saving_point
9
-
10
- {:savepoint_name => :required}
11
-
12
- end
13
-
14
- public
15
-
16
- # === Description
17
- # Stablish a savepoint in a given moment during transactions.
18
- #
19
- # === Usage
20
- # abstract_adapter.create_savepoint :savepoint_name => 'here'
21
- #
22
- # === Options
23
- # * :savepoint_name
24
- #
25
- # === Returning
26
- # nothing
27
-
28
- def create_savepoint ( options = {} )
29
-
30
- check_options expected_options_for_saving_point, options
31
-
32
- query sql_for_saving_point( options )
33
-
34
- rescue adapter_specific_exception => ex
35
-
36
- raise TransactionError.new(ex.message)
37
-
38
- end
39
-
40
- private
41
-
42
- def expected_options_for_restoring_point
43
-
44
- {:savepoint_name => :required}
45
-
46
- end
47
-
48
- public
49
-
50
- # === Description
51
- # Rollback to a given savepoint.
52
- #
53
- # === Usage
54
- # abstract_adapter.restore_savepoint :savepoint_name => 'here'
55
- #
56
- # === Options
57
- # * :savepoint_name
58
- #
59
- # === Returning
60
- # nothing
61
-
62
- def restore_savepoint ( options = {} )
63
-
64
- check_options expected_options_for_restoring_point, options
65
-
66
- query sql_for_rolling_back( options )
67
-
68
- rescue adapter_specific_exception => ex
69
-
70
- raise TransactionError.new(ex.message)
71
-
72
- end
73
-
74
- # === Description
75
- # Initiate a transaction.
76
- #
77
- # === Usage
78
- # abstract_adapter.initialize_transaction
79
- #
80
- # === Options
81
- # no options
82
- #
83
- # === Returning
84
- # nothing
85
-
86
- def initialize_transaction
87
-
88
- query sql_for_initializing_a_transaction
89
-
90
- rescue adapter_specific_exception => ex
91
-
92
- raise TransactionError.new(ex.message)
93
-
94
- end
95
-
96
- # === Description
97
- # Terminate a transaction by commiting.
98
- #
99
- # === Usage
100
- # abstract_adapter.terminate_transaction
101
- #
102
- # === Options
103
- # no options
104
- #
105
- # === Returning
106
- # nothing
107
-
108
- def terminate_transaction
109
-
110
- query sql_for_terminating_a_transaction
111
-
112
- rescue adapter_specific_exception => ex
113
-
114
- raise TransactionError.new(ex.message)
115
-
116
- end
117
-
118
- # === Description
119
- # Rollback a transaction.
120
- #
121
- # === Usage
122
- # abstract_adapter.rollback_transaction
123
- #
124
- # === Options
125
- # no options
126
- #
127
- # === Returning
128
- # nothing
129
-
130
- def rollback_transaction
131
-
132
- query sql_for_rolling_back
133
-
134
- rescue adapter_specific_exception => ex
135
-
136
- raise TransactionError.new(ex.message)
137
-
138
- end
139
-
140
- end
141
- end
142
- end
143
- end
@@ -1,50 +0,0 @@
1
- module Imparcial
2
- module Driver
3
- module AbstractExpression
4
- module Update
5
-
6
- private
7
-
8
- def expected_options_for_updating
9
-
10
- {:table_name => :required, :values => :required, :conditions => :required}
11
-
12
- end
13
-
14
- public
15
-
16
- # === Description
17
- # Update some records.
18
- #
19
- # === Usage
20
- # abstract_adapter.update :table_name => 'person', :values => {:salary => 1500},
21
- # :conditions => ['id = ?',10]
22
- #
23
- # === Options
24
- # * :table_name
25
- # * :values
26
- # * :conditions
27
- #
28
- # === Returning
29
- # nothing
30
-
31
- def update ( options )
32
-
33
- check_options expected_options_for_updating, options
34
-
35
- sql = sql_for_updating( options )
36
-
37
- logger.warn sql if @update_logging
38
-
39
- query sql
40
-
41
- rescue adapter_specific_exception => ex
42
-
43
- raise UpdateError.new(ex.message)
44
-
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,24 +0,0 @@
1
- FileList[File.dirname(__FILE__) + '/expression/*.rb'].each do |f|
2
- require f
3
- end
4
-
5
- module Imparcial
6
- module Driver
7
- module AbstractExpression
8
- include Base
9
- include Statement
10
- include Sequence
11
- include Column
12
- include Table
13
- include Constraint
14
- include Insert
15
- include Select
16
- include Delete
17
- include Update
18
- include Record
19
- include Lock
20
- include Transaction
21
- include Index
22
- end
23
- end
24
- end
@@ -1,95 +0,0 @@
1
- module Imparcial
2
- module Driver
3
-
4
- # This class will serve as base for adapter specific result class.
5
-
6
- class AbstractResult
7
- attr_reader :specific
8
-
9
- def initialize ( result_specific )
10
-
11
- @specific = result_specific
12
-
13
- end
14
-
15
- # === Description
16
- # get number of rows avaliable.
17
-
18
- def rows
19
-
20
- raise FeatureNotFound
21
-
22
- end
23
-
24
- # === Description
25
- # fetch the result.
26
-
27
- def fetch
28
-
29
- raise FeatureNotFound
30
-
31
- end
32
-
33
- def fetch_in_array
34
-
35
- array = []
36
-
37
- fetch do |*rows|
38
-
39
- array << rows
40
-
41
- end
42
-
43
- array
44
-
45
- end
46
-
47
- # === Description
48
- # Fetch the first row. Ignoring others if avaliable.
49
-
50
- def fetch_first_row
51
-
52
- fetch do |*rows|
53
- return *rows
54
- end
55
-
56
- end
57
-
58
-
59
- end
60
-
61
- # This class wraps a regular row.
62
- # Usually, a row will only come with value.
63
- # Instead, we can also keep the column name. So that, this class
64
- # can keep track of column name and value.
65
- #
66
- # -------------------
67
- # id | name | price <- column name
68
- # 1 | apple | 0.99 <- column value
69
- # 2 | lemon | 1.99 <- column value
70
- # -------------------
71
-
72
- class Row
73
- include Imparcial::Driver::AbstractUtil
74
-
75
- attr_accessor :name, :value
76
- alias_method :column_name, :name
77
- alias_method :column_value, :value
78
-
79
- def initialize ( column_name, column_value )
80
-
81
- @name = column_name
82
- @value = unquote_value(column_value)
83
-
84
- end
85
-
86
- def to_s
87
-
88
- @value
89
-
90
- end
91
-
92
- end
93
-
94
- end
95
- end