(->ast parsed)Given a sql query, return a clojure ast that represents it.
This ast can potentially be lossy and generally shouldn't be as part of a round trip back to sql.
Given a sql query, return a clojure ast that represents it. This ast can potentially be lossy and generally shouldn't be as part of a round trip back to sql.
(parsed-query query & {:as opts})Main entry point: takes a string query and returns a Statement object that can be handled by the other functions.
NOTE: unescape-parse does not un-shift token positions (e.g. net.sf.jsqlparser.parser.Token#-endColumn),
they continue to refer to the escaped string.
It would be complex and expensive to update every subsequent token, and unnecessary in most use cases.
We account for this in replace-names, and expect any future code to compensate for it too where needed.
Main entry point: takes a string query and returns a `Statement` object that can be handled by the other functions.
NOTE: `unescape-parse` does not un-shift token positions (e.g. `net.sf.jsqlparser.parser.Token#-endColumn`),
they continue to refer to the escaped string.
It would be complex and expensive to update every subsequent token, and unnecessary in most use cases.
We account for this in [[replace-names]], and expect any future code to compensate for it too where needed.(query->components parsed & {:as opts})Given a parsed query (i.e., a [subclass of] Statement) return a map with the elements found within it.
(Specifically, it returns their fully-qualified names as strings, where 'fully-qualified' means 'as referred to in the query'; this function doesn't do additional inference work to find out a table's schema.)
Note that this is O(N^2) normally, but drops to O(N) when :strip-contexts? is specified.
Given a parsed query (i.e., a [subclass of] `Statement`) return a map with the elements found within it. (Specifically, it returns their fully-qualified names as strings, where 'fully-qualified' means 'as referred to in the query'; this function doesn't do additional inference work to find out a table's schema.) Note that this is O(N^2) normally, but drops to O(N) when :strip-contexts? is specified.
(query->tables sql & {:keys [mode] :as opts})Given a parsed query (i.e., a [subclass of] Statement) return a set of all the table identifiers found within it.
Given a parsed query (i.e., a [subclass of] `Statement`) return a set of all the table identifiers found within it.
(replace-names sql renames & {:as opts})Given an SQL query, apply the given table, column, and schema renames.
Supported options:
case-insensitive: whether to relax the comparison
quotes-preserve-case: whether quoted identifiers should override the previous option.
Given an SQL query, apply the given table, column, and schema renames. Supported options: - case-insensitive: whether to relax the comparison - :upper - identifiers are implicitly case to uppercase, as per the SQL-92 standard. - :lower - identifiers are implicitly cast to lowercase, as per Postgres et al. - :agnostic - case is ignored when comparing identifiers in code to replacement "from" strings. - quotes-preserve-case: whether quoted identifiers should override the previous option.
(scope-id s)A unique identifier for the given scope.
A unique identifier for the given scope.
(scope-label s)The type of scope we're talking about e.g., a top-level SELECT.
The type of scope we're talking about e.g., a top-level SELECT.
(unescape item keywords ctx)Rewrite identifiers back to their original names, where they were escaped to bypass reserved words.
Rewrite identifiers back to their original names, where they were escaped to bypass reserved words.
(unescape-parsed parsed keywords)Unescape the AST (parsed) created by CCJSqlParserUtil/parse.
This compensates for the pre-processing done in [[escape-keywords]].
_Unescape_ the AST (`parsed`) created by `CCJSqlParserUtil/parse`. This compensates for the pre-processing done in [[escape-keywords]].
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |