SQL::Ab...ct::Tree(3)
π¦ SQL::Abstract::Tree π¦
okay bestie, this is the SQL::Abstract::Tree(3) page from User Contributed Perl Documentation, and it is literally about representing SQL as an AST. No cap, it's giving parser-tree main character energy. π
πΈ NAME πΈ
SQL::Abstract::Tree β Represent SQL as an AST
β¨ SYNOPSIS β¨
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
π METHODS π
π new π
my $sqla_tree = SQL::Abstract::Tree->new({ profile => 'console' });
Here's the whole $args situation, bestie β every option, default and comment is right here:
$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. Periodt. π
π§ format π§
$sqlat->format('SELECT * FROM bar WHERE x = ?', [1])
Takes $sql and \@bindargs.
Returns a formatting string based on the string passed in. β¨
π¦ parse π¦
$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. π
πΈ unparse πΈ
$sqlat->unparse($tree_structure, \@bindargs)
Transform "tree" into SQL, applying various transforms on the way. π₯
π format_keyword π
$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. iykyk. π
π pad_keyword π
my ($before, $after) = @{$sqlat->pad_keyword('SELECT')};
Returns whitespace to be inserted around a keyword. π«Ά
π fill_in_placeholder π
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. π
π§ indent π§
Returns as many indent strings as indent_amount times the first argument.
π ACCESSORS π
These are all just accessors that point back to new β no cap. π
colormapβ Seenew.fill_in_placeholdersβ Seenew.indent_amountβ Seenew.indent_stringβ Seenew.indentmapβ Seenew.newlineβ Seenew.placeholder_surroundβ Seenew.
that's the whole page, bestie π«Ά This manual page is from perl v5.42.0, dated 2021-01-24, and the footer reads SQL::Ab...ct::Tree(3). Slay. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-SQL-Abstract 2.000001-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms