1SQL::Translator::ProducUesre:r:TCToSncthreimbau(t3e)d PeSrQlL:D:oTcruamnesnltaattoiro:n:Producer::TTSchema(3)
2
3
4
6 SQL::Translator::Producer::TTSchema -
7 Produces output using the Template Toolkit from a SQL schema
8
10 use SQL::Translator;
11 my $translator = SQL::Translator->new(
12 from => 'MySQL',
13 filename => 'foo_schema.sql',
14 to => 'TTSchema',
15 producer_args => {
16 ttfile => 'foo_template.tt', # Template file to use
17
18 # Extra template variables
19 tt_vars => {
20 author => "Mr Foo",
21 },
22
23 # Template config options
24 tt_conf => {
25 INCLUDE_PATH => '/foo/templates',
26 },
27 },
28 );
29 print $translator->translate;
30
32 Produces schema output using a given Template Tookit template.
33
34 It needs one additional producer arg of "ttfile" which is the file name
35 of the template to use. This template will be passed a variable called
36 "schema", which is the "SQL::Translator::Producer::Schema" object
37 created by the parser. You can then use it to walk the schema via the
38 methods documented in that module.
39
40 Here's a brief example of what the template could look like:
41
42 database: [% schema.database %]
43 tables:
44 [% FOREACH table = schema.get_tables %]
45 [% table.name %]
46 ================
47 [% FOREACH field = table.get_fields %]
48 [% field.name %] [% field.data_type %]([% field.size %])
49 [% END -%]
50 [% END %]
51
52 See t/data/template/basic.tt for a more complete example.
53
54 The template will also get the set of extra variables given as a
55 hashref via the "tt_vars" producer arg. (Note that the old style of
56 passing this config in the "ttargs" producer arg has been deprecated).
57
58 You can set any of the options used to initialize the Template object
59 by adding a "tt_conf" producer arg. See Template Toolkit docs for
60 details of the options. (Note that the old style of passing this
61 config directly in the "ttargs" producer args has been deprecated).
62
63 $translator = SQL::Translator->new(
64 to => 'TT',
65 producer_args => {
66 ttfile => 'foo_template.tt',
67 tt_vars => {},
68 tt_conf => {
69 INCLUDE_PATH => '/foo/templates/tt',
70 INTERPOLATE => 1,
71 }
72 },
73 );
74
75 You can use this producer to create any type of text output you like,
76 even using it to create your own versions of what the other producers
77 make. For example, you could create a template that translates the
78 schema into MySQL's syntax, your own HTML documentation, your own
79 Class::DBI classes (or some other code) -- the opportunities are
80 limitless!
81
82 Producer Args
83 ttfile
84 The template file to generate the output with.
85
86 tt_vars
87 A hash ref of extra variables you want to add to the template.
88
89 tt_conf
90 A hash ref of configuration options to pass to the Template
91 object's constructor.
92
94 Mark Addison <grommit@users.sourceforge.net>.
95
97 More template vars? e.g. [% tables %] as a shortcut for [%
98 schema.get_tables %].
99
101 SQL::Translator.
102
103
104
105perl v5.36.0 2023-02S-Q2L7::Translator::Producer::TTSchema(3)