@query-doctor/core 0.1.1 → 0.1.2

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.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from "./sql/builder.js";
6
6
  export * from "./sql/pg-identifier.js";
7
7
  export * from "./optimizer/genalgo.js";
8
8
  export * from "./optimizer/statistics.js";
9
+ export * from "./optimizer/pss-rewriter.js";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -1974,6 +1974,28 @@ __publicField(_Statistics, "defaultStatsMode", Object.freeze({
1974
1974
  relpages: DEFAULT_RELPAGES
1975
1975
  }));
1976
1976
  var Statistics = _Statistics;
1977
+
1978
+ // src/optimizer/pss-rewriter.ts
1979
+ var PssRewriter = class {
1980
+ constructor() {
1981
+ __publicField(this, "problematicKeywords", ["interval", "timestamp", "geometry"]);
1982
+ }
1983
+ rewrite(query) {
1984
+ return this.rewriteKeywordWithParameter(query);
1985
+ }
1986
+ rewriteKeywordWithParameter(query) {
1987
+ return query.replace(/\b(\w+) (\$\d+)\b/gi, (match) => {
1988
+ const [keyword, parameter] = match.split(" ");
1989
+ const isProblematicKeyword = this.problematicKeywords.includes(
1990
+ keyword.toLowerCase()
1991
+ );
1992
+ if (!isProblematicKeyword) {
1993
+ return match;
1994
+ }
1995
+ return `(${parameter}::${keyword.toLowerCase()})`;
1996
+ });
1997
+ }
1998
+ };
1977
1999
  export {
1978
2000
  Analyzer,
1979
2001
  ExportedStats,
@@ -1986,6 +2008,7 @@ export {
1986
2008
  PgIdentifier,
1987
2009
  PostgresQueryBuilder,
1988
2010
  PostgresVersion,
2011
+ PssRewriter,
1989
2012
  SKIP,
1990
2013
  Statistics,
1991
2014
  StatisticsMode,