1SQL::Abstract::Tree(3)User Contributed Perl DocumentationSQL::Abstract::Tree(3)
2
3
4

NAME

6       SQL::Abstract::Tree - Represent SQL as an AST
7

SYNOPSIS

9        my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' });
10
11        print $sqla_tree->format('SELECT * FROM foo WHERE foo.a > 2');
12
13        # SELECT *
14        #   FROM foo
15        #   WHERE foo.a > 2
16

METHODS

18   new
19        my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' });
20
21        $args = {
22          profile => 'console',      # predefined profile to use (default: 'none')
23          fill_in_placeholders => 1, # true for placeholder population
24          placeholder_surround =>    # The strings that will be wrapped around
25                     [GREEN, RESET], # populated placeholders if the above is set
26          indent_string => ' ',      # the string used when indenting
27          indent_amount => 2,        # how many of above string to use for a single
28                                     # indent level
29          newline       => "\n",     # string for newline
30          colormap      => {
31            select => [RED, RESET], # a pair of strings defining what to surround
32                                    # the keyword with for colorization
33            # ...
34          },
35          indentmap     => {
36            select        => 0,     # A zero means that the keyword will start on
37                                    # a new line
38            from          => 1,     # Any other positive integer means that after
39            on            => 2,     # said newline it will get that many indents
40            # ...
41          },
42        }
43
44       Returns a new SQL::Abstract::Tree object.  All arguments are optional.
45
46       profiles
47
48       There are four predefined profiles, "none", "console",
49       "console_monochrome", and "html".  Typically a user will probably just
50       use "console" or "console_monochrome", but if something about a profile
51       bothers you, merely use the profile and override the parts that you
52       don't like.
53
54   format
55        $sqlat->format('SELECT * FROM bar WHERE x = ?', [1])
56
57       Takes $sql and "\@bindargs".
58
59       Returns a formatting string based on the string passed in
60
61   parse
62        $sqlat->parse('SELECT * FROM bar WHERE x = ?')
63
64       Returns a "tree" representing passed in SQL.  Please do not depend on
65       the structure of the returned tree.  It may be stable at some point,
66       but not yet.
67
68   unparse
69        $sqlat->unparse($tree_structure, \@bindargs)
70
71       Transform "tree" into SQL, applying various transforms on the way.
72
73   format_keyword
74        $sqlat->format_keyword('SELECT')
75
76       Currently this just takes a keyword and puts the "colormap" stuff
77       around it.  Later on it may do more and allow for coderef based
78       transforms.
79
80   pad_keyword
81        my ($before, $after) = @{$sqlat->pad_keyword('SELECT')};
82
83       Returns whitespace to be inserted around a keyword.
84
85   fill_in_placeholder
86        my $value = $sqlat->fill_in_placeholder(\@bindargs)
87
88       Removes last arg from passed arrayref and returns it, surrounded with
89       the values in placeholder_surround, and then surrounded with single
90       quotes.
91
92   indent
93       Returns as many indent strings as indent amounts times the first
94       argument.
95

ACCESSORS

97   colormap
98       See "new"
99
100   fill_in_placeholders
101       See "new"
102
103   indent_amount
104       See "new"
105
106   indent_string
107       See "new"
108
109   indentmap
110       See "new"
111
112   newline
113       See "new"
114
115   placeholder_surround
116       See "new"
117
118
119
120perl v5.34.0                      2021-07-22            SQL::Abstract::Tree(3)
Impressum