ramen 0.4.0
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.
- data/doc/doc_resources/MetaData_Class_Diagram.gif +0 -0
- data/doc/doc_resources/MetaData_Class_Diagram.png +0 -0
- data/doc/doc_resources/Thumbs.db +0 -0
- data/lib/ramen/core.rb +75 -0
- data/lib/ramen/default_logger.rb +29 -0
- data/lib/ramen/engine/engine.rb +34 -0
- data/lib/ramen/engine/mysql.rb +225 -0
- data/lib/ramen/engine/sql2005.rb +377 -0
- data/lib/ramen/home.rb +162 -0
- data/lib/ramen/metadata/column.rb +38 -0
- data/lib/ramen/metadata/database.rb +137 -0
- data/lib/ramen/metadata/foreign_key.rb +71 -0
- data/lib/ramen/metadata/foreign_key_column.rb +51 -0
- data/lib/ramen/metadata/index.rb +71 -0
- data/lib/ramen/metadata/index_column.rb +49 -0
- data/lib/ramen/metadata/key_constraint.rb +56 -0
- data/lib/ramen/metadata/metadata.rb +10 -0
- data/lib/ramen/metadata/primary_key.rb +71 -0
- data/lib/ramen/metadata/primary_key_column.rb +49 -0
- data/lib/ramen/metadata/schema.rb +86 -0
- data/lib/ramen/metadata/table.rb +202 -0
- data/lib/ramen/ramen_error.rb +16 -0
- data/lib/ramen/ramen_hash.rb +143 -0
- data/lib/ramen/ramen_module.rb +52 -0
- data/lib/ramen/row_data_gateway.rb +89 -0
- data/lib/ramen/version.rb +16 -0
- data/lib/ramen.rb +62 -0
- data/readme.txt +159 -0
- data/test/config/config.yml +19 -0
- data/test/helper.rb +18 -0
- data/test/mysql_create_test_db.sql +47 -0
- data/test/sql2005_create_test_db.sql +45 -0
- data/test/test_bugs.rb +32 -0
- data/test/test_core.rb +63 -0
- data/test/test_default_logger.rb +38 -0
- data/test/test_home.rb +33 -0
- data/test/test_ramen.rb +274 -0
- data/test/test_ramen_hash.rb +78 -0
- data/test/test_ramen_module.rb +21 -0
- metadata +99 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/ramen/core.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
# 'core.rb' contains additions to Ruby's core classes: String and NilClass
|
|
6
|
+
|
|
7
|
+
module Kernel
|
|
8
|
+
unless Kernel.respond_to? :singleton_class
|
|
9
|
+
def singleton_class
|
|
10
|
+
class << self; self; end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class String
|
|
16
|
+
# to_delimited_words #=> string
|
|
17
|
+
#
|
|
18
|
+
# Returns a string with CamelCase converted to underscore delimited words.
|
|
19
|
+
#
|
|
20
|
+
# usage:
|
|
21
|
+
# "CamelCase".to_delimited_words #=> "camel_case"
|
|
22
|
+
#
|
|
23
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-core_rb.html]
|
|
24
|
+
#
|
|
25
|
+
def to_delimited_words
|
|
26
|
+
results = []
|
|
27
|
+
word = ''
|
|
28
|
+
(0...self.size).each do |i|
|
|
29
|
+
char = self[i,1]
|
|
30
|
+
if char.is_upcase?
|
|
31
|
+
unless word.size == 0
|
|
32
|
+
results << word
|
|
33
|
+
word = ''
|
|
34
|
+
end
|
|
35
|
+
word << char.downcase
|
|
36
|
+
else
|
|
37
|
+
word << char
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
unless word.size == 0
|
|
41
|
+
results << word
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
results.join( '_')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# is_upcase?
|
|
48
|
+
#
|
|
49
|
+
# Intention Revealing Message pattern. (Kent Beck. Smalltalk Best Practices
|
|
50
|
+
# Patterns. Perntice Hall PTR, Upper Saddle River, NJ 1997)
|
|
51
|
+
#
|
|
52
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-core_rb.html]
|
|
53
|
+
#
|
|
54
|
+
def is_upcase?
|
|
55
|
+
self.upcase == self
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class NilClass
|
|
60
|
+
unless NilClass.method_defined? '<=>'.to_sym
|
|
61
|
+
# Comparison, returns -1,0,+1
|
|
62
|
+
#
|
|
63
|
+
# if argument is nil, returns 0 (same)
|
|
64
|
+
# otherwise returns -1 (self is < other)
|
|
65
|
+
#
|
|
66
|
+
# this allows sorting of collections that contain nil, the nil will sort to
|
|
67
|
+
# the front.
|
|
68
|
+
#
|
|
69
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-core_rb.html]
|
|
70
|
+
#
|
|
71
|
+
def <=> other
|
|
72
|
+
(other.nil?) ? 0 : -1
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen
|
|
7
|
+
# A simple logger, just calls #puts to display warn, error and fatal messages.
|
|
8
|
+
#
|
|
9
|
+
# When creating a custom logger for Ramen#create or Home#new, these methods need
|
|
10
|
+
# to be defined.
|
|
11
|
+
#
|
|
12
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-default_logger_rb.html]
|
|
13
|
+
#
|
|
14
|
+
class DefaultLogger
|
|
15
|
+
def debug( msg )
|
|
16
|
+
end
|
|
17
|
+
def info( msg )
|
|
18
|
+
end
|
|
19
|
+
def warn( msg )
|
|
20
|
+
puts msg
|
|
21
|
+
end
|
|
22
|
+
def error( msg )
|
|
23
|
+
puts msg
|
|
24
|
+
end
|
|
25
|
+
def fatal( msg )
|
|
26
|
+
puts msg
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen
|
|
7
|
+
# This module is a mix-in into modules which contain the code specific to
|
|
8
|
+
# database engines. For example, Sql2005 has the code for SQL Server 2005,
|
|
9
|
+
# and therefore it includes this module.
|
|
10
|
+
module Engine
|
|
11
|
+
class << self
|
|
12
|
+
def included( mod )
|
|
13
|
+
lineno, source = __LINE__, <<-SOURCE
|
|
14
|
+
class << self
|
|
15
|
+
def const_missing( name )
|
|
16
|
+
unless Ramen::Metadata.const_defined? name
|
|
17
|
+
raise NameError, "uninitialized constant \#{self.name}::\#{name}", caller
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
parent_class = Ramen::Metadata.const_get( name )
|
|
21
|
+
unless parent_class.instance_of? Class
|
|
22
|
+
raise NameError, "uninitialized constant \#{self.name}::\#{name}", caller
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
self.module_eval "class \#{name} < \#{parent_class}; end", __FILE__, __LINE__
|
|
26
|
+
self.const_get( name )
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
SOURCE
|
|
30
|
+
mod.module_eval source, __FILE__, lineno
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2007 Gregory N. Houston
|
|
3
|
+
# See ramen.rb for license information.
|
|
4
|
+
#++
|
|
5
|
+
|
|
6
|
+
module Ramen
|
|
7
|
+
# Responsible for returning T-SQL statements for various Sql Server 2005 queries.
|
|
8
|
+
#
|
|
9
|
+
# Links: readme.txt[link:files/readme_txt.html]; source[link:rcov/lib-ramen-sql2005_rb.html]
|
|
10
|
+
#
|
|
11
|
+
module MySql500
|
|
12
|
+
include Ramen::Engine
|
|
13
|
+
|
|
14
|
+
class Sql
|
|
15
|
+
# returns the query for all schemas and their meta-data.
|
|
16
|
+
#
|
|
17
|
+
# the query must include the schema_name
|
|
18
|
+
def Sql.schemas
|
|
19
|
+
<<SQL
|
|
20
|
+
select
|
|
21
|
+
catalog_name,
|
|
22
|
+
schema_name,
|
|
23
|
+
default_character_set_name,
|
|
24
|
+
default_collation_name,
|
|
25
|
+
sql_path
|
|
26
|
+
from information_schema.schemata
|
|
27
|
+
SQL
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# returns the query for all tables and their meta-data.
|
|
31
|
+
#
|
|
32
|
+
# the query must include the table_schema and table_name.
|
|
33
|
+
def Sql.tables
|
|
34
|
+
<<SQL
|
|
35
|
+
select
|
|
36
|
+
table_catalog,
|
|
37
|
+
table_schema,
|
|
38
|
+
table_name,
|
|
39
|
+
table_type,
|
|
40
|
+
engine,
|
|
41
|
+
version,
|
|
42
|
+
row_format,
|
|
43
|
+
table_rows,
|
|
44
|
+
avg_row_length,
|
|
45
|
+
data_length,
|
|
46
|
+
max_data_length,
|
|
47
|
+
index_length,
|
|
48
|
+
data_free,
|
|
49
|
+
auto_increment,
|
|
50
|
+
create_time,
|
|
51
|
+
update_time,
|
|
52
|
+
check_time,
|
|
53
|
+
table_collation,
|
|
54
|
+
checksum,
|
|
55
|
+
create_options,
|
|
56
|
+
table_comment
|
|
57
|
+
from information_schema.tables
|
|
58
|
+
SQL
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# selects all tables, via a different query. used for testing only.
|
|
62
|
+
#
|
|
63
|
+
# returns table_schema and table_name for every table.
|
|
64
|
+
def Sql.list_tables
|
|
65
|
+
<<SQL
|
|
66
|
+
SELECT table_schema, table_name from information_schema.tables
|
|
67
|
+
SQL
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# returns the query for all columns and their meta-data.
|
|
71
|
+
#
|
|
72
|
+
# the query must include the table_schema, table_name and column_name.
|
|
73
|
+
def Sql.columns
|
|
74
|
+
<<SQL
|
|
75
|
+
select
|
|
76
|
+
table_catalog,
|
|
77
|
+
table_schema,
|
|
78
|
+
table_name,
|
|
79
|
+
column_name,
|
|
80
|
+
ordinal_position,
|
|
81
|
+
column_default,
|
|
82
|
+
is_nullable,
|
|
83
|
+
data_type,
|
|
84
|
+
character_maximum_length,
|
|
85
|
+
character_octet_length,
|
|
86
|
+
numeric_precision,
|
|
87
|
+
numeric_scale,
|
|
88
|
+
character_set_name,
|
|
89
|
+
collation_name,
|
|
90
|
+
column_type,
|
|
91
|
+
column_key,
|
|
92
|
+
extra,
|
|
93
|
+
privileges,
|
|
94
|
+
column_comment
|
|
95
|
+
from information_schema.columns
|
|
96
|
+
SQL
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# returns the query for all primary keys and their meta-data.
|
|
100
|
+
#
|
|
101
|
+
# the query must include the table_schema, table_name and
|
|
102
|
+
# primary_key_name.
|
|
103
|
+
def Sql.primary_keys
|
|
104
|
+
<<SQL
|
|
105
|
+
select
|
|
106
|
+
constraint_schema as table_schema,
|
|
107
|
+
table_name,
|
|
108
|
+
constraint_name as primary_key_name
|
|
109
|
+
from information_schema.table_constraints tc
|
|
110
|
+
where tc.constraint_type = 'PRIMARY KEY'
|
|
111
|
+
SQL
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# returns the query for all primary key columns and their meta-data.
|
|
115
|
+
#
|
|
116
|
+
# the query must include the table_schema, table_name,
|
|
117
|
+
# primary_key_name, and column_name.
|
|
118
|
+
def Sql.primary_key_columns
|
|
119
|
+
<<SQL
|
|
120
|
+
select
|
|
121
|
+
tc.constraint_schema as table_schema,
|
|
122
|
+
tc.table_name,
|
|
123
|
+
tc.constraint_name as primary_key_name,
|
|
124
|
+
kcu.column_name,
|
|
125
|
+
kcu.ordinal_position,
|
|
126
|
+
kcu.position_in_unique_constraint,
|
|
127
|
+
kcu.referenced_table_schema,
|
|
128
|
+
kcu.referenced_table_name,
|
|
129
|
+
kcu.referenced_column_name
|
|
130
|
+
from information_schema.table_constraints tc
|
|
131
|
+
inner join information_schema.key_column_usage kcu
|
|
132
|
+
on tc.constraint_schema = kcu.constraint_schema
|
|
133
|
+
and tc.table_name = kcu.table_name
|
|
134
|
+
and tc.constraint_name = kcu.constraint_name
|
|
135
|
+
where tc.constraint_type = 'PRIMARY KEY'
|
|
136
|
+
SQL
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# returns the query for all indexes and their meta-data.
|
|
140
|
+
#
|
|
141
|
+
# the query must include the table_schema, table_name,
|
|
142
|
+
# and index_name.
|
|
143
|
+
def Sql.indexes
|
|
144
|
+
<<SQL
|
|
145
|
+
select
|
|
146
|
+
s.table_schema,
|
|
147
|
+
s.table_name,
|
|
148
|
+
s.index_name,
|
|
149
|
+
s.index_type,
|
|
150
|
+
s.non_unique
|
|
151
|
+
from information_schema.statistics s
|
|
152
|
+
where s.index_name not in ('PRIMARY')
|
|
153
|
+
-- foreign keys dont appear in statistics table
|
|
154
|
+
-- use a full outer join if foreign keys are needed.
|
|
155
|
+
group by s.table_schema, s.table_name, s.index_name, s.index_type, s.non_unique
|
|
156
|
+
SQL
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# returns the query for all index columns and their meta-data.
|
|
160
|
+
#
|
|
161
|
+
# the query must include the table_schema, table_name, index_name,
|
|
162
|
+
# and column_name.
|
|
163
|
+
def Sql.index_columns
|
|
164
|
+
<<SQL
|
|
165
|
+
select
|
|
166
|
+
s.table_schema,
|
|
167
|
+
s.table_name,
|
|
168
|
+
s.index_name,
|
|
169
|
+
s.column_name,
|
|
170
|
+
s.seq_in_index,
|
|
171
|
+
s.collation,
|
|
172
|
+
s.cardinality,
|
|
173
|
+
s.sub_part,
|
|
174
|
+
s.packed,
|
|
175
|
+
s.nullable,
|
|
176
|
+
s.comment
|
|
177
|
+
from information_schema.statistics s
|
|
178
|
+
where s.index_name not in ('PRIMARY')
|
|
179
|
+
-- foreign keys dont appear in statistics table
|
|
180
|
+
-- use a full outer join if foreign keys are needed.
|
|
181
|
+
SQL
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# returns the query for all foreign keys and their meta-data.
|
|
185
|
+
#
|
|
186
|
+
# the query must include the table_schema, table_name, and foreign_key_name.
|
|
187
|
+
def Sql.foreign_keys
|
|
188
|
+
<<SQL
|
|
189
|
+
select
|
|
190
|
+
constraint_schema as table_schema,
|
|
191
|
+
table_name,
|
|
192
|
+
constraint_name as foreign_key_name
|
|
193
|
+
from information_schema.table_constraints tc
|
|
194
|
+
where tc.constraint_type = 'FOREIGN KEY'
|
|
195
|
+
SQL
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# returns the query for all foreign key columns and their meta-data.
|
|
199
|
+
#
|
|
200
|
+
# the query must include foreign_key_name, table_schema, table_name,
|
|
201
|
+
# column_name, referenced_table_schema, referenced_table_name,
|
|
202
|
+
# referenced_column_name.
|
|
203
|
+
def Sql.foreign_key_columns
|
|
204
|
+
<<SQL
|
|
205
|
+
select
|
|
206
|
+
tc.constraint_schema as table_schema,
|
|
207
|
+
tc.table_name,
|
|
208
|
+
tc.constraint_name as foreign_key_name,
|
|
209
|
+
kcu.column_name,
|
|
210
|
+
kcu.ordinal_position,
|
|
211
|
+
kcu.position_in_unique_constraint,
|
|
212
|
+
kcu.referenced_table_schema,
|
|
213
|
+
kcu.referenced_table_name,
|
|
214
|
+
kcu.referenced_column_name
|
|
215
|
+
from information_schema.table_constraints tc
|
|
216
|
+
inner join information_schema.key_column_usage kcu
|
|
217
|
+
on tc.constraint_schema = kcu.constraint_schema
|
|
218
|
+
and tc.table_name = kcu.table_name
|
|
219
|
+
and tc.constraint_name = kcu.constraint_name
|
|
220
|
+
where tc.constraint_type = 'FOREIGN KEY'
|
|
221
|
+
SQL
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|