flattendb 0.0.3.242 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to flattendb version 0.0.3
5
+ This documentation refers to flattendb version 0.0.4
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -10,6 +10,15 @@ This documentation refers to flattendb version 0.0.3
10
10
  TODO: well, the description... ;-)
11
11
 
12
12
 
13
+ == LINKS
14
+
15
+ <b></b>
16
+ Documentation:: <http://prometheus.rubyforge.org/flattendb>
17
+ Source code (old):: <http://prometheus.rubyforge.org/svn/scratch/flattendb>
18
+ Source code:: <http://github.com/blackwinter/flattendb>
19
+ Rubyforge project:: <http://rubyforge.org/projects/prometheus>
20
+
21
+
13
22
  == AUTHORS
14
23
 
15
24
  * Jens Wille <mailto:jens.wille@uni-koeln.de>
data/bin/flattendb.mysql CHANGED
@@ -42,6 +42,10 @@ else
42
42
  abort "Input file doesn't seem to be a valid XML file, XML declaration missing"
43
43
  end
44
44
  when :sql
45
+ $dump_file = $infile.sub(/\.(?:sql|dump)$/i, '') << '.xml'
46
+ abort "Dump file and output file are the same: #{$dump_file} = #{$outfile}" \
47
+ if File.expand_path($dump_file) == File.expand_path($outfile)
48
+
45
49
  mysql_cmd = 'mysql'
46
50
  dump_cmd = 'mysqldump'
47
51
 
@@ -60,10 +64,6 @@ else
60
64
  temp_user = 'flattendb_user'
61
65
  temp_pass = 'flattendb_pass'
62
66
 
63
- $dump_file = $infile.sub(/\.(?:sql|dump)$/i, '') << '.xml'
64
- abort "Dump file and output file are the same: #{$dump_file} = #{$outfile}" \
65
- if File.expand_path($dump_file) == File.expand_path($outfile)
66
-
67
67
  mysql_args = "--one-database -u#{temp_user} -p#{temp_pass} #{temp_db} < #{$infile}"
68
68
  dump_args = "--xml -u#{temp_user} -p#{temp_pass} #{temp_db} > #{$dump_file}"
69
69
 
@@ -8,3 +8,11 @@ object:
8
8
  barobject:
9
9
  @key: ObjID
10
10
  attr4: attr4ID
11
+
12
+ #primary_table:
13
+ # foreign_table1: foreign_key1 # local_key1 = foreign_key1
14
+ # foreign_table2: [local_key2, foreign_key2]
15
+ # foreign_table3:
16
+ # @key: foreign_key3 # local_key3 = foreign_key3
17
+ # foreign_table4:
18
+ # @key: [local_key4, foreign_key4]
@@ -26,8 +26,6 @@
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- require 'xml/libxml'
30
-
31
29
  require 'flattendb/base'
32
30
 
33
31
  module FlattenDB
@@ -26,7 +26,7 @@
26
26
  ###############################################################################
27
27
  #++
28
28
 
29
- require 'xml/libxml'
29
+ require 'libxml'
30
30
 
31
31
  require 'flattendb/base'
32
32
 
@@ -41,7 +41,7 @@ module FlattenDB
41
41
  def initialize(infile, outfile, config)
42
42
  super
43
43
 
44
- @document = XML::Document.file(@input.first)
44
+ @document = LibXML::XML::Document.file(@input.first)
45
45
  @database = @document.root.find_first('database[@name]')
46
46
  @name = @database[:name]
47
47
  @tables = {}
@@ -102,15 +102,18 @@ module FlattenDB
102
102
  when Array
103
103
  inject_foreign(tables, primary_table, foreign_table, *spec)
104
104
  when Hash
105
- raise "invalid join table spec, '#{JOIN_KEY}' missing" unless spec.has_key?(JOIN_KEY)
105
+ raise ArgumentError, "invalid join table spec, '#{JOIN_KEY}' missing" unless spec.has_key?(JOIN_KEY)
106
106
 
107
- local_key, foreign_key = spec.delete(JOIN_KEY)
108
- foreign_key ||= local_key
107
+ join_key_spec = spec.delete(JOIN_KEY)
109
108
 
110
109
  joined_tables = tables.dup
111
110
  flatten_tables!(joined_tables, foreign_table, spec)
112
111
 
113
- inject_foreign(tables, primary_table, foreign_table, local_key, foreign_key, joined_tables)
112
+ (join_key_spec.is_a?(Hash) ? join_key_spec : { foreign_table => join_key_spec }).each { |foreign_table_name, join_key|
113
+ local_key, foreign_key = join_key
114
+
115
+ inject_foreign(tables, primary_table, foreign_table, local_key, foreign_key || local_key, joined_tables, foreign_table_name)
116
+ }
114
117
  else
115
118
  raise ArgumentError, "don't know how to handle spec of type '#{spec.class}'"
116
119
  end
@@ -121,15 +124,19 @@ module FlattenDB
121
124
  }
122
125
  end
123
126
 
124
- def inject_foreign(tables, primary_table, foreign_table, local_key, foreign_key = local_key, foreign_tables = tables)
125
- tables[primary_table].each { |row|
126
- next unless row.has_key?(local_key)
127
+ def inject_foreign(tables, primary_table, foreign_table, local_key, foreign_key = local_key, foreign_tables = tables, foreign_table_name = foreign_table)
128
+ raise ArgumentError, "no such foreign table: #{foreign_table}" unless foreign_tables.has_key?(foreign_table)
127
129
 
128
- foreign_content = foreign_tables[foreign_table].find_all { |foreign_row|
129
- row[local_key] == foreign_row[foreign_key]
130
- }
130
+ foreign_rows = foreign_tables[foreign_table]
131
131
 
132
- row[foreign_table] = foreign_content unless foreign_content.empty?
132
+ tables[primary_table].each { |row|
133
+ if row.has_key?(local_key)
134
+ foreign_content = foreign_rows.select { |foreign_row|
135
+ row[local_key] == foreign_row[foreign_key]
136
+ }
137
+
138
+ row[foreign_table_name] = foreign_content unless foreign_content.empty?
139
+ end
133
140
  }
134
141
  end
135
142
 
@@ -32,7 +32,7 @@ module FlattenDB
32
32
 
33
33
  MAJOR = 0
34
34
  MINOR = 0
35
- TINY = 3
35
+ TINY = 4
36
36
 
37
37
  class << self
38
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flattendb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.242
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-21 00:00:00 +02:00
12
+ date: 2008-12-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: highline
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: libxml-ruby
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,7 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: builder
37
+ type: :runtime
35
38
  version_requirement:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
@@ -41,6 +44,7 @@ dependencies:
41
44
  version:
42
45
  - !ruby/object:Gem::Dependency
43
46
  name: ruby-nuggets
47
+ type: :runtime
44
48
  version_requirement:
45
49
  version_requirements: !ruby/object:Gem::Requirement
46
50
  requirements:
@@ -51,8 +55,8 @@ dependencies:
51
55
  description: Flatten relational databases.
52
56
  email: jens.wille@uni-koeln.de
53
57
  executables:
54
- - flattendb
55
58
  - flattendb.mysql
59
+ - flattendb
56
60
  - flattendb.mdb
57
61
  extensions: []
58
62
 
@@ -61,36 +65,36 @@ extra_rdoc_files:
61
65
  - ChangeLog
62
66
  - README
63
67
  files:
68
+ - lib/flattendb/types/mdb.rb
69
+ - lib/flattendb/types/mysql.rb
70
+ - lib/flattendb/cli.rb
64
71
  - lib/flattendb/version.rb
65
72
  - lib/flattendb/base.rb
66
- - lib/flattendb/cli.rb
67
- - lib/flattendb/types/mysql.rb
68
- - lib/flattendb/types/mdb.rb
69
73
  - lib/flattendb.rb
70
- - bin/flattendb
71
74
  - bin/flattendb.mysql
75
+ - bin/flattendb
72
76
  - bin/flattendb.mdb
77
+ - Rakefile
73
78
  - COPYING
74
- - README
75
79
  - ChangeLog
76
- - Rakefile
77
- - example/mysql-sample.sql
80
+ - README
81
+ - example/mysql-sample.xml
78
82
  - example/mysql-sample2flat.yaml
79
83
  - example/mysql-sample.flat.xml
80
- - example/mysql-sample.xml
84
+ - example/mysql-sample.sql
81
85
  has_rdoc: true
82
86
  homepage: http://prometheus.rubyforge.org/flattendb
83
87
  post_install_message:
84
88
  rdoc_options:
85
- - --all
86
89
  - --line-numbers
87
- - --main
88
- - README
89
90
  - --inline-source
90
91
  - --title
91
92
  - flattendb Application documentation
93
+ - --main
94
+ - README
92
95
  - --charset
93
96
  - UTF-8
97
+ - --all
94
98
  require_paths:
95
99
  - lib
96
100
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -108,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  requirements: []
109
113
 
110
114
  rubyforge_project: prometheus
111
- rubygems_version: 1.1.1
115
+ rubygems_version: 1.3.1
112
116
  signing_key:
113
117
  specification_version: 2
114
118
  summary: Flatten relational databases.