@query-doctor/core 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -44,6 +44,7 @@ __export(index_exports, {
44
44
  PgIdentifier: () => PgIdentifier,
45
45
  PostgresQueryBuilder: () => PostgresQueryBuilder,
46
46
  PostgresVersion: () => PostgresVersion,
47
+ PssRewriter: () => PssRewriter,
47
48
  SKIP: () => SKIP,
48
49
  Statistics: () => Statistics,
49
50
  StatisticsMode: () => StatisticsMode,
@@ -902,6 +903,9 @@ var _PgIdentifier = class _PgIdentifier {
902
903
  }
903
904
  return this.value;
904
905
  }
906
+ toJSON() {
907
+ return this.toString();
908
+ }
905
909
  };
906
910
  // Every keyword that's not explicitly marked as
907
911
  // unreserved in src/include/parser/kwlist.h
@@ -2023,6 +2027,28 @@ __publicField(_Statistics, "defaultStatsMode", Object.freeze({
2023
2027
  relpages: DEFAULT_RELPAGES
2024
2028
  }));
2025
2029
  var Statistics = _Statistics;
2030
+
2031
+ // src/optimizer/pss-rewriter.ts
2032
+ var PssRewriter = class {
2033
+ constructor() {
2034
+ __publicField(this, "problematicKeywords", ["interval", "timestamp", "geometry"]);
2035
+ }
2036
+ rewrite(query) {
2037
+ return this.rewriteKeywordWithParameter(query);
2038
+ }
2039
+ rewriteKeywordWithParameter(query) {
2040
+ return query.replace(/\b(\w+) (\$\d+)\b/gi, (match) => {
2041
+ const [keyword, parameter] = match.split(" ");
2042
+ const isProblematicKeyword = this.problematicKeywords.includes(
2043
+ keyword.toLowerCase()
2044
+ );
2045
+ if (!isProblematicKeyword) {
2046
+ return match;
2047
+ }
2048
+ return `(${parameter}::${keyword.toLowerCase()})`;
2049
+ });
2050
+ }
2051
+ };
2026
2052
  // Annotate the CommonJS export names for ESM import in node:
2027
2053
  0 && (module.exports = {
2028
2054
  Analyzer,
@@ -2036,6 +2062,7 @@ var Statistics = _Statistics;
2036
2062
  PgIdentifier,
2037
2063
  PostgresQueryBuilder,
2038
2064
  PostgresVersion,
2065
+ PssRewriter,
2039
2066
  SKIP,
2040
2067
  Statistics,
2041
2068
  StatisticsMode,