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 β€” See new.
  • fill_in_placeholders β€” See new.
  • indent_amount β€” See new.
  • indent_string β€” See new.
  • indentmap β€” See new.
  • newline β€” See new.
  • placeholder_surround β€” See new.

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