@pgplex/pgconsole 1.0.1 → 1.0.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.
@@ -1 +1 @@
1
- import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./index-D7n7c6X5.js";export{o as ensureModuleLoaded};
1
+ import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g}from"./index-CRV3ELJ0.js";export{o as ensureModuleLoaded};
@@ -9,7 +9,7 @@
9
9
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
10
  <link href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&display=swap" rel="stylesheet" />
11
11
  <title>pgconsole</title>
12
- <script type="module" crossorigin src="/assets/index-D7n7c6X5.js"></script>
12
+ <script type="module" crossorigin src="/assets/index-CRV3ELJ0.js"></script>
13
13
  <link rel="stylesheet" crossorigin href="/assets/index-C8bwjbrl.css">
14
14
  </head>
15
15
  <body>
package/dist/server.mjs CHANGED
@@ -57892,6 +57892,7 @@ function transformSelect(raw) {
57892
57892
  return {
57893
57893
  kind: "select",
57894
57894
  distinct: false,
57895
+ distinctOn: null,
57895
57896
  columns: [],
57896
57897
  from: null,
57897
57898
  where: null,
@@ -57900,28 +57901,35 @@ function transformSelect(raw) {
57900
57901
  orderBy: null,
57901
57902
  limit: null,
57902
57903
  offset: null,
57904
+ windowClause: null,
57903
57905
  withClause: null,
57904
57906
  setOp: {
57905
57907
  op: opType,
57906
57908
  all: !!raw.all,
57907
57909
  left: transformSelect(raw.larg),
57908
57910
  right: transformSelect(raw.rarg)
57909
- }
57911
+ },
57912
+ lockingClause: null
57910
57913
  };
57911
57914
  }
57915
+ const distinctClause = raw.distinctClause;
57916
+ const hasDistinctOn = distinctClause && distinctClause.length > 0 && Object.keys(distinctClause[0]).length > 0;
57912
57917
  return {
57913
57918
  kind: "select",
57914
- distinct: !!raw.distinctClause,
57919
+ distinct: !!distinctClause,
57920
+ distinctOn: hasDistinctOn ? distinctClause.map(transformExpr) : null,
57915
57921
  columns: transformTargetList(raw.targetList),
57916
57922
  from: transformFromClause(raw.fromClause),
57917
57923
  where: raw.whereClause ? transformExpr(raw.whereClause) : null,
57918
- groupBy: raw.groupClause ? raw.groupClause.map(transformExpr) : null,
57924
+ groupBy: raw.groupClause ? raw.groupClause.map(transformGroupByItem) : null,
57919
57925
  having: raw.havingClause ? transformExpr(raw.havingClause) : null,
57920
57926
  orderBy: transformSortClause(raw.sortClause),
57921
57927
  limit: raw.limitCount ? transformExpr(raw.limitCount) : null,
57922
57928
  offset: raw.limitOffset ? transformExpr(raw.limitOffset) : null,
57929
+ windowClause: transformWindowClause(raw.windowClause),
57923
57930
  withClause: transformWithClause(raw.withClause),
57924
- setOp: null
57931
+ setOp: null,
57932
+ lockingClause: transformLockingClause(raw.lockingClause)
57925
57933
  };
57926
57934
  }
57927
57935
  function transformTargetList(list) {
@@ -57961,11 +57969,73 @@ function transformSortClause(list) {
57961
57969
  };
57962
57970
  });
57963
57971
  }
57972
+ function transformLockingClause(nodes) {
57973
+ if (!nodes || nodes.length === 0) return null;
57974
+ return nodes.map((node) => {
57975
+ const lc = node.LockingClause;
57976
+ const strength = lc.strength;
57977
+ const strengthMap = {
57978
+ "LCS_FORUPDATE": "update",
57979
+ "LCS_FORNOKEYUPDATE": "no_key_update",
57980
+ "LCS_FORSHARE": "share",
57981
+ "LCS_FORKEYSHARE": "key_share"
57982
+ };
57983
+ const waitPolicy = lc.waitPolicy;
57984
+ const waitPolicyMap = {
57985
+ "LockWaitBlock": "block",
57986
+ "LockWaitSkip": "skip_locked",
57987
+ "LockWaitError": "nowait"
57988
+ };
57989
+ const lockedRels = lc.lockedRels;
57990
+ return {
57991
+ strength: strengthMap[strength] || "update",
57992
+ waitPolicy: waitPolicyMap[waitPolicy] || "block",
57993
+ lockedRels: lockedRels ? lockedRels.map((r2) => {
57994
+ const rangeVar = r2.RangeVar;
57995
+ return rangeVar.relname;
57996
+ }) : null
57997
+ };
57998
+ });
57999
+ }
57964
58000
  function transformFromClause(list) {
57965
58001
  if (!list || list.length === 0) return null;
57966
- return transformFromItem(list[0]);
58002
+ if (list.length === 1) {
58003
+ return transformFromItem(list[0]);
58004
+ }
58005
+ let result = transformFromItem(list[0]);
58006
+ for (let i2 = 1; i2 < list.length; i2++) {
58007
+ result = {
58008
+ kind: "join",
58009
+ type: "cross",
58010
+ left: result,
58011
+ right: transformFromItem(list[i2]),
58012
+ on: null,
58013
+ using: null
58014
+ };
58015
+ }
58016
+ return result;
57967
58017
  }
57968
58018
  function transformFromItem(node) {
58019
+ if ("RangeTableSample" in node) {
58020
+ const rts = node.RangeTableSample;
58021
+ const relation = rts.relation;
58022
+ const rv = relation.RangeVar;
58023
+ const alias = rts.alias;
58024
+ const method = rts.method;
58025
+ const methodName = method.length > 0 ? method[0].String.sval : "BERNOULLI";
58026
+ const args = rts.args;
58027
+ return {
58028
+ kind: "table",
58029
+ schema: rv.schemaname || null,
58030
+ table: rv.relname,
58031
+ alias: alias?.aliasname || null,
58032
+ tablesample: {
58033
+ method: methodName,
58034
+ args: args ? args.map(transformExpr) : [],
58035
+ repeatable: rts.repeatable ? transformExpr(rts.repeatable) : null
58036
+ }
58037
+ };
58038
+ }
57969
58039
  if ("RangeVar" in node) {
57970
58040
  const rv = node.RangeVar;
57971
58041
  const alias = rv.alias;
@@ -57973,7 +58043,8 @@ function transformFromItem(node) {
57973
58043
  kind: "table",
57974
58044
  schema: rv.schemaname || null,
57975
58045
  table: rv.relname,
57976
- alias: alias?.aliasname || null
58046
+ alias: alias?.aliasname || null,
58047
+ tablesample: null
57977
58048
  };
57978
58049
  }
57979
58050
  if ("RangeSubselect" in node) {
@@ -57982,6 +58053,7 @@ function transformFromItem(node) {
57982
58053
  const subquery = rs.subquery;
57983
58054
  return {
57984
58055
  kind: "subquery",
58056
+ lateral: !!rs.lateral,
57985
58057
  query: transformSelect(subquery.SelectStmt),
57986
58058
  alias: alias?.aliasname || ""
57987
58059
  };
@@ -58005,7 +58077,27 @@ function transformFromItem(node) {
58005
58077
  using: using ? using.map((u) => u.String.sval) : null
58006
58078
  };
58007
58079
  }
58008
- return { kind: "table", schema: null, table: "", alias: null };
58080
+ return { kind: "table", schema: null, table: "", alias: null, tablesample: null };
58081
+ }
58082
+ function transformGroupByItem(node) {
58083
+ if (!node || typeof node !== "object") return transformExpr(node);
58084
+ const obj = node;
58085
+ if ("GroupingSet" in obj) {
58086
+ const gs = obj.GroupingSet;
58087
+ const kindMap = {
58088
+ "GROUPING_SET_ROLLUP": "rollup",
58089
+ "GROUPING_SET_CUBE": "cube",
58090
+ "GROUPING_SET_SETS": "sets",
58091
+ "GROUPING_SET_EMPTY": "empty"
58092
+ };
58093
+ const kind = kindMap[gs.kind] || "sets";
58094
+ const content = gs.content;
58095
+ return {
58096
+ kind,
58097
+ content: content ? content.map(transformGroupByItem) : []
58098
+ };
58099
+ }
58100
+ return transformExpr(node);
58009
58101
  }
58010
58102
  function transformExpr(node) {
58011
58103
  if (!node || typeof node !== "object") return { kind: "unknown", raw: node };
@@ -58025,6 +58117,71 @@ function transformExpr(node) {
58025
58117
  if ("RowExpr" in obj) return transformRowExpr(obj.RowExpr);
58026
58118
  return { kind: "unknown", raw: node };
58027
58119
  }
58120
+ function transformWindowClause(list) {
58121
+ if (!list || list.length === 0) return null;
58122
+ return list.map((item) => {
58123
+ const w = item.WindowDef;
58124
+ return {
58125
+ name: w.name || null,
58126
+ partitionBy: w.partitionClause ? w.partitionClause.map(transformExpr) : null,
58127
+ orderBy: transformSortClause(w.orderClause),
58128
+ frameClause: transformWindowFrame(w)
58129
+ };
58130
+ });
58131
+ }
58132
+ function transformWindowFrame(overNode) {
58133
+ const frameOptions = overNode.frameOptions;
58134
+ if (!frameOptions || frameOptions === 0) return null;
58135
+ const FRAMEOPTION_ROWS = 4;
58136
+ const FRAMEOPTION_RANGE = 2;
58137
+ const FRAMEOPTION_GROUPS = 8;
58138
+ const FRAMEOPTION_BETWEEN = 16;
58139
+ const FRAMEOPTION_START_UNBOUNDED_PRECEDING = 32;
58140
+ const FRAMEOPTION_START_CURRENT_ROW = 512;
58141
+ const FRAMEOPTION_START_OFFSET_PRECEDING = 2048;
58142
+ const FRAMEOPTION_START_OFFSET_FOLLOWING = 4096;
58143
+ const FRAMEOPTION_END_UNBOUNDED_PRECEDING = 64;
58144
+ const FRAMEOPTION_END_UNBOUNDED_FOLLOWING = 256;
58145
+ const FRAMEOPTION_END_CURRENT_ROW = 1024;
58146
+ const FRAMEOPTION_END_OFFSET_PRECEDING = 8192;
58147
+ const FRAMEOPTION_END_OFFSET_FOLLOWING = 16384;
58148
+ let frameType;
58149
+ if (frameOptions & FRAMEOPTION_ROWS) frameType = "rows";
58150
+ else if (frameOptions & FRAMEOPTION_RANGE) frameType = "range";
58151
+ else if (frameOptions & FRAMEOPTION_GROUPS) frameType = "groups";
58152
+ else return null;
58153
+ let startBound;
58154
+ if (frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING) {
58155
+ startBound = { type: "unbounded_preceding", offset: null };
58156
+ } else if (frameOptions & FRAMEOPTION_START_CURRENT_ROW) {
58157
+ startBound = { type: "current_row", offset: null };
58158
+ } else if (frameOptions & FRAMEOPTION_START_OFFSET_PRECEDING) {
58159
+ startBound = { type: "preceding", offset: overNode.startOffset ? transformExpr(overNode.startOffset) : null };
58160
+ } else if (frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) {
58161
+ startBound = { type: "following", offset: overNode.startOffset ? transformExpr(overNode.startOffset) : null };
58162
+ } else {
58163
+ return null;
58164
+ }
58165
+ let endBound = null;
58166
+ if (frameOptions & FRAMEOPTION_BETWEEN) {
58167
+ if (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING) {
58168
+ endBound = { type: "unbounded_following", offset: null };
58169
+ } else if (frameOptions & FRAMEOPTION_END_CURRENT_ROW) {
58170
+ endBound = { type: "current_row", offset: null };
58171
+ } else if (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING) {
58172
+ endBound = { type: "preceding", offset: overNode.endOffset ? transformExpr(overNode.endOffset) : null };
58173
+ } else if (frameOptions & FRAMEOPTION_END_OFFSET_FOLLOWING) {
58174
+ endBound = { type: "following", offset: overNode.endOffset ? transformExpr(overNode.endOffset) : null };
58175
+ } else if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING) {
58176
+ endBound = { type: "unbounded_preceding", offset: null };
58177
+ }
58178
+ }
58179
+ return {
58180
+ type: frameType,
58181
+ start: startBound,
58182
+ end: endBound
58183
+ };
58184
+ }
58028
58185
  function transformColumnRef(node) {
58029
58186
  const fields = node.fields;
58030
58187
  const parts = fields.map((f3) => {
@@ -58091,8 +58248,10 @@ function transformFuncCall(node) {
58091
58248
  if (node.over) {
58092
58249
  const overNode = node.over;
58093
58250
  over = {
58251
+ name: overNode.name || null,
58094
58252
  partitionBy: overNode.partitionClause ? overNode.partitionClause.map(transformExpr) : null,
58095
- orderBy: transformSortClause(overNode.orderClause)
58253
+ orderBy: transformSortClause(overNode.orderClause),
58254
+ frameClause: transformWindowFrame(overNode)
58096
58255
  };
58097
58256
  }
58098
58257
  return {
@@ -58198,20 +58357,48 @@ function transformInsert(raw) {
58198
58357
  select = transformSelect(innerSelect);
58199
58358
  }
58200
58359
  const returningList = raw.returningList;
58360
+ const onConflictClause = raw.onConflictClause;
58201
58361
  return {
58202
58362
  kind: "insert",
58203
58363
  table: {
58204
58364
  kind: "table",
58205
58365
  schema: relation.schemaname || null,
58206
58366
  table: relation.relname,
58207
- alias: alias?.aliasname || null
58367
+ alias: alias?.aliasname || null,
58368
+ tablesample: null
58208
58369
  },
58209
58370
  columns,
58210
58371
  values,
58211
58372
  select,
58373
+ onConflict: onConflictClause ? transformOnConflict(onConflictClause) : null,
58212
58374
  returning: returningList ? transformTargetList(returningList) : null
58213
58375
  };
58214
58376
  }
58377
+ function transformOnConflict(raw) {
58378
+ const action = raw.action;
58379
+ const actionType = action === "ONCONFLICT_UPDATE" ? "update" : "nothing";
58380
+ const infer = raw.infer;
58381
+ const indexElems = infer?.indexElems;
58382
+ const target = indexElems ? indexElems.map((elem) => {
58383
+ const indexElem = elem.IndexElem;
58384
+ return indexElem.name;
58385
+ }) : null;
58386
+ const targetList = raw.targetList;
58387
+ const assignments = targetList ? targetList.map((item) => {
58388
+ const resTarget = item.ResTarget;
58389
+ return {
58390
+ column: resTarget.name,
58391
+ value: transformExpr(resTarget.val)
58392
+ };
58393
+ }) : null;
58394
+ const whereClause = raw.whereClause ? transformExpr(raw.whereClause) : null;
58395
+ return {
58396
+ action: actionType,
58397
+ target,
58398
+ assignments,
58399
+ where: whereClause
58400
+ };
58401
+ }
58215
58402
  function transformUpdate(raw) {
58216
58403
  const relation = raw.relation;
58217
58404
  const alias = relation.alias;
@@ -58230,7 +58417,8 @@ function transformUpdate(raw) {
58230
58417
  kind: "table",
58231
58418
  schema: relation.schemaname || null,
58232
58419
  table: relation.relname,
58233
- alias: alias?.aliasname || null
58420
+ alias: alias?.aliasname || null,
58421
+ tablesample: null
58234
58422
  },
58235
58423
  assignments,
58236
58424
  from: transformFromClause(raw.fromClause),
@@ -58248,7 +58436,8 @@ function transformDelete(raw) {
58248
58436
  kind: "table",
58249
58437
  schema: relation.schemaname || null,
58250
58438
  table: relation.relname,
58251
- alias: alias?.aliasname || null
58439
+ alias: alias?.aliasname || null,
58440
+ tablesample: null
58252
58441
  },
58253
58442
  using: transformFromClause(raw.usingClause),
58254
58443
  where: raw.whereClause ? transformExpr(raw.whereClause) : null,
@@ -58277,7 +58466,8 @@ function transformCreateTable(raw) {
58277
58466
  kind: "table",
58278
58467
  schema: relation.schemaname || null,
58279
58468
  table: relation.relname,
58280
- alias: null
58469
+ alias: null,
58470
+ tablesample: null
58281
58471
  },
58282
58472
  columns,
58283
58473
  constraints,
@@ -58467,7 +58657,8 @@ function transformAlterTable(raw) {
58467
58657
  kind: "table",
58468
58658
  schema: relation.schemaname || null,
58469
58659
  table: relation.relname,
58470
- alias: null
58660
+ alias: null,
58661
+ tablesample: null
58471
58662
  },
58472
58663
  commands
58473
58664
  };
@@ -58541,7 +58732,8 @@ function transformCreateView(raw, source) {
58541
58732
  kind: "table",
58542
58733
  schema: view.schemaname || null,
58543
58734
  table: view.relname,
58544
- alias: null
58735
+ alias: null,
58736
+ tablesample: null
58545
58737
  },
58546
58738
  query: transformSelect(query.SelectStmt),
58547
58739
  replace: !!raw.replace,
@@ -58560,7 +58752,8 @@ function transformCreateTableAs(raw, source) {
58560
58752
  kind: "table",
58561
58753
  schema: rel.schemaname || null,
58562
58754
  table: rel.relname,
58563
- alias: null
58755
+ alias: null,
58756
+ tablesample: null
58564
58757
  },
58565
58758
  query: transformSelect(query.SelectStmt),
58566
58759
  replace: false,
@@ -58595,7 +58788,8 @@ function transformCreateIndex(raw, source) {
58595
58788
  kind: "table",
58596
58789
  schema: relation.schemaname || null,
58597
58790
  table: relation.relname,
58598
- alias: null
58791
+ alias: null,
58792
+ tablesample: null
58599
58793
  },
58600
58794
  columns,
58601
58795
  unique: !!raw.unique,
@@ -58819,7 +59013,8 @@ function transformTruncate(raw, source) {
58819
59013
  kind: "table",
58820
59014
  schema: rangeVar.schemaname || null,
58821
59015
  table: rangeVar.relname,
58822
- alias: null
59016
+ alias: null,
59017
+ tablesample: null
58823
59018
  });
58824
59019
  }
58825
59020
  }
@@ -92227,7 +92422,15 @@ var TEXT_TO_SQL = {
92227
92422
  2. Use the exact table and column names from the schema
92228
92423
  3. Prefer explicit column names over SELECT *
92229
92424
  4. Include appropriate WHERE clauses when the request implies filtering
92230
- 5. Use proper PostgreSQL {{version}} syntax`,
92425
+ 5. Use proper PostgreSQL {{version}} syntax
92426
+
92427
+ ## Formatting
92428
+
92429
+ Format the SQL with proper indentation and line breaks for readability:
92430
+ - Keywords (SELECT, FROM, WHERE, etc.) on separate lines
92431
+ - Column lists with one column per line (when multiple columns)
92432
+ - Indent clauses with 2 spaces
92433
+ - Use uppercase for SQL keywords`,
92231
92434
  user: ({ prompt }) => prompt
92232
92435
  };
92233
92436
  var EXPLAIN_SQL = {
@@ -92980,7 +93183,7 @@ async function start() {
92980
93183
  \\ \\_\\ /\\____/
92981
93184
  \\/_/ \\_/__/
92982
93185
 
92983
- Version ${"1.0.1"}
93186
+ Version ${"1.0.2"}
92984
93187
  `);
92985
93188
  console.log(`Server running on http://localhost:${port}`);
92986
93189
  const browserUrl = false ? `http://localhost:5173` : getExternalUrl() || `http://localhost:${port}`;