SQL::Abstract::Tree(3) | User Contributed Perl Documentation | SQL::Abstract::Tree(3) |
SQL::Abstract::Tree - Represent SQL as an AST
my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' }); print $sqla_tree->format('SELECT * FROM foo WHERE foo.a > 2'); # SELECT * # FROM foo # WHERE foo.a > 2
my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' }); $args = { profile => 'console', # predefined profile to use (default: 'none') fill_in_placeholders => 1, # true for placeholder population placeholder_surround => # The strings that will be wrapped around [GREEN, RESET], # populated placeholders if the above is set indent_string => ' ', # the string used when indenting indent_amount => 2, # how many of above string to use for a single # indent level newline => "\n", # string for newline colormap => { select => [RED, RESET], # a pair of strings defining what to surround # the keyword with for colorization # ... }, indentmap => { select => 0, # A zero means that the keyword will start on # a new line from => 1, # Any other positive integer means that after on => 2, # said newline it will get that many indents # ... }, }
Returns a new SQL::Abstract::Tree object. All arguments are optional.
profiles
There are four predefined profiles, "none", "console", "console_monochrome", and "html". Typically a user will probably just use "console" or "console_monochrome", but if something about a profile bothers you, merely use the profile and override the parts that you don't like.
$sqlat->format('SELECT * FROM bar WHERE x = ?', [1])
Takes $sql and "\@bindargs".
Returns a formatting string based on the string passed in
$sqlat->parse('SELECT * FROM bar WHERE x = ?')
Returns a "tree" representing passed in SQL. Please do not depend on the structure of the returned tree. It may be stable at some point, but not yet.
$sqlat->unparse($tree_structure, \@bindargs)
Transform "tree" into SQL, applying various transforms on the way.
$sqlat->format_keyword('SELECT')
Currently this just takes a keyword and puts the "colormap" stuff around it. Later on it may do more and allow for coderef based transforms.
my ($before, $after) = @{$sqlat->pad_keyword('SELECT')};
Returns whitespace to be inserted around a keyword.
my $value = $sqlat->fill_in_placeholder(\@bindargs)
Removes last arg from passed arrayref and returns it, surrounded with the values in placeholder_surround, and then surrounded with single quotes.
Returns as many indent strings as indent amounts times the first argument.
See "new"
See "new"
See "new"
See "new"
See "new"
See "new"
See "new"
2018-06-11 | perl v5.34.0 |