|
NAMEpgFormatter::Beautify - Library for pretty-printing SQL queriesVERSIONVersion 5.2SYNOPSISThis module can be used to reformat given SQL query, optionally anonymizing parameters.Output can be either plain text, or it can be HTML with appropriate styles so that it can be displayed on a web page. Example usage: my $beautifier = pgFormatter::Beautify->new(); $beautifier->query( 'select a,b,c from d where e = f' ); $beautifier->beautify(); my $nice_txt = $beautifier->content(); $beautifier->format('html'); $beautifier->beautify(); my $nice_html = $beautifier->content(); $beautifier->format('html'); $beautifier->anonymize(); $beautifier->beautify(); my $nice_anonymized_html = $beautifier->content(); $beautifier->format(); $beautifier->beautify(); $beautifier->wrap_lines() my $wrapped_txt = $beautifier->content(); FUNCTIONSnewGeneric constructor - creates object, sets defaults, and reads config from given hash with options.Takes options as hash. Following options are recognized:
For defaults, please check function set_defaults. queryAccessor to query string. Both reads:$object->query() , and writes $object->query( $something ) contentAccessor to content of results. Must be called after $object->beautify().This can be either plain text or html following the format asked by the client with the $object->format() method. highlight_codeMakes result html with styles set for highlighting.tokenize_sqlSplits input SQL into tokensCode lifted from SQL::Beautify beautifyBeautify SQL.After calling this function, $object->content() will contain nicely indented result. Code lifted from SQL::Beautify _add_tokenAdd a token to the beautified string.Code lifted from SQL::Beautify _overIncrease the indentation level.Code lifted from SQL::Beautify _backDecrease the indentation level.Code lifted from SQL::Beautify _indentReturn a string of spaces according to the current indentation level and the spaces setting for indenting.Code lifted from SQL::Beautify _new_lineAdd a line break, but make sure there are no empty lines.Code lifted from SQL::Beautify _next_tokenHave a look at the token that's coming up next.Code lifted from SQL::Beautify _tokenGet the next token, removing it from the list of remaining tokens.Code lifted from SQL::Beautify _is_keywordCheck if a token is a known SQL keyword.Code lifted from SQL::Beautify _is_typeCheck if a token is a known SQL type_is_commentCheck if a token is a SQL or C style comment_is_functionCheck if a token is a known SQL function.Code lifted from SQL::Beautify and rewritten to check one long regexp instead of a lot of small ones. add_keywordsAdd new keywords to highlight.Code lifted from SQL::Beautify _re_from_listCreate compiled regexp from prefix, suffix and and a list of values to match._refresh_functions_reRefresh compiled regexp for functions.add_functionsAdd new functions to highlight.Code lifted from SQL::Beautify add_ruleAdd new rules.Code lifted from SQL::Beautify _get_ruleFind custom rule for a token.Code lifted from SQL::Beautify _process_ruleApplies defined rule.Code lifted from SQL::Beautify _is_constantCheck if a token is a constant.Code lifted from SQL::Beautify _is_punctuationCheck if a token is punctuation.Code lifted from SQL::Beautify _generate_anonymized_stringSimply generate a random string, thanks to Perlmonks.Returns original in certain cases which don't require anonymization, like timestamps, or intervals. anonymizeAnonymize litteral in SQL queries by replacing parameters with fake valuesset_defaultsSets defaults for newly created objects.Currently defined defaults:
formatSet output format - possible values: 'text' and 'html'Default is text output. Returns 0 in case or wrong format and use default. set_dictsSets various dictionaries (lists of keywords, functions, symbols, and the like)This was moved to separate function, so it can be put at the very end of module so it will be easier to read the rest of the code. _remove_dynamic_codeInternal function used to hide dynamic code in plpgsql to the parser. The original values are restored with function _restore_dynamic_code()._restore_dynamic_codeInternal function used to restore plpgsql dynamic code in plpgsql that was removed by the _remove_dynamic_code() method._quote_operatorInternal function used to quote operator with multiple character to be tokenized as a single word. The original values are restored with function _restore_operator()._restore_operatorInternal function used to restore operator that was removed by the _quote_operator() method._quote_comment_stmtInternal function used to replace constant in a COMMENT statement to be tokenized as a single word. The original values are restored with function _restore_comment_stmt()._restore_comment_stmtInternal function used to restore comment string that was removed by the _quote_comment_stmt() method._remove_commentsInternal function used to remove comments in SQL code to simplify the work of the wrap_lines. Comments must be restored with the _restore_comments() method._restore_commentsInternal function used to restore comments in SQL code that was removed by the _remove_comments() method.wrap_linesInternal function used to wrap line at a certain length.AUTHORpgFormatter is an original work from Gilles DaroldBUGSPlease report any bugs or feature requests to: https://github.com/darold/pgFormatter/issuesCOPYRIGHTCopyright 2012-2021 Gilles Darold. All rights reserved.LICENSEpgFormatter is free software distributed under the PostgreSQL Licence.A modified version of the SQL::Beautify Perl Module is embedded in pgFormatter with copyright (C) 2009 by Jonas Kramer and is published under the terms of the Artistic License 2.0.
Visit the GSP FreeBSD Man Page Interface. |