@rex0220/kintone-sql-tools 1.0.3 → 1.1.1

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/README.md CHANGED
@@ -21,7 +21,7 @@ kintone アプリを SQL 風の構文で操作するツールセットです。
21
21
  ## npm(グローバル)
22
22
 
23
23
  ```bash
24
- npm install -g kintone-sql-tools
24
+ npm install -g @rex0220/kintone-sql-tools
25
25
  ksql --help
26
26
  ```
27
27
 
@@ -168,6 +168,9 @@ Options:
168
168
  5. `@profile` を使った DELETE が失敗する
169
169
  - 現在 `DELETE` の `@profile` は未対応です。
170
170
 
171
+ 6. Windows で `ksql --help` 実行時にエディタが開いてしまう
172
+ - `.js` 関連付けの影響の可能性があります。`ksql.cmd --help` または `node dist-cli/ksql.js --help` で確認してください。
173
+
171
174
  ## 機密情報の取り扱い
172
175
 
173
176
  - token / password は直書きせず、環境変数または `env:` 参照を推奨します。
package/dist-cli/ksql.js CHANGED
@@ -3596,6 +3596,7 @@ function project(rows, columns, scalarCache) {
3596
3596
  return { rows: projected2, columns: cols };
3597
3597
  }
3598
3598
  const orderedKeys = [];
3599
+ const defaultFieldKeys = buildDefaultFieldOutputKeys(columns);
3599
3600
  const projected = rows.map((row, rowIdx) => {
3600
3601
  const out = {};
3601
3602
  for (const [colIdx, col] of columns.entries()) {
@@ -3612,7 +3613,7 @@ function project(rows, columns, scalarCache) {
3612
3613
  break;
3613
3614
  }
3614
3615
  case "FIELD": {
3615
- const key = col.alias ?? col.field;
3616
+ const key = col.alias ?? defaultFieldKeys.get(colIdx) ?? col.field;
3616
3617
  out[key] = resolveFieldRef(row, col.field);
3617
3618
  if (rowIdx === 0) orderedKeys.push(key);
3618
3619
  break;
@@ -3651,7 +3652,12 @@ function project(rows, columns, scalarCache) {
3651
3652
  }
3652
3653
  case "STRFUNC_COL": {
3653
3654
  const key = col.alias ?? stringFuncDefaultKey(col.expr);
3654
- out[key] = row[key] ?? evalStringFunc(col.expr, row);
3655
+ if (hasAggregateInStringFuncExpr2(col.expr)) {
3656
+ const srcKey = stringFuncDefaultKey(col.expr);
3657
+ out[key] = row[col.alias ?? srcKey] ?? row[srcKey] ?? evalStringFunc(col.expr, row);
3658
+ } else {
3659
+ out[key] = evalStringFunc(col.expr, row);
3660
+ }
3655
3661
  if (rowIdx === 0) orderedKeys.push(key);
3656
3662
  break;
3657
3663
  }
@@ -3667,6 +3673,30 @@ function project(rows, columns, scalarCache) {
3667
3673
  });
3668
3674
  return { rows: projected, columns: orderedKeys };
3669
3675
  }
3676
+ function buildDefaultFieldOutputKeys(columns) {
3677
+ const qualifierCollisionCount = /* @__PURE__ */ new Map();
3678
+ for (const col of columns) {
3679
+ if (col.type !== "FIELD" || col.alias) continue;
3680
+ const unqualified = stripTableQualifier(col.field);
3681
+ qualifierCollisionCount.set(unqualified, (qualifierCollisionCount.get(unqualified) ?? 0) + 1);
3682
+ }
3683
+ const keys = /* @__PURE__ */ new Map();
3684
+ for (const [idx, col] of columns.entries()) {
3685
+ if (col.type !== "FIELD" || col.alias) continue;
3686
+ const unqualified = stripTableQualifier(col.field);
3687
+ const duplicate = (qualifierCollisionCount.get(unqualified) ?? 0) > 1;
3688
+ const hasTableQualifier = col.field.includes(".") && !col.field.startsWith("_p.");
3689
+ keys.set(idx, duplicate && hasTableQualifier ? col.field : unqualified);
3690
+ }
3691
+ return keys;
3692
+ }
3693
+ function stripTableQualifier(field) {
3694
+ if (field.startsWith("_p.")) return field;
3695
+ const dot = field.indexOf(".");
3696
+ if (dot <= 0) return field;
3697
+ const unqualified = field.slice(dot + 1);
3698
+ return unqualified || field;
3699
+ }
3670
3700
  function stripParentShortcutColumns(row) {
3671
3701
  const out = {};
3672
3702
  for (const [k, v] of Object.entries(row)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rex0220/kintone-sql-tools",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "kintone SQL plugin and CLI tools (ksql)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  "prepack": "npm run build:cli",
26
26
  "start": "run-p develop upload",
27
27
  "develop": "node build.mjs --watch",
28
- "upload": "rex0220-plugin-uploader -f dist/ksql-plugin-v1.0.0.zip --watch"
28
+ "upload": "rex0220-plugin-uploader -f dist/ksql-plugin-v1.1.1.zip --watch"
29
29
  },
30
30
  "files": [
31
31
  "dist-cli/",