kwatable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog.txt +27 -0
  3. data/README.txt +81 -0
  4. data/bin/kwatable +20 -0
  5. data/examples/ex1/Makefile +34 -0
  6. data/examples/ex1/example1.yaml +85 -0
  7. data/examples/ex2/Makefile +34 -0
  8. data/examples/ex2/example2.yaml +94 -0
  9. data/kwatable.gemspec +48 -0
  10. data/lib/kwatable.rb +31 -0
  11. data/lib/kwatable/error-msg.rb +37 -0
  12. data/lib/kwatable/kwatable.schema.yaml +133 -0
  13. data/lib/kwatable/main-program.rb +197 -0
  14. data/lib/kwatable/manufactory.rb +213 -0
  15. data/lib/kwatable/templates/ddl-mysql.eruby +169 -0
  16. data/lib/kwatable/templates/ddl-postgresql.eruby +153 -0
  17. data/lib/kwatable/templates/defaults.yaml +87 -0
  18. data/lib/kwatable/templates/dto-java.eruby +204 -0
  19. data/lib/kwatable/templates/dto-ruby.eruby +180 -0
  20. data/setup.rb +1331 -0
  21. data/test/assert-diff.rb +44 -0
  22. data/test/test.rb +202 -0
  23. data/test/test1/test1.ddl-mysql.expected +22 -0
  24. data/test/test1/test1.ddl-postgresql.expected +22 -0
  25. data/test/test1/test1.dto-java.Group.expected +32 -0
  26. data/test/test1/test1.dto-java.User.expected +59 -0
  27. data/test/test1/test1.dto-ruby.Group.expected +21 -0
  28. data/test/test1/test1.dto-ruby.User.expected +36 -0
  29. data/test/test1/test1.yaml +85 -0
  30. data/test/test2/test2.ddl-mysql.expected +49 -0
  31. data/test/test2/test2.ddl-postgresql.expected +49 -0
  32. data/test/test2/test2.dto-java.Address.expected +42 -0
  33. data/test/test2/test2.dto-java.Customer.expected +49 -0
  34. data/test/test2/test2.dto-java.Item.expected +37 -0
  35. data/test/test2/test2.dto-java.SalesOrder.expected +50 -0
  36. data/test/test2/test2.dto-java.SalesOrderLine.expected +56 -0
  37. data/test/test2/test2.dto-ruby.Address.expected +25 -0
  38. data/test/test2/test2.dto-ruby.Customer.expected +32 -0
  39. data/test/test2/test2.dto-ruby.Item.expected +23 -0
  40. data/test/test2/test2.dto-ruby.SalesOrder.expected +32 -0
  41. data/test/test2/test2.dto-ruby.SalesOrderLine.expected +39 -0
  42. data/test/test2/test2.yaml +94 -0
  43. metadata +91 -0
@@ -0,0 +1,34 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 11 $
5
+ ###
6
+
7
+ datafile = example1.yaml
8
+
9
+ all: ddl-mysql ddl-postgresql dto-java dto-ruby
10
+
11
+ clean:
12
+ rm -f *.sql *.java *.rb
13
+
14
+ ddl-mysql:
15
+ kwatable -f ddl-mysql.eruby $(datafile) > ddl-mysql.sql
16
+ ddl-postgresql:
17
+ kwatable -f ddl-postgresql.eruby $(datafile) > ddl-postgresql.sql
18
+ dto-java:
19
+ kwatable -m -f dto-java.eruby $(datafile)
20
+ dto-ruby:
21
+ kwatable -m -f dto-ruby.eruby $(datafile)
22
+
23
+ #bindir = ../../bin
24
+ #libdir = ../../lib
25
+ #tpldir = $(libdir)/kwatable/templates
26
+ #
27
+ #ddl-mysql:
28
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -f ddl-mysql.eruby $(datafile) > ddl-mysql.sql
29
+ #ddl-postgresql:
30
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -f ddl-postgresql.eruby $(datafile) > ddl-postgresql.sql
31
+ #dto-java:
32
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -m -f dto-java.eruby $(datafile)
33
+ #dto-ruby:
34
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -m -f dto-ruby.eruby $(datafile)
@@ -0,0 +1,85 @@
1
+ ##
2
+ ## example data file for kwatable
3
+ ##
4
+ ## copyright(c) 2005 kuwata-lab.com all rights reserved.
5
+ ## $Release: 0.0.1 $
6
+ ## $Rev: 10 $
7
+ ##
8
+
9
+ columns:
10
+ - name: id
11
+ type: integer
12
+ primary-key: yes
13
+ serial: yes
14
+
15
+ - name: name
16
+ type: string
17
+ not-null: yes
18
+ width: 63
19
+
20
+ - name: desc
21
+ type: string
22
+
23
+ - name: email
24
+ type: string
25
+ width: 63
26
+
27
+ - name: status
28
+ type: string
29
+ width: 15
30
+
31
+ - name: username
32
+ type: string
33
+ width: 31
34
+
35
+ - name: password
36
+ type: string
37
+ width: 31
38
+
39
+ - name: memo
40
+ type: text
41
+
42
+ - name: text
43
+ type: text
44
+
45
+ - name: birth
46
+ type: date
47
+
48
+ - name: age
49
+ type: integer
50
+
51
+ - name: last_update
52
+ type: timestamp
53
+
54
+ - name: gender
55
+ type: string
56
+ values:
57
+ - M
58
+ - F
59
+
60
+ tables:
61
+ - name: groups
62
+ class: Group
63
+ desc: Group master table
64
+ columns:
65
+ - name: id
66
+ - name: name
67
+ - name: desc
68
+
69
+ - name: users
70
+ class: User
71
+ desc: User master table
72
+ columns:
73
+ - name: id
74
+ - name: name
75
+ - name: desc
76
+ - name: email
77
+ - name: group_id
78
+ ref: groups.id
79
+ - name: account
80
+ type: string
81
+ width: 31
82
+ not-null: yes
83
+ - name: password
84
+ not-null: yes
85
+
@@ -0,0 +1,34 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 11 $
5
+ ###
6
+
7
+ datafile = example2.yaml
8
+
9
+ all: ddl-mysql ddl-postgresql dto-java dto-ruby
10
+
11
+ clean:
12
+ rm -f *.sql *.java *.rb
13
+
14
+ ddl-mysql:
15
+ kwatable -f ddl-mysql.eruby $(datafile) > ddl-mysql.sql
16
+ ddl-postgresql:
17
+ kwatable -f ddl-postgresql.eruby $(datafile) > ddl-postgresql.sql
18
+ dto-java:
19
+ kwatable -m -f dto-java.eruby $(datafile)
20
+ dto-ruby:
21
+ kwatable -m -f dto-ruby.eruby $(datafile)
22
+
23
+ #bindir = ../../bin
24
+ #libdir = ../../lib
25
+ #tpldir = $(libdir)/kwatable/templates
26
+ #
27
+ #ddl-mysql:
28
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -f ddl-mysql.eruby $(datafile) > ddl-mysql.sql
29
+ #ddl-postgresql:
30
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -f ddl-postgresql.eruby $(datafile) > ddl-postgresql.sql
31
+ #dto-java:
32
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -m -f dto-java.eruby $(datafile)
33
+ #dto-ruby:
34
+ # ruby -I $(libdir) $(bindir)/kwatable -I $(tpldir) -m -f dto-ruby.eruby $(datafile)
@@ -0,0 +1,94 @@
1
+ columns:
2
+ - name: id
3
+ type: int
4
+ primary-key: yes
5
+ serial: yes
6
+
7
+ - name: name
8
+ type: str
9
+ not-null: yes
10
+
11
+ - name: desc
12
+ type: str
13
+
14
+
15
+ tables:
16
+
17
+ - name: addresses
18
+ class: Address
19
+ desc: Address master table
20
+ columns:
21
+ - name: id
22
+ - name: zipcode
23
+ type: str
24
+ width: 8
25
+ pattern: /^\d+-\d+$/
26
+ - name: addr1
27
+ type: str
28
+ - name: addr2
29
+ type: str
30
+ - name: addr3
31
+ type: str
32
+
33
+ - name: customers
34
+ class: Customer
35
+ desc: Customer master table
36
+ columns:
37
+ - name: id
38
+ - name: name
39
+ - name: tel
40
+ type: str
41
+ - name: email
42
+ type: str
43
+ - name: address_id
44
+ ref: addresses.id
45
+ not-null: yes
46
+
47
+ - name: items
48
+ class: Item
49
+ desc: Item master table
50
+ columns:
51
+ - name: id
52
+ - name: name
53
+ - name: desc
54
+ - name: price
55
+ type: money
56
+ not-null: yes
57
+
58
+ - name: sales_orders
59
+ class: SalesOrder
60
+ desc: Sales order master table
61
+ columns:
62
+ - name: id
63
+ - name: customer_id
64
+ ref: customers.id
65
+ not-null: yes
66
+ - name: ordered_date
67
+ type: date
68
+ not-null: yes
69
+ - name: delivery_date
70
+ type: date
71
+ - name: amount
72
+ type: money
73
+
74
+ - name: sales_order_lines
75
+ class: SalesOrderLine
76
+ desc: Sales Order detail lines
77
+ columns:
78
+ - name: num
79
+ type: int
80
+ not-null: yes
81
+ - name: order_id
82
+ ref: sales_orders.id
83
+ not-null: yes
84
+ - name: item_id
85
+ ref: items.id
86
+ not-null: yes
87
+ - name: price
88
+ type: money
89
+ not-null: yes
90
+ - name: quantity
91
+ type: int
92
+ not-null: yes
93
+ primary-keys: [ order_id, item_id ]
94
+
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###
4
+ ### RubyGems Specification file for kwatable
5
+ ###
6
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
7
+ ### $Release: 0.0.1 $
8
+ ### $Rev: 10 $
9
+ ###
10
+
11
+ require 'rubygems'
12
+
13
+ spec = Gem::Specification.new do |s|
14
+ ## package information
15
+ s.name = 'kwatable'
16
+ s.author = 'makoto kuwata'
17
+ s.version = ("$Release: 0.0.1 $" =~ /Release: ([\.\d]+)/) && $1
18
+ s.platform = Gem::Platform::RUBY
19
+ s.homepage = 'http://www.kuwata-lab.com/kwatable'
20
+ s.summary = "SQL and DTO generator from table definition"
21
+ s.description = <<-'END'
22
+ Kwatable is a pretty tool to generate SQL and DTO from database
23
+ table definition.
24
+ Kwatable reads table definition written in YAML, and generates
25
+ 'create table' SQL script for MySQL and PostgreSQL, or generates
26
+ DTO class file for Java and Ruby.
27
+ You can add your own eRuby template.
28
+ END
29
+
30
+ ## files
31
+ files = []
32
+ files += Dir.glob('lib/**/*')
33
+ files += Dir.glob('bin/**/*')
34
+ files += Dir.glob('templates/**/*')
35
+ files += Dir.glob('examples/**/*')
36
+ files += Dir.glob('test/**/*')
37
+ files += %w[README.txt ChangeLog.txt COPYING setup.rb kwatable.gemspec]
38
+ #s.files = files.delete_if { |path| path =~ /\.svn/ }
39
+ s.files = files
40
+ s.executables = ['kwatable']
41
+ s.bindir = 'bin'
42
+ s.test_file = 'test/test.rb'
43
+ end
44
+
45
+ if $0 == __FILE__
46
+ Gem::manage_gems
47
+ Gem::Builder.new(spec).build
48
+ end
@@ -0,0 +1,31 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 11 $
5
+ ###
6
+
7
+ module Kwatable
8
+
9
+ ## base class of exception
10
+ class KwatableError < StandardError
11
+ end
12
+
13
+ ## template path
14
+ @@template_path = []
15
+ if ENV['KWATABLE_PATH']
16
+ @@template_path += ENV['KWATABLE_PATH'].split(File::PATH_SEPARATOR)
17
+ end
18
+ $LOAD_PATH.each do |path|
19
+ template_path = "#{path}/kwatable/templates"
20
+ @@template_path << template_path if test(?d, template_path)
21
+ end
22
+
23
+ def self.template_path
24
+ return @@template_path
25
+ end
26
+
27
+ end
28
+
29
+ require 'kwatable/error-msg'
30
+
31
+ require 'kwatable/manufactory'
@@ -0,0 +1,37 @@
1
+ ###
2
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
3
+ ### $Release: 0.0.1 $
4
+ ### $Rev: 12 $
5
+ ###
6
+
7
+ module Kwatable
8
+
9
+ @@messages = {}
10
+
11
+ def self.msg(key)
12
+ return @@messages[key]
13
+ end
14
+
15
+ #----- begin auto generate
16
+ @@messages[:template_required] = "template is not specified."
17
+ @@messages[:template_notfound] = "`%s': template file not found."
18
+ @@messages[:file_generated] = "generated: %s"
19
+ @@messages[:template_required] = "-%s: template filename required."
20
+ @@messages[:outdir_required] = "-%s: output directory required."
21
+ @@messages[:directory_required] = "-%s: directory required."
22
+ @@messages[:option_invalid] = "-%s: invalid option."
23
+ @@messages[:colname_required] = "column definition doesn't have a name."
24
+ @@messages[:regexp_invalid] = "column %s: %s"
25
+ @@messages[:coldef_duplicated] = "column definition `%s' is duplicated."
26
+ @@messages[:colname_required] = "column definition doesn't have a name nor namepattern."
27
+ @@messages[:coldef_duplicated] = "column definition `%s' is duplicated."
28
+ @@messages[:tablename_required] = "table definition doesn't have a name."
29
+ @@messages[:tabledef_duplicated] = "table definition `%s' is duplicated."
30
+ @@messages[:tablecolumn_required] = "table '%s': column name requried."
31
+ @@messages[:tablecolumn_duplicated] = "table '%s': column '%s' is duplicated."
32
+ @@messages[:tabletype_required] = "table `%s': type of column `%s' is not determined."
33
+ @@messages[:reftable_notfound] = "`ref: %s': table not found."
34
+ @@messages[:refcolumn_notfound] = "`ref: %s': column not found in the table."
35
+ #----- end auto generate
36
+
37
+ end
@@ -0,0 +1,133 @@
1
+ ###
2
+ ### schema definition of kwalify for kwatable
3
+ ###
4
+ ### copyright(c) 2005 kuwata-lab.com all rights reserved.
5
+ ### $Release: 0.0.1 $
6
+ ### $Rev$
7
+ ###
8
+
9
+
10
+ type: map
11
+ mapping:
12
+ "columns":
13
+ type: seq
14
+ sequence:
15
+ - type: map
16
+ mapping:
17
+ "name":
18
+ type: string
19
+ "namepattern":
20
+ type: string
21
+ pattern: /^\/.*\/$/
22
+ "desc":
23
+ type: text
24
+ "type":
25
+ type: string
26
+ values:
27
+ - char
28
+ - short
29
+ - integer
30
+ - int
31
+ - string
32
+ - str
33
+ - text
34
+ - float
35
+ - double
36
+ - boolean
37
+ - bool
38
+ - date
39
+ - timestamp
40
+ - money
41
+ "width":
42
+ type: integer
43
+ "primary-key":
44
+ type: boolean
45
+ "identifier":
46
+ type: boolean
47
+ "not-null":
48
+ type: boolean
49
+ "required":
50
+ type: boolean
51
+ "unique":
52
+ type: boolean
53
+ "sequence":
54
+ type: boolean
55
+ "serial":
56
+ type: boolean
57
+ "values":
58
+ type: seq
59
+ sequence:
60
+ - type: string
61
+ "ref":
62
+ type: string
63
+ pattern: /^\w+\.\w+$/
64
+ "ref-name":
65
+ type: string
66
+ "pattern":
67
+ type: string
68
+ pattern: /^\/.*\/$/
69
+
70
+ "tables":
71
+ type: seq
72
+ sequence:
73
+ - type: map
74
+ mapping:
75
+ "name":
76
+ type: string
77
+ required: yes
78
+ "desc":
79
+ type: text
80
+ "class":
81
+ type: string
82
+ "columns":
83
+ type: seq
84
+ sequence:
85
+ - type: map
86
+ mapping:
87
+ "name":
88
+ type: string
89
+ "desc":
90
+ type: text
91
+ "type":
92
+ type: string
93
+ values:
94
+ - char
95
+ - short
96
+ - integer
97
+ - int
98
+ - string
99
+ - str
100
+ - text
101
+ - float
102
+ - double
103
+ - boolean
104
+ - bool
105
+ - money
106
+ "width":
107
+ type: integer
108
+ "primary-key":
109
+ type: boolean
110
+ "identifier":
111
+ type: boolean
112
+ "not-null":
113
+ type: boolean
114
+ "required":
115
+ type: boolean
116
+ "unique":
117
+ type: boolean
118
+ "sequence":
119
+ type: boolean
120
+ "serial":
121
+ type: boolean
122
+ "values":
123
+ type: seq
124
+ sequence:
125
+ - type: string
126
+ "ref":
127
+ type: string
128
+ pattern: /^\w+\.\w+$/
129
+ "ref-name":
130
+ type: string
131
+ "pattern":
132
+ type: string
133
+ pattern: /^\/.*\/$/