imparcial 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +5 -0
- data/README.txt +48 -0
- data/Rakefile +51 -0
- data/lib/imparcial.rb +7 -0
- metadata +37 -81
- data/lib/imparcial/driver/abstract/expression/base.rb +0 -111
- data/lib/imparcial/driver/abstract/expression/column.rb +0 -313
- data/lib/imparcial/driver/abstract/expression/constraint.rb +0 -149
- data/lib/imparcial/driver/abstract/expression/delete.rb +0 -88
- data/lib/imparcial/driver/abstract/expression/index.rb +0 -206
- data/lib/imparcial/driver/abstract/expression/insert.rb +0 -49
- data/lib/imparcial/driver/abstract/expression/lock.rb +0 -11
- data/lib/imparcial/driver/abstract/expression/record.rb +0 -41
- data/lib/imparcial/driver/abstract/expression/select.rb +0 -38
- data/lib/imparcial/driver/abstract/expression/sequence.rb +0 -260
- data/lib/imparcial/driver/abstract/expression/statement.rb +0 -128
- data/lib/imparcial/driver/abstract/expression/table.rb +0 -416
- data/lib/imparcial/driver/abstract/expression/transaction.rb +0 -143
- data/lib/imparcial/driver/abstract/expression/update.rb +0 -50
- data/lib/imparcial/driver/abstract/expression.rb +0 -24
- data/lib/imparcial/driver/abstract/result.rb +0 -95
- data/lib/imparcial/driver/abstract/sql/column.rb +0 -103
- data/lib/imparcial/driver/abstract/sql/constraint.rb +0 -42
- data/lib/imparcial/driver/abstract/sql/delete.rb +0 -22
- data/lib/imparcial/driver/abstract/sql/index.rb +0 -45
- data/lib/imparcial/driver/abstract/sql/insert.rb +0 -63
- data/lib/imparcial/driver/abstract/sql/record.rb +0 -19
- data/lib/imparcial/driver/abstract/sql/select.rb +0 -101
- data/lib/imparcial/driver/abstract/sql/sequence.rb +0 -55
- data/lib/imparcial/driver/abstract/sql/table.rb +0 -42
- data/lib/imparcial/driver/abstract/sql/transaction.rb +0 -43
- data/lib/imparcial/driver/abstract/sql/update.rb +0 -29
- data/lib/imparcial/driver/abstract/sql.rb +0 -21
- data/lib/imparcial/driver/abstract/typemap.rb +0 -168
- data/lib/imparcial/driver/abstract/util.rb +0 -53
- data/lib/imparcial/driver/abstract.rb +0 -255
- data/lib/imparcial/driver/mysql/expression/table.rb +0 -17
- data/lib/imparcial/driver/mysql/expression.rb +0 -11
- data/lib/imparcial/driver/mysql/result.rb +0 -33
- data/lib/imparcial/driver/mysql/sql/column.rb +0 -59
- data/lib/imparcial/driver/mysql/sql/constraint.rb +0 -39
- data/lib/imparcial/driver/mysql/sql/index.rb +0 -42
- data/lib/imparcial/driver/mysql/sql/sequence.rb +0 -39
- data/lib/imparcial/driver/mysql/sql/table.rb +0 -67
- data/lib/imparcial/driver/mysql/sql.rb +0 -15
- data/lib/imparcial/driver/mysql/typemap.rb +0 -13
- data/lib/imparcial/driver/mysql/util.rb +0 -13
- data/lib/imparcial/driver/mysql.rb +0 -49
- data/lib/imparcial/driver/postgre/expression.rb +0 -32
- data/lib/imparcial/driver/postgre/result.rb +0 -35
- data/lib/imparcial/driver/postgre/sql/column.rb +0 -53
- data/lib/imparcial/driver/postgre/sql/constraint.rb +0 -37
- data/lib/imparcial/driver/postgre/sql/index.rb +0 -53
- data/lib/imparcial/driver/postgre/sql/sequence.rb +0 -30
- data/lib/imparcial/driver/postgre/sql/table.rb +0 -46
- data/lib/imparcial/driver/postgre/sql.rb +0 -15
- data/lib/imparcial/driver/postgre/typemap.rb +0 -29
- data/lib/imparcial/driver/postgre/util.rb +0 -19
- data/lib/imparcial/driver/postgre.rb +0 -43
- data/lib/imparcial/driver.rb +0 -1
- data/lib/imparcial/exception.rb +0 -71
- data/lib/imparcial/initializer.rb +0 -62
@@ -1,149 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Constraint
|
5
|
-
|
6
|
-
###########################################
|
7
|
-
# #
|
8
|
-
# Primary Key #
|
9
|
-
# #
|
10
|
-
###########################################
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def expected_options_for_adding_primary_key
|
15
|
-
|
16
|
-
{:table_name => :required, :fields => :required}
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
|
-
# === Description
|
23
|
-
# Make a bunch of fields primary key.
|
24
|
-
#
|
25
|
-
# === Usage
|
26
|
-
# abstract_adapter.primary_key :table_name => 'person',
|
27
|
-
# :fields => ['id','name']
|
28
|
-
#
|
29
|
-
# === Options
|
30
|
-
# * :table_name
|
31
|
-
# * :fields
|
32
|
-
#
|
33
|
-
# === Returning
|
34
|
-
# nothing
|
35
|
-
|
36
|
-
def add_primary_key ( options = {} )
|
37
|
-
|
38
|
-
check_options expected_options_for_adding_primary_key, options
|
39
|
-
|
40
|
-
sql = sql_for_adding_primary_key( options )
|
41
|
-
|
42
|
-
logger.warn sql if @column_logging
|
43
|
-
|
44
|
-
query sql
|
45
|
-
|
46
|
-
rescue adapter_specific_exception => ex
|
47
|
-
|
48
|
-
raise ColumnConstraintError.new(ex.message)
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
###########################################
|
53
|
-
# #
|
54
|
-
# Auto Increment #
|
55
|
-
# #
|
56
|
-
###########################################
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def expected_options_for_adding_auto_increment
|
61
|
-
|
62
|
-
{:table_name => :required, :field => :required}
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
public
|
67
|
-
|
68
|
-
# === Description
|
69
|
-
# Make a bunch of fields auto increment.
|
70
|
-
#
|
71
|
-
# === Usage
|
72
|
-
# abstract_adapter.add_auto_increment :table_name => 'person',
|
73
|
-
# :fields => ['id','name']
|
74
|
-
#
|
75
|
-
# === Options
|
76
|
-
# * :table_name
|
77
|
-
# * :fields
|
78
|
-
#
|
79
|
-
# === Returning
|
80
|
-
# nothing
|
81
|
-
|
82
|
-
def add_auto_increment ( options = {} )
|
83
|
-
|
84
|
-
check_options expected_options_for_adding_auto_increment, options
|
85
|
-
|
86
|
-
add_primary_key :table_name => options[:table_name], :fields => [options[:field]]
|
87
|
-
sql = sql_for_adding_auto_increment( options )
|
88
|
-
|
89
|
-
logger.warn sql if @column_logging
|
90
|
-
|
91
|
-
query sql
|
92
|
-
|
93
|
-
rescue adapter_specific_exception => ex
|
94
|
-
|
95
|
-
raise ColumnConstraintError.new(ex.message)
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
###########################################
|
100
|
-
# #
|
101
|
-
# Default Value #
|
102
|
-
# #
|
103
|
-
###########################################
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
def expected_options_for_adding_default_value
|
108
|
-
|
109
|
-
{:table_name => :required, :fields => :required}
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
public
|
114
|
-
|
115
|
-
# === Description
|
116
|
-
# Add default value for some fields.
|
117
|
-
#
|
118
|
-
# === Usage
|
119
|
-
# abstract_adapter.add_default_value :table_name => 'person',
|
120
|
-
# :fields => {:id => 1, :name => 'jota'}
|
121
|
-
#
|
122
|
-
# === Options
|
123
|
-
# * :table_name
|
124
|
-
# * :fields
|
125
|
-
#
|
126
|
-
# === Returning
|
127
|
-
# nothing
|
128
|
-
|
129
|
-
def add_default_value ( options = {} )
|
130
|
-
|
131
|
-
check_options expected_options_for_adding_default_value, options
|
132
|
-
|
133
|
-
sql = sql_for_adding_default_value( options )
|
134
|
-
|
135
|
-
logger.warn sql if @column_logging
|
136
|
-
|
137
|
-
query sql
|
138
|
-
|
139
|
-
rescue adapter_specific_exception => ex
|
140
|
-
|
141
|
-
raise ColumnConstraintError.new(ex.message)
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
@@ -1,88 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Delete
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def expected_options_for_deleting
|
9
|
-
|
10
|
-
{:table_name => :required, :conditions => :required}
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
public
|
15
|
-
|
16
|
-
# === Description
|
17
|
-
# Delete some records. Besides, this function demands deleting
|
18
|
-
# with some conditions.
|
19
|
-
#
|
20
|
-
# === Usage
|
21
|
-
# abstract_adapter.delete :table_name => 'person', :conditions =>
|
22
|
-
# ['id = ?',1]
|
23
|
-
#
|
24
|
-
# === Options
|
25
|
-
# * :table_name
|
26
|
-
# * :conditions
|
27
|
-
#
|
28
|
-
# === Returning
|
29
|
-
# nothing
|
30
|
-
|
31
|
-
def delete ( options = {} )
|
32
|
-
|
33
|
-
check_options expected_options_for_deleting, options
|
34
|
-
|
35
|
-
sql = sql_for_deleting( options )
|
36
|
-
|
37
|
-
logger.warn sql if @delete_logging
|
38
|
-
|
39
|
-
query sql
|
40
|
-
|
41
|
-
rescue adapter_specific_exception => ex
|
42
|
-
|
43
|
-
raise DeleteError.new(ex.message)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def expected_options_for_deleting_all
|
50
|
-
|
51
|
-
{:table_name => :required}
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
public
|
56
|
-
|
57
|
-
# === Description
|
58
|
-
# Delete some records. Besides, this function demands no conditions.
|
59
|
-
#
|
60
|
-
# === Usage
|
61
|
-
# abstract_adapter.delete_all :table_name => 'person'
|
62
|
-
#
|
63
|
-
# === Options
|
64
|
-
# * :table_name
|
65
|
-
#
|
66
|
-
# === Returning
|
67
|
-
# nothing
|
68
|
-
|
69
|
-
def delete_all ( options = {} )
|
70
|
-
|
71
|
-
check_options expected_options_for_deleting_all, options
|
72
|
-
|
73
|
-
sql = sql_for_deleting( options )
|
74
|
-
|
75
|
-
logger.warn sql if @delete_logging
|
76
|
-
|
77
|
-
query sql
|
78
|
-
|
79
|
-
rescue adapter_specific_exception => ex
|
80
|
-
|
81
|
-
raise DeleteError.new(ex.message)
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,206 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Index
|
5
|
-
|
6
|
-
###########################################
|
7
|
-
# #
|
8
|
-
# Index Creation #
|
9
|
-
# #
|
10
|
-
###########################################
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def expected_options_for_creating_index
|
15
|
-
|
16
|
-
{
|
17
|
-
:index_name => :required, :index_type => :optional, :table_name => :required,
|
18
|
-
:column_name => :required
|
19
|
-
}
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
public
|
24
|
-
|
25
|
-
# === Description
|
26
|
-
# Create an index.
|
27
|
-
#
|
28
|
-
# === Usage
|
29
|
-
# abstract_adapter.create_index :index_name => 'idx', :table_name = 'person'
|
30
|
-
# ,:column_name => :id
|
31
|
-
#
|
32
|
-
# === Options
|
33
|
-
# * :index_name
|
34
|
-
# * :table_name
|
35
|
-
# * :column_name
|
36
|
-
# * :index_type
|
37
|
-
#
|
38
|
-
# === Returning
|
39
|
-
# nothing
|
40
|
-
|
41
|
-
def create_index ( options = {} )
|
42
|
-
|
43
|
-
check_options expected_options_for_creating_index, options
|
44
|
-
|
45
|
-
sql = sql_for_creating_index( options )
|
46
|
-
|
47
|
-
logger.warn sql if @index_logging
|
48
|
-
|
49
|
-
query sql
|
50
|
-
|
51
|
-
rescue adapter_specific_exception => ex
|
52
|
-
|
53
|
-
raise IndexCreateError.new(ex.message)
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
###########################################
|
58
|
-
# #
|
59
|
-
# Index Dropping #
|
60
|
-
# #
|
61
|
-
###########################################
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def expected_options_for_dropping_index
|
66
|
-
|
67
|
-
{:table_name => :required, :index_name => :required}
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
public
|
72
|
-
|
73
|
-
def drop_index ( options = {} )
|
74
|
-
|
75
|
-
check_options expected_options_for_dropping_index, options
|
76
|
-
|
77
|
-
sql = sql_for_dropping_index( options )
|
78
|
-
|
79
|
-
logger.warn sql if @index_logging
|
80
|
-
|
81
|
-
query sql
|
82
|
-
|
83
|
-
rescue adapter_specific_exception => ex
|
84
|
-
|
85
|
-
raise IndexDropError.new(ex.message)
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
def expected_options_for_dropping_all_indexes
|
90
|
-
|
91
|
-
{:table_name => :required}
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
public
|
96
|
-
|
97
|
-
def drop_all_indexes ( options = {} )
|
98
|
-
|
99
|
-
check_options expected_options_for_dropping_all_indexes, options
|
100
|
-
|
101
|
-
for index in get_indexes(:table_name => options[:table_name])
|
102
|
-
|
103
|
-
drop_index :table_name => index[:table], :index_name => index[:name]
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
###########################################
|
110
|
-
# #
|
111
|
-
# Index Listing #
|
112
|
-
# #
|
113
|
-
###########################################
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def expected_options_for_getting_indexes
|
118
|
-
|
119
|
-
{:table_name => :required}
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
public
|
124
|
-
|
125
|
-
# === Description
|
126
|
-
# Get metadata about all indexes.
|
127
|
-
#
|
128
|
-
# === Usage
|
129
|
-
# abstract_adapter.retrieve_indexes
|
130
|
-
#
|
131
|
-
# === Options
|
132
|
-
# No options
|
133
|
-
#
|
134
|
-
# === Returning
|
135
|
-
# an array with hashes.
|
136
|
-
|
137
|
-
def get_indexes ( options = {} )
|
138
|
-
|
139
|
-
check_options expected_options_for_getting_indexes, options
|
140
|
-
|
141
|
-
sql = sql_for_getting_indexes options
|
142
|
-
|
143
|
-
logger.warn sql if @index_logging
|
144
|
-
|
145
|
-
query sql
|
146
|
-
|
147
|
-
indexes = []
|
148
|
-
|
149
|
-
result.fetch do |table, column, index|
|
150
|
-
|
151
|
-
indexes << {:table => table.value,:column => column.value,:name => index.value}
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
indexes
|
156
|
-
|
157
|
-
rescue adapter_specific_exception => ex
|
158
|
-
|
159
|
-
raise IndexListError.new(ex.message)
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
private
|
164
|
-
|
165
|
-
def expected_options_for_verifying_index_existance
|
166
|
-
|
167
|
-
{:index_name => :required, :table_name => :required}
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
public
|
172
|
-
|
173
|
-
# === Description
|
174
|
-
# Verify if a given index exists.
|
175
|
-
#
|
176
|
-
# === Usage
|
177
|
-
# abstract_adapter.retrieve_indexes
|
178
|
-
#
|
179
|
-
# === Options
|
180
|
-
# No options
|
181
|
-
#
|
182
|
-
# === Returning
|
183
|
-
# true or false.
|
184
|
-
|
185
|
-
def index_exists? ( options = {} )
|
186
|
-
|
187
|
-
check_options expected_options_for_verifying_index_existance, options
|
188
|
-
|
189
|
-
sql = sql_for_index_exists?( options )
|
190
|
-
|
191
|
-
logger.warn sql if @index_logging
|
192
|
-
|
193
|
-
query sql
|
194
|
-
|
195
|
-
result.rows > 0
|
196
|
-
|
197
|
-
rescue adapter_specific_exception => ex
|
198
|
-
|
199
|
-
raise IndexDropError.new(ex.message)
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Insert
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def expected_options_for_inserting
|
9
|
-
|
10
|
-
{:table_name => :required, :values => :required}
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
public
|
15
|
-
|
16
|
-
# === Description
|
17
|
-
# Insert some records.
|
18
|
-
#
|
19
|
-
# === Usage
|
20
|
-
# abstract_adapter.insert :table_name => 'person', :values =>
|
21
|
-
# {:id => 1, :name => 'ronaldinho'}
|
22
|
-
#
|
23
|
-
# === Options
|
24
|
-
# * :table_name
|
25
|
-
# * :values
|
26
|
-
#
|
27
|
-
# === Returning
|
28
|
-
# nothing
|
29
|
-
|
30
|
-
def insert ( options = {} )
|
31
|
-
|
32
|
-
check_options expected_options_for_inserting, options
|
33
|
-
|
34
|
-
sql = sql_for_inserting( options )
|
35
|
-
|
36
|
-
logger.warn sql if @insert_logging
|
37
|
-
|
38
|
-
query sql
|
39
|
-
|
40
|
-
rescue adapter_specific_exception => ex
|
41
|
-
|
42
|
-
raise InsertError.new(ex.message)
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Record
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def expected_options_for_total_of_records
|
9
|
-
|
10
|
-
{:table_name => :required}
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
public
|
15
|
-
|
16
|
-
# Retrieve the total of records in a table.
|
17
|
-
|
18
|
-
def total_of_records ( options = {} )
|
19
|
-
|
20
|
-
check_options expected_options_for_total_of_records, options
|
21
|
-
|
22
|
-
sql = sql_for_couting_records( options )
|
23
|
-
|
24
|
-
logger.warn sql if @record_logging
|
25
|
-
|
26
|
-
query sql
|
27
|
-
|
28
|
-
result.fetch_first_row.value
|
29
|
-
|
30
|
-
rescue adapter_specific_exception => ex
|
31
|
-
|
32
|
-
raise ExpressionError.new(ex.message)
|
33
|
-
|
34
|
-
end
|
35
|
-
alias_method :num_of_records, :total_of_records
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Imparcial
|
2
|
-
module Driver
|
3
|
-
module AbstractExpression
|
4
|
-
module Select
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def expected_options_for_selecting
|
9
|
-
|
10
|
-
{
|
11
|
-
:table_name => :optional, :joins => :optional, :fields => :optional,
|
12
|
-
:conditions => :optional, :limit => :optional, :order_asc => :optional,
|
13
|
-
:order_desc => :optional
|
14
|
-
}
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
public
|
20
|
-
|
21
|
-
def select ( options = {} )
|
22
|
-
|
23
|
-
sql = sql_for_selecting( options )
|
24
|
-
|
25
|
-
logger.warn sql if @select_logging
|
26
|
-
|
27
|
-
query sql
|
28
|
-
|
29
|
-
rescue adapter_specific_exception => ex
|
30
|
-
|
31
|
-
raise SelectError.new(ex.message)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|