@cchistory/lite 0.4.5 → 0.5.0
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/INSTALL.md +1 -1
- package/apps/lite-cli/dist/agent-contract.d.ts +4 -5
- package/apps/lite-cli/dist/agent-contract.d.ts.map +1 -1
- package/apps/lite-cli/dist/agent-contract.js +32 -25
- package/apps/lite-cli/dist/agent-contract.js.map +1 -1
- package/apps/lite-cli/dist/bin.js +3 -3
- package/apps/lite-cli/dist/bin.js.map +1 -1
- package/apps/lite-cli/dist/index.d.ts.map +1 -1
- package/apps/lite-cli/dist/index.js +147 -66
- package/apps/lite-cli/dist/index.js.map +1 -1
- package/apps/lite-cli/dist/index.test.js +76 -60
- package/apps/lite-cli/dist/index.test.js.map +1 -1
- package/apps/lite-cli/dist/query.d.ts +4 -1
- package/apps/lite-cli/dist/query.d.ts.map +1 -1
- package/apps/lite-cli/dist/query.js +45 -29
- package/apps/lite-cli/dist/query.js.map +1 -1
- package/apps/lite-cli/dist/resource-errors.d.ts +3 -0
- package/apps/lite-cli/dist/resource-errors.d.ts.map +1 -0
- package/apps/lite-cli/dist/resource-errors.js +17 -0
- package/apps/lite-cli/dist/resource-errors.js.map +1 -0
- package/apps/lite-cli/dist/shell.d.ts +12 -2
- package/apps/lite-cli/dist/shell.d.ts.map +1 -1
- package/apps/lite-cli/dist/shell.js +129 -57
- package/apps/lite-cli/dist/shell.js.map +1 -1
- package/apps/lite-cli/dist/sql-query.test.d.ts +2 -0
- package/apps/lite-cli/dist/sql-query.test.d.ts.map +1 -0
- package/apps/lite-cli/dist/sql-query.test.js +290 -0
- package/apps/lite-cli/dist/sql-query.test.js.map +1 -0
- package/apps/lite-cli/dist/version.d.ts +1 -1
- package/apps/lite-cli/dist/version.js +1 -1
- package/apps/lite-tui/dist/bin.js +3 -3
- package/apps/lite-tui/dist/bin.js.map +1 -1
- package/apps/lite-tui/dist/index.d.ts.map +1 -1
- package/apps/lite-tui/dist/index.js +2 -2
- package/apps/lite-tui/dist/index.js.map +1 -1
- package/apps/lite-tui/dist/index.test.js +5 -3
- package/apps/lite-tui/dist/index.test.js.map +1 -1
- package/apps/lite-tui/dist/render.d.ts +1 -1
- package/apps/lite-tui/dist/version.d.ts +1 -1
- package/apps/lite-tui/dist/version.js +1 -1
- package/bin/cchistory-lite-tui.mjs +3 -3
- package/bin/cchistory-lite.mjs +3 -3
- package/docs/guide/for-agents.md +65 -46
- package/docs/guide/lite.md +49 -11
- package/docs/guide/queries/latest-sessions.sql +4 -0
- package/docs/guide/queries/latest-turns.sql +1 -0
- package/docs/guide/queries/list-sessions.sql +2 -0
- package/docs/guide/query.md +153 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts +7 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/directory-scope.js +11 -0
- package/node_modules/@cchistory/canonical/dist/directory-scope.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts +5 -1
- package/node_modules/@cchistory/canonical/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/index.js +5 -1
- package/node_modules/@cchistory/canonical/dist/index.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/query.d.ts +15 -0
- package/node_modules/@cchistory/canonical/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/query.js +208 -0
- package/node_modules/@cchistory/canonical/dist/query.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts +1 -0
- package/node_modules/@cchistory/canonical/dist/session-family.d.ts.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.js +3 -0
- package/node_modules/@cchistory/canonical/dist/session-family.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-family.test.js +61 -0
- package/node_modules/@cchistory/canonical/dist/session-family.test.js.map +1 -1
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts +30 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js +713 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.js.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts +2 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.d.ts.map +1 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js +56 -0
- package/node_modules/@cchistory/canonical/dist/session-interpreter.test.js.map +1 -0
- package/node_modules/@cchistory/canonical/package.json +1 -1
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts +7 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js +36 -0
- package/node_modules/@cchistory/domain/dist/evidence-atoms.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts +26 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js +80 -0
- package/node_modules/@cchistory/domain/dist/evidence-values.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/domain/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/domain/dist/index.js +5 -0
- package/node_modules/@cchistory/domain/dist/index.js.map +1 -1
- package/node_modules/@cchistory/domain/dist/masks.d.ts +31 -0
- package/node_modules/@cchistory/domain/dist/masks.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/masks.js +342 -0
- package/node_modules/@cchistory/domain/dist/masks.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts +58 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js +2 -0
- package/node_modules/@cchistory/domain/dist/parsed-session.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts +67 -0
- package/node_modules/@cchistory/domain/dist/query.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/query.js +2 -0
- package/node_modules/@cchistory/domain/dist/query.js.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts +14 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js +247 -0
- package/node_modules/@cchistory/domain/dist/token-evidence.js.map +1 -0
- package/node_modules/@cchistory/domain/package.json +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts +0 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js +0 -1
- package/node_modules/@cchistory/live-runtime/dist/bootstrap.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts +30 -9
- package/node_modules/@cchistory/live-runtime/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.js +263 -142
- package/node_modules/@cchistory/live-runtime/dist/index.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/index.test.js +177 -20
- package/node_modules/@cchistory/live-runtime/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts +16 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js +55 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js +192 -0
- package/node_modules/@cchistory/live-runtime/dist/preparation-metadata.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts +21 -22
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js +53 -41
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js +266 -57
- package/node_modules/@cchistory/live-runtime/dist/scan-guard.test.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts +47 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js +15 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js +166 -0
- package/node_modules/@cchistory/live-runtime/dist/selective-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts +37 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js +301 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js +67 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-query.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js +14 -0
- package/node_modules/@cchistory/live-runtime/dist/sql-worker.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts +13 -10
- package/node_modules/@cchistory/live-runtime/dist/system-memory.d.ts.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js +61 -34
- package/node_modules/@cchistory/live-runtime/dist/system-memory.js.map +1 -1
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts +2 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.d.ts.map +1 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js +76 -0
- package/node_modules/@cchistory/live-runtime/dist/system-memory.test.js.map +1 -0
- package/node_modules/@cchistory/live-runtime/package.json +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/discovery.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts +2 -4
- package/node_modules/@cchistory/source-adapters/dist/core/factories.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js +1 -23
- package/node_modules/@cchistory/source-adapters/dist/core/factories.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts +25 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js +80 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js +122 -0
- package/node_modules/@cchistory/source-adapters/dist/core/file-read-plan.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js +2 -11
- package/node_modules/@cchistory/source-adapters/dist/core/git-project.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js +4 -4
- package/node_modules/@cchistory/source-adapters/dist/core/parser.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts +8 -6
- package/node_modules/@cchistory/source-adapters/dist/core/probe.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js +54 -36
- package/node_modules/@cchistory/source-adapters/dist/core/probe.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts +2 -28
- package/node_modules/@cchistory/source-adapters/dist/core/projections.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js +2 -695
- package/node_modules/@cchistory/source-adapters/dist/core/projections.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/projections.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts +18 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js +27 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js +75 -0
- package/node_modules/@cchistory/source-adapters/dist/core/read-budget.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/session-grouping.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/source-identity.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts +1 -13
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js +1 -246
- package/node_modules/@cchistory/source-adapters/dist/core/token-usage.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/tokens.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts +1 -25
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js +1 -79
- package/node_modules/@cchistory/source-adapters/dist/core/type-guards.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts +6 -35
- package/node_modules/@cchistory/source-adapters/dist/core/types.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js +14 -10
- package/node_modules/@cchistory/source-adapters/dist/core/vscode-state.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts +6 -0
- package/node_modules/@cchistory/source-adapters/dist/index.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.js +4 -0
- package/node_modules/@cchistory/source-adapters/dist/index.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/index.test.js +2 -0
- package/node_modules/@cchistory/source-adapters/dist/index.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts +1 -30
- package/node_modules/@cchistory/source-adapters/dist/masks.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/masks.js +1 -341
- package/node_modules/@cchistory/source-adapters/dist/masks.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/accio.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/amp.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/antigravity.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/claude.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codebuddy.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts +14 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js +103 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex/activity-evidence.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/codex.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js +5 -3
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor-agent.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/cursor.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/factory-droid.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/gemini.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js +24 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/grok.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/kimi.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/lobechat.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/openclaw.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/opencode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.d.ts.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js +11 -9
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode/runtime.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js +2 -1
- package/node_modules/@cchistory/source-adapters/dist/platforms/zcode.test.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts +8 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.d.ts.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js +7 -0
- package/node_modules/@cchistory/source-adapters/dist/probe-reference.test.js.map +1 -0
- package/node_modules/@cchistory/source-adapters/dist/test-helpers.js.map +1 -1
- package/node_modules/@cchistory/source-adapters/package.json +1 -1
- package/node_modules/commander/LICENSE +22 -0
- package/node_modules/commander/Readme.md +428 -0
- package/node_modules/commander/index.js +1224 -0
- package/node_modules/commander/package.json +38 -0
- package/node_modules/commander/typings/index.d.ts +310 -0
- package/node_modules/discontinuous-range/.npmignore +28 -0
- package/node_modules/discontinuous-range/.travis.yml +4 -0
- package/node_modules/discontinuous-range/LICENSE +21 -0
- package/node_modules/discontinuous-range/README.md +23 -0
- package/node_modules/discontinuous-range/index.js +144 -0
- package/node_modules/discontinuous-range/package.json +27 -0
- package/node_modules/discontinuous-range/test/main-test.js +96 -0
- package/node_modules/moo/LICENSE +29 -0
- package/node_modules/moo/README.md +385 -0
- package/node_modules/moo/moo.js +645 -0
- package/node_modules/moo/package.json +29 -0
- package/node_modules/nearley/LICENSE.txt +21 -0
- package/node_modules/nearley/README.md +80 -0
- package/node_modules/nearley/bin/nearley-railroad.js +121 -0
- package/node_modules/nearley/bin/nearley-test.js +64 -0
- package/node_modules/nearley/bin/nearley-unparse.js +29 -0
- package/node_modules/nearley/bin/nearleyc.js +38 -0
- package/node_modules/nearley/builtin/cow.ne +2 -0
- package/node_modules/nearley/builtin/number.ne +51 -0
- package/node_modules/nearley/builtin/postprocessors.ne +36 -0
- package/node_modules/nearley/builtin/string.ne +26 -0
- package/node_modules/nearley/builtin/whitespace.ne +5 -0
- package/node_modules/nearley/lib/compile.js +307 -0
- package/node_modules/nearley/lib/generate.js +244 -0
- package/node_modules/nearley/lib/lint.js +28 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.js +132 -0
- package/node_modules/nearley/lib/nearley-language-bootstrapped.ne +126 -0
- package/node_modules/nearley/lib/nearley.js +564 -0
- package/node_modules/nearley/lib/stream.js +18 -0
- package/node_modules/nearley/lib/unparse.js +139 -0
- package/node_modules/nearley/package.json +63 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts +237 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-mapper.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/ast-visitor.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.d.ts +11 -0
- package/node_modules/pgsql-ast-parser/index.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/index.js +6484 -0
- package/node_modules/pgsql-ast-parser/index.js.map +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts +1 -0
- package/node_modules/pgsql-ast-parser/interfaces.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/keywords.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts +15 -0
- package/node_modules/pgsql-ast-parser/lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/lexer.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/array.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/geometric.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts +10 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-builder.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-iso.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval-lexer.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/literal-syntaxes/interval.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/package.json +69 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts +33 -0
- package/node_modules/pgsql-ast-parser/parser.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts +2 -0
- package/node_modules/pgsql-ast-parser/pg-escape.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/readme.md +255 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.spec.ts +296 -0
- package/node_modules/pgsql-ast-parser/src/ast-mapper.ts +1378 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.spec.ts +57 -0
- package/node_modules/pgsql-ast-parser/src/ast-visitor.ts +101 -0
- package/node_modules/pgsql-ast-parser/src/index.ts +10 -0
- package/node_modules/pgsql-ast-parser/src/interfaces.ts +0 -0
- package/node_modules/pgsql-ast-parser/src/keywords.ts +8 -0
- package/node_modules/pgsql-ast-parser/src/lexer.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/lexer.ts +267 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array-lexer.ts +27 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/array.spec.ts +55 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.ne +88 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/geometric.spec.ts +131 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-builder.ts +148 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso-lexer.ts +17 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-iso.ne +53 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval-lexer.ts +26 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.ne +54 -0
- package/node_modules/pgsql-ast-parser/src/literal-syntaxes/interval.spec.ts +106 -0
- package/node_modules/pgsql-ast-parser/src/parser.ts +142 -0
- package/node_modules/pgsql-ast-parser/src/pg-escape.ts +14 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.ne +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-index.spec.ts +35 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.ne +123 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-table.spec.ts +476 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.ne +33 -0
- package/node_modules/pgsql-ast-parser/src/syntax/alter-type.spec.ts +29 -0
- package/node_modules/pgsql-ast-parser/src/syntax/ast.ts +1150 -0
- package/node_modules/pgsql-ast-parser/src/syntax/base.ne +369 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.ne +17 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-extension.spec.ts +37 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.ne +62 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-index.spec.ts +245 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.ne +174 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-table.spec.ts +761 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.ne +40 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-type.spec.ts +32 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.ne +68 -0
- package/node_modules/pgsql-ast-parser/src/syntax/create-view.spec.ts +187 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.ne +13 -0
- package/node_modules/pgsql-ast-parser/src/syntax/deallocate.spec.ts +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.ne +36 -0
- package/node_modules/pgsql-ast-parser/src/syntax/delete.spec.ts +71 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.ne +28 -0
- package/node_modules/pgsql-ast-parser/src/syntax/drop.spec.ts +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/edge-cases.spec.ts +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.ne +350 -0
- package/node_modules/pgsql-ast-parser/src/syntax/expr.spec.ts +1638 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.ne +114 -0
- package/node_modules/pgsql-ast-parser/src/syntax/functions.spec.ts +235 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.ne +63 -0
- package/node_modules/pgsql-ast-parser/src/syntax/insert.spec.ts +292 -0
- package/node_modules/pgsql-ast-parser/src/syntax/main.ne +77 -0
- package/node_modules/pgsql-ast-parser/src/syntax/nearley.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.ne +8 -0
- package/node_modules/pgsql-ast-parser/src/syntax/prepare.spec.ts +44 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.ne +19 -0
- package/node_modules/pgsql-ast-parser/src/syntax/refresh-materialized-view.spec.ts +42 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.ne +223 -0
- package/node_modules/pgsql-ast-parser/src/syntax/select.spec.ts +1063 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.ne +101 -0
- package/node_modules/pgsql-ast-parser/src/syntax/sequence.spec.ts +103 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.ne +168 -0
- package/node_modules/pgsql-ast-parser/src/syntax/simple-statements.spec.ts +327 -0
- package/node_modules/pgsql-ast-parser/src/syntax/spec-utils.ts +333 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.ne +18 -0
- package/node_modules/pgsql-ast-parser/src/syntax/union.spec.ts +125 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.ne +56 -0
- package/node_modules/pgsql-ast-parser/src/syntax/update.spec.ts +87 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.ne +41 -0
- package/node_modules/pgsql-ast-parser/src/syntax/with.spec.ts +155 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.spec.ts +85 -0
- package/node_modules/pgsql-ast-parser/src/to-sql.ts +1555 -0
- package/node_modules/pgsql-ast-parser/src/utils.ts +47 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/alter-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts +826 -0
- package/node_modules/pgsql-ast-parser/syntax/ast.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-extension.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-index.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-table.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-type.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/create-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/deallocate.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/delete.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/drop.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/edge-cases.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/expr.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/functions.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/insert.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts +29 -0
- package/node_modules/pgsql-ast-parser/syntax/main.ne.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/prepare.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/refresh-materialized-view.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/select.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/sequence.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/simple-statements.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts +35 -0
- package/node_modules/pgsql-ast-parser/syntax/spec-utils.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/union.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/update.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/syntax/with.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts +7 -0
- package/node_modules/pgsql-ast-parser/to-sql.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts +3 -0
- package/node_modules/pgsql-ast-parser/to-sql.spec.d.ts.map +1 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts +16 -0
- package/node_modules/pgsql-ast-parser/utils.d.ts.map +1 -0
- package/node_modules/railroad-diagrams/.gitattributes +22 -0
- package/node_modules/railroad-diagrams/.npmignore +163 -0
- package/node_modules/railroad-diagrams/README.md +86 -0
- package/node_modules/railroad-diagrams/css-example.py-js +183 -0
- package/node_modules/railroad-diagrams/example.html +141 -0
- package/node_modules/railroad-diagrams/generator.html +59 -0
- package/node_modules/railroad-diagrams/package.json +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.css +23 -0
- package/node_modules/railroad-diagrams/railroad-diagrams.js +524 -0
- package/node_modules/railroad-diagrams/railroad_diagrams.py +427 -0
- package/node_modules/randexp/LICENSE +19 -0
- package/node_modules/randexp/README.md +134 -0
- package/node_modules/randexp/lib/randexp.js +245 -0
- package/node_modules/randexp/package.json +48 -0
- package/node_modules/ret/LICENSE +19 -0
- package/node_modules/ret/README.md +183 -0
- package/node_modules/ret/lib/index.js +282 -0
- package/node_modules/ret/lib/positions.js +17 -0
- package/node_modules/ret/lib/sets.js +82 -0
- package/node_modules/ret/lib/types.js +10 -0
- package/node_modules/ret/lib/util.js +111 -0
- package/node_modules/ret/package.json +35 -0
- package/package.json +22 -6
- package/schemas/cchistory-lite-agent-v1.schema.json +6 -7
- package/schemas/cchistory-lite-error-v1.schema.json +58 -8
- package/schemas/cchistory-lite-query-result-v2.schema.json +66 -11
- package/schemas/cchistory-lite-query-result-v3.schema.json +219 -0
- package/schemas/cchistory-lite-query-v3.schema.json +57 -0
- package/schemas/cchistory-lite-source-inventory-v1.schema.json +72 -0
- package/skills/using-cchistory-lite/SKILL.md +125 -55
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts +0 -8
- package/node_modules/@cchistory/live-runtime/dist/node-memory.d.ts.map +0 -1
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js +0 -110
- package/node_modules/@cchistory/live-runtime/dist/node-memory.js.map +0 -1
|
@@ -0,0 +1,1555 @@
|
|
|
1
|
+
import { IAstPartialMapper, AstDefaultMapper } from './ast-mapper';
|
|
2
|
+
import { astVisitor, IAstVisitor, IAstFullVisitor } from './ast-visitor';
|
|
3
|
+
import { NotSupported, nil, ReplaceReturnType, NoExtraProperties } from './utils';
|
|
4
|
+
import { TableConstraint, JoinClause, ColumnConstraint, AlterSequenceStatement, CreateSequenceStatement, AlterSequenceSetOptions, CreateSequenceOptions, QName, SetGlobalValue, AlterColumnAddGenerated, QColumn, Name, OrderByStatement, QNameAliased } from './syntax/ast';
|
|
5
|
+
import { literal } from './pg-escape';
|
|
6
|
+
import { sqlKeywords } from './keywords';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export type IAstToSql = { readonly [key in keyof IAstPartialMapper]-?: ReplaceReturnType<IAstPartialMapper[key], string> }
|
|
11
|
+
|
|
12
|
+
const kwSet = new Set(sqlKeywords.map(x => x.toLowerCase()));
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
let ret: string[] = [];
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function name<T extends Name>(nm: NoExtraProperties<Name, T>) {
|
|
19
|
+
return ident(nm.name);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function ident(nm: string, forceDoubleQuote?: boolean) {
|
|
23
|
+
if (!forceDoubleQuote) {
|
|
24
|
+
// only add quotes if has upper cases, or if it is a keyword.
|
|
25
|
+
const low = nm.toLowerCase();
|
|
26
|
+
if (low === nm && !kwSet.has(low) && /^[a-z][a-z0-9_]*$/.test(low)) {
|
|
27
|
+
return nm;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return '"' + nm + '"';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function list<T>(elems: T[], act: (e: T) => any, addParen: boolean) {
|
|
34
|
+
if (addParen) {
|
|
35
|
+
ret.push('(');
|
|
36
|
+
}
|
|
37
|
+
let first = true;
|
|
38
|
+
for (const e of elems) {
|
|
39
|
+
if (!first) {
|
|
40
|
+
ret.push(', ');
|
|
41
|
+
}
|
|
42
|
+
first = false;
|
|
43
|
+
act(e);
|
|
44
|
+
}
|
|
45
|
+
if (addParen) {
|
|
46
|
+
ret.push(')');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function addConstraint(c: ColumnConstraint | TableConstraint, m: IAstVisitor) {
|
|
52
|
+
switch (c.type) {
|
|
53
|
+
case 'foreign key':
|
|
54
|
+
ret.push(' foreign key ('
|
|
55
|
+
, ...c.localColumns.map(name).join(', ')
|
|
56
|
+
, ')');
|
|
57
|
+
// 👈 There is no "break" here... that's not an error, we want to fall throught the 'reference' case
|
|
58
|
+
case 'reference':
|
|
59
|
+
ret.push(' REFERENCES ');
|
|
60
|
+
m.tableRef(c.foreignTable);
|
|
61
|
+
ret.push('('
|
|
62
|
+
, ...c.foreignColumns.map(name).join(', ')
|
|
63
|
+
, ') ');
|
|
64
|
+
if (c.match) {
|
|
65
|
+
ret.push(' MATCH ', c.match.toUpperCase());
|
|
66
|
+
}
|
|
67
|
+
if (c.onDelete) {
|
|
68
|
+
ret.push(' ON DELETE ', c.onDelete);
|
|
69
|
+
}
|
|
70
|
+
if (c.onUpdate) {
|
|
71
|
+
ret.push(' ON UPDATE ', c.onUpdate);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case 'primary key':
|
|
75
|
+
case 'unique':
|
|
76
|
+
ret.push(' ', c.type, ' ');
|
|
77
|
+
if ('columns' in c) {
|
|
78
|
+
ret.push('('
|
|
79
|
+
, ...c.columns.map(name).join(', ')
|
|
80
|
+
, ') ');
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case 'check':
|
|
84
|
+
ret.push(' check ');
|
|
85
|
+
m.expr(c.expr);
|
|
86
|
+
break;
|
|
87
|
+
case 'not null':
|
|
88
|
+
case 'null':
|
|
89
|
+
ret.push(' ', c.type, ' ');
|
|
90
|
+
break;
|
|
91
|
+
case 'default':
|
|
92
|
+
ret.push(' default ');
|
|
93
|
+
m.expr(c.default);
|
|
94
|
+
break;
|
|
95
|
+
case 'add generated':
|
|
96
|
+
ret.push(' GENERATED ');
|
|
97
|
+
visitGenerated(m, c);
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
throw NotSupported.never(c)
|
|
101
|
+
}
|
|
102
|
+
ret.push(' ');
|
|
103
|
+
}
|
|
104
|
+
function visitQualifiedName(cs: QName, forceDoubleQuote?: boolean) {
|
|
105
|
+
if (cs.schema) {
|
|
106
|
+
ret.push(ident(cs.schema), '.');
|
|
107
|
+
}
|
|
108
|
+
ret.push(ident(cs.name, forceDoubleQuote), ' ');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function visitQualifiedNameAliased(cs: QNameAliased) {
|
|
112
|
+
visitQualifiedName(cs);
|
|
113
|
+
if (cs.alias) {
|
|
114
|
+
ret.push(' AS ', ident(cs.alias), ' ');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function visitOrderBy(m: IAstVisitor, orderBy: OrderByStatement[]) {
|
|
119
|
+
ret.push(' ORDER BY ');
|
|
120
|
+
list(orderBy, e => {
|
|
121
|
+
m.expr(e.by);
|
|
122
|
+
if (e.order) {
|
|
123
|
+
ret.push(' ', e.order, ' ');
|
|
124
|
+
}
|
|
125
|
+
if (e.nulls) {
|
|
126
|
+
ret.push(' NULLS ', e.nulls, ' ')
|
|
127
|
+
}
|
|
128
|
+
}, false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function visitSetVal(set: SetGlobalValue) {
|
|
132
|
+
|
|
133
|
+
switch (set.type) {
|
|
134
|
+
case 'default':
|
|
135
|
+
ret.push('DEFAULT ');
|
|
136
|
+
break;
|
|
137
|
+
case 'identifier':
|
|
138
|
+
ret.push(set.name);
|
|
139
|
+
break;
|
|
140
|
+
case 'list':
|
|
141
|
+
let first = true;
|
|
142
|
+
for (const v of set.values) {
|
|
143
|
+
if (!first) {
|
|
144
|
+
ret.push(', ');
|
|
145
|
+
}
|
|
146
|
+
first = false;
|
|
147
|
+
visitSetVal(v);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case 'value':
|
|
151
|
+
ret.push(typeof set.value === 'number' ? set.value.toString() : literal(set.value));
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
throw NotSupported.never(set);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function visitGenerated(m: IAstVisitor, alter: AlterColumnAddGenerated) {
|
|
159
|
+
if (alter.always) {
|
|
160
|
+
ret.push(alter.always.toUpperCase(), ' ');
|
|
161
|
+
}
|
|
162
|
+
ret.push('AS ');
|
|
163
|
+
if (alter.expression) {
|
|
164
|
+
ret.push('(');
|
|
165
|
+
m.expr(alter.expression);
|
|
166
|
+
ret.push(') ');
|
|
167
|
+
} else {
|
|
168
|
+
ret.push('IDENTITY ');
|
|
169
|
+
}
|
|
170
|
+
if (alter.sequence) {
|
|
171
|
+
ret.push('(');
|
|
172
|
+
if (alter.sequence.name) {
|
|
173
|
+
ret.push('SEQUENCE NAME ');
|
|
174
|
+
visitQualifiedName(alter.sequence.name);
|
|
175
|
+
ret.push(' ');
|
|
176
|
+
}
|
|
177
|
+
visitSeqOpts(m, alter.sequence);
|
|
178
|
+
ret.push(') ');
|
|
179
|
+
}
|
|
180
|
+
if (alter.stored) {
|
|
181
|
+
ret.push('STORED ');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function visitSeqOpts(m: IAstVisitor, cs: AlterSequenceSetOptions | CreateSequenceOptions) {
|
|
185
|
+
if (cs.as) {
|
|
186
|
+
ret.push('AS ');
|
|
187
|
+
m.dataType(cs.as);
|
|
188
|
+
ret.push(' ');
|
|
189
|
+
}
|
|
190
|
+
if (typeof cs.incrementBy === 'number') {
|
|
191
|
+
ret.push('INCREMENT BY ', cs.incrementBy.toString(), ' ');
|
|
192
|
+
}
|
|
193
|
+
if (cs.minValue === 'no minvalue') {
|
|
194
|
+
ret.push('NO MINVALUE ');
|
|
195
|
+
}
|
|
196
|
+
if (typeof cs.minValue === 'number') {
|
|
197
|
+
ret.push('MINVALUE ', cs.minValue.toString(), ' ');
|
|
198
|
+
}
|
|
199
|
+
if (cs.maxValue === 'no maxvalue') {
|
|
200
|
+
ret.push('NO MAXVALUE ');
|
|
201
|
+
}
|
|
202
|
+
if (typeof cs.maxValue === 'number') {
|
|
203
|
+
ret.push('MAXVALUE ', cs.maxValue.toString(), ' ');
|
|
204
|
+
}
|
|
205
|
+
if (typeof cs.startWith === 'number') {
|
|
206
|
+
ret.push('START WITH ', cs.startWith.toString(), ' ');
|
|
207
|
+
}
|
|
208
|
+
if (typeof cs.cache === 'number') {
|
|
209
|
+
ret.push('CACHE ', cs.cache.toString(), ' ');
|
|
210
|
+
}
|
|
211
|
+
if (cs.cycle) {
|
|
212
|
+
ret.push(cs.cycle, ' ');
|
|
213
|
+
}
|
|
214
|
+
if (cs.ownedBy === 'none') {
|
|
215
|
+
ret.push('OWNED BY NONE ');
|
|
216
|
+
} else if (cs.ownedBy) {
|
|
217
|
+
ret.push('OWNED BY ');
|
|
218
|
+
visitQColumn(cs.ownedBy);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if ('restart' in cs) {
|
|
222
|
+
if (cs.restart === true) {
|
|
223
|
+
ret.push('RESTART ')
|
|
224
|
+
} else if (cs.restart) {
|
|
225
|
+
ret.push('RESTART WITH ', cs.restart.toString(), ' ');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function visitQColumn(col: QColumn) {
|
|
231
|
+
if (col.schema) {
|
|
232
|
+
ret.push(ident(col.schema), '.');
|
|
233
|
+
}
|
|
234
|
+
ret.push(ident(col.table), '.', ident(col.column), ' ');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function join(m: IAstVisitor, j: JoinClause | nil, tbl: () => void) {
|
|
238
|
+
if (!j) {
|
|
239
|
+
tbl();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
ret.push(j.type, ' ');
|
|
243
|
+
tbl();
|
|
244
|
+
if (j.on) {
|
|
245
|
+
ret.push('ON ')
|
|
246
|
+
m.expr(j.on);
|
|
247
|
+
}
|
|
248
|
+
if (j.using) {
|
|
249
|
+
ret.push('USING (');
|
|
250
|
+
list(j.using, x => ret.push(name(x)), false);
|
|
251
|
+
ret.push(') ');
|
|
252
|
+
}
|
|
253
|
+
ret.push(' ');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function visitOp(v: { op: string; opSchema?: string; }) {
|
|
257
|
+
if (v.opSchema) {
|
|
258
|
+
ret.push(' operator(', ident(v.opSchema), '.', v.op, ') ');
|
|
259
|
+
} else {
|
|
260
|
+
ret.push(' ', v.op, ' ');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const visitor = astVisitor<IAstFullVisitor>(m => ({
|
|
265
|
+
|
|
266
|
+
addColumn: (...args) => {
|
|
267
|
+
ret.push(' ADD COLUMN ');
|
|
268
|
+
if (args[0].ifNotExists) {
|
|
269
|
+
ret.push('IF NOT EXISTS ');
|
|
270
|
+
}
|
|
271
|
+
m.super().addColumn(...args);
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
createExtension: e => {
|
|
275
|
+
ret.push('CREATE EXTENSION ');
|
|
276
|
+
if (e.ifNotExists) {
|
|
277
|
+
ret.push(' IF NOT EXISTS ');
|
|
278
|
+
}
|
|
279
|
+
ret.push(name(e.extension));
|
|
280
|
+
if (!e.from && !e.version && !e.schema) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
ret.push(' WITH');
|
|
284
|
+
if (e.schema) {
|
|
285
|
+
ret.push(' SCHEMA ', name(e.schema));
|
|
286
|
+
}
|
|
287
|
+
if (e.version) {
|
|
288
|
+
ret.push(' VERSION ', literal(e.version.value));
|
|
289
|
+
}
|
|
290
|
+
if (e.from) {
|
|
291
|
+
ret.push(' FROM ', literal(e.from.value));
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
tablespace: t => {
|
|
296
|
+
ret.push('TABLESPACE ', name(t.tablespace));
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
addConstraint: c => {
|
|
300
|
+
ret.push(' ADD ');
|
|
301
|
+
const cname = c.constraint.constraintName;
|
|
302
|
+
if (cname) {
|
|
303
|
+
ret.push(' CONSTRAINT ', name(cname), ' ');
|
|
304
|
+
}
|
|
305
|
+
addConstraint(c.constraint, m);
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
alterColumn: (c, t) => {
|
|
309
|
+
ret.push(' ALTER COLUMN ', name(c.column), ' ');
|
|
310
|
+
m.super().alterColumn(c, t);
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
setColumnDefault: (a, t, c) => {
|
|
314
|
+
ret.push(' SET DEFAULT ');
|
|
315
|
+
m.expr(a.default);
|
|
316
|
+
if (a.updateExisting) {
|
|
317
|
+
throw new Error('Not implemented: updateExisting on set column default');
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
createEnum: t => {
|
|
322
|
+
ret.push('CREATE TYPE ');
|
|
323
|
+
visitQualifiedName(t.name);
|
|
324
|
+
ret.push(' AS ENUM ');
|
|
325
|
+
list(t.values, x => ret.push(literal(x.value)), true);
|
|
326
|
+
ret.push(' ');
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
alterEnum: t => {
|
|
330
|
+
ret.push('ALTER TYPE ');
|
|
331
|
+
visitQualifiedName(t.name);
|
|
332
|
+
if (t.change.type === 'rename') {
|
|
333
|
+
ret.push(' RENAME TO ');
|
|
334
|
+
visitQualifiedName(t.change.to);
|
|
335
|
+
} else {
|
|
336
|
+
ret.push(' ADD VALUE ', literal(t.change.add.value));
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
createCompositeType: c => {
|
|
341
|
+
ret.push('CREATE TYPE ');
|
|
342
|
+
visitQualifiedName(c.name);
|
|
343
|
+
ret.push(' AS ');
|
|
344
|
+
list(c.attributes, x => {
|
|
345
|
+
ret.push(name(x.name), ' ');
|
|
346
|
+
m.dataType(x.dataType);
|
|
347
|
+
if (x.collate) {
|
|
348
|
+
ret.push('COLLATE ');
|
|
349
|
+
visitQualifiedName(x.collate);
|
|
350
|
+
}
|
|
351
|
+
}, true);
|
|
352
|
+
ret.push(' ');
|
|
353
|
+
},
|
|
354
|
+
|
|
355
|
+
setTableOwner: o => {
|
|
356
|
+
ret.push(' OWNER TO ', name(o.to));
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
alterColumnSimple: c => ret.push(c.type),
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
alterColumnAddGenerated: (alter) => {
|
|
364
|
+
ret.push(' ADD GENERATED ');
|
|
365
|
+
visitGenerated(m, alter)
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
setColumnType: t => {
|
|
369
|
+
ret.push(' SET DATA TYPE ');
|
|
370
|
+
m.dataType(t.dataType);
|
|
371
|
+
ret.push(' ');
|
|
372
|
+
},
|
|
373
|
+
|
|
374
|
+
alterTable: t => {
|
|
375
|
+
ret.push('ALTER TABLE ');
|
|
376
|
+
if (t.ifExists) {
|
|
377
|
+
ret.push(' IF EXISTS ');
|
|
378
|
+
}
|
|
379
|
+
if (t.only) {
|
|
380
|
+
ret.push(' ONLY ');
|
|
381
|
+
}
|
|
382
|
+
visitQualifiedNameAliased(t.table);
|
|
383
|
+
list(t.changes, change => m.tableAlteration(change, t.table), false);
|
|
384
|
+
},
|
|
385
|
+
|
|
386
|
+
alterIndex: t => {
|
|
387
|
+
ret.push('ALTER INDEX ');
|
|
388
|
+
if (t.ifExists) {
|
|
389
|
+
ret.push(' IF EXISTS ');
|
|
390
|
+
}
|
|
391
|
+
visitQualifiedNameAliased(t.index);
|
|
392
|
+
switch (t.change.type) {
|
|
393
|
+
case 'rename':
|
|
394
|
+
ret.push(' RENAME TO ');
|
|
395
|
+
visitQualifiedName(t.change.to);
|
|
396
|
+
ret.push(' ');
|
|
397
|
+
break;
|
|
398
|
+
case 'set tablespace':
|
|
399
|
+
ret.push(' SET TABLESPACE ');
|
|
400
|
+
visitQualifiedName(t.change.tablespace);
|
|
401
|
+
ret.push(' ');
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
throw NotSupported.never(t.change, 'Alter index type not supported: ');
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
tableAlteration: (change, table) => {
|
|
409
|
+
switch (change.type) {
|
|
410
|
+
case 'add column':
|
|
411
|
+
return m.addColumn(change, table);
|
|
412
|
+
case 'add constraint':
|
|
413
|
+
return m.addConstraint(change, table);
|
|
414
|
+
case 'alter column':
|
|
415
|
+
return m.alterColumn(change, table);
|
|
416
|
+
case 'rename':
|
|
417
|
+
return m.renameTable(change, table);
|
|
418
|
+
case 'rename column':
|
|
419
|
+
return m.renameColumn(change, table);
|
|
420
|
+
case 'rename constraint':
|
|
421
|
+
return m.renameConstraint(change, table);
|
|
422
|
+
case 'drop column':
|
|
423
|
+
return m.dropColumn(change, table);
|
|
424
|
+
case 'drop constraint':
|
|
425
|
+
return m.dropConstraint(change, table);
|
|
426
|
+
case 'owner':
|
|
427
|
+
return m.setTableOwner(change, table);
|
|
428
|
+
default:
|
|
429
|
+
throw NotSupported.never(change);
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
array: v => {
|
|
434
|
+
ret.push(v.type === 'array' ? 'ARRAY[' : '(');
|
|
435
|
+
list(v.expressions, e => m.expr(e), false);
|
|
436
|
+
ret.push(v.type === 'array' ? ']' : ')');
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
arrayIndex: v => {
|
|
440
|
+
m.expr(v.array);
|
|
441
|
+
ret.push('[');
|
|
442
|
+
m.expr(v.index);
|
|
443
|
+
ret.push('] ');
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
expr: e => {
|
|
447
|
+
if (e.type === 'ref') {
|
|
448
|
+
m.ref(e);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
// lists can become incorrect with an additional set of parentheses
|
|
452
|
+
if (e.type === 'list') {
|
|
453
|
+
m.super().expr(e);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// this forces to respect precedence
|
|
458
|
+
// (however, it will introduce lots of unecessary parenthesis)
|
|
459
|
+
ret.push('(');
|
|
460
|
+
m.super().expr(e);
|
|
461
|
+
ret.push(')');
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
callOverlay: o => {
|
|
465
|
+
ret.push('OVERLAY(');
|
|
466
|
+
m.expr(o.value);
|
|
467
|
+
ret.push(' PLACING ');
|
|
468
|
+
m.expr(o.placing);
|
|
469
|
+
ret.push(' FROM ');
|
|
470
|
+
m.expr(o.from);
|
|
471
|
+
if (o.for) {
|
|
472
|
+
ret.push(' FOR ');
|
|
473
|
+
m.expr(o.for);
|
|
474
|
+
}
|
|
475
|
+
ret.push(')');
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
callSubstring: s => {
|
|
479
|
+
ret.push('SUBSTRING(');
|
|
480
|
+
m.expr(s.value);
|
|
481
|
+
if (s.from) {
|
|
482
|
+
ret.push(' FROM ');
|
|
483
|
+
m.expr(s.from);
|
|
484
|
+
}
|
|
485
|
+
if (s.for) {
|
|
486
|
+
ret.push(' FOR ');
|
|
487
|
+
m.expr(s.for);
|
|
488
|
+
}
|
|
489
|
+
ret.push(')');
|
|
490
|
+
},
|
|
491
|
+
|
|
492
|
+
binary: v => {
|
|
493
|
+
m.expr(v.left);
|
|
494
|
+
visitOp(v);
|
|
495
|
+
m.expr(v.right);
|
|
496
|
+
},
|
|
497
|
+
|
|
498
|
+
call: v => {
|
|
499
|
+
visitQualifiedName(v.function);
|
|
500
|
+
ret.push('(');
|
|
501
|
+
if (v.distinct) {
|
|
502
|
+
ret.push(v.distinct, ' ');
|
|
503
|
+
}
|
|
504
|
+
list(v.args, e => m.expr(e), false);
|
|
505
|
+
if (v.orderBy) {
|
|
506
|
+
visitOrderBy(m, v.orderBy);
|
|
507
|
+
}
|
|
508
|
+
ret.push(') ');
|
|
509
|
+
if (v.filter) {
|
|
510
|
+
ret.push('filter (where ');
|
|
511
|
+
m.expr(v.filter);
|
|
512
|
+
ret.push(') ');
|
|
513
|
+
}
|
|
514
|
+
if (v.withinGroup) {
|
|
515
|
+
ret.push('WITHIN GROUP (');
|
|
516
|
+
visitOrderBy(m, [v.withinGroup]);
|
|
517
|
+
ret.push(') ');
|
|
518
|
+
}
|
|
519
|
+
if (v.over) {
|
|
520
|
+
ret.push('over (');
|
|
521
|
+
if (v.over.partitionBy) {
|
|
522
|
+
ret.push('PARTITION BY ');
|
|
523
|
+
list(v.over.partitionBy, x => m.expr(x), false);
|
|
524
|
+
ret.push(' ');
|
|
525
|
+
}
|
|
526
|
+
if (v.over.orderBy) {
|
|
527
|
+
visitOrderBy(m, v.over.orderBy);
|
|
528
|
+
ret.push(' ');
|
|
529
|
+
}
|
|
530
|
+
ret.push(') ');
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
|
|
534
|
+
case: c => {
|
|
535
|
+
ret.push('CASE ')
|
|
536
|
+
if (c.value) {
|
|
537
|
+
m.expr(c.value);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
for (const e of c.whens) {
|
|
541
|
+
ret.push(' WHEN ');
|
|
542
|
+
m.expr(e.when);
|
|
543
|
+
ret.push(' THEN ')
|
|
544
|
+
m.expr(e.value);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (c.else) {
|
|
548
|
+
ret.push(' ELSE ');
|
|
549
|
+
m.expr(c.else);
|
|
550
|
+
}
|
|
551
|
+
ret.push(' END ');
|
|
552
|
+
},
|
|
553
|
+
|
|
554
|
+
cast: c => {
|
|
555
|
+
m.expr(c.operand);
|
|
556
|
+
ret.push('::');
|
|
557
|
+
m.dataType(c.to);
|
|
558
|
+
},
|
|
559
|
+
|
|
560
|
+
constant: c => {
|
|
561
|
+
switch (c.type) {
|
|
562
|
+
case 'boolean':
|
|
563
|
+
ret.push(c.value ? 'true' : 'false');
|
|
564
|
+
break;
|
|
565
|
+
case 'integer':
|
|
566
|
+
ret.push(c.value.toString(10));
|
|
567
|
+
break;
|
|
568
|
+
case 'numeric':
|
|
569
|
+
ret.push(c.value.toString());
|
|
570
|
+
if (Number.isInteger(c.value)) {
|
|
571
|
+
ret.push('.');
|
|
572
|
+
}
|
|
573
|
+
break;
|
|
574
|
+
case 'null':
|
|
575
|
+
ret.push('null');
|
|
576
|
+
break;
|
|
577
|
+
case 'constant':
|
|
578
|
+
break;
|
|
579
|
+
case 'string':
|
|
580
|
+
ret.push(literal(c.value));
|
|
581
|
+
break;
|
|
582
|
+
default:
|
|
583
|
+
throw NotSupported.never(c);
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
|
|
587
|
+
valueKeyword: v => {
|
|
588
|
+
ret.push(v.keyword, ' ');
|
|
589
|
+
},
|
|
590
|
+
|
|
591
|
+
comment: c => {
|
|
592
|
+
ret.push('COMMENT ON ', c.on.type.toUpperCase(), ' ');
|
|
593
|
+
switch (c.on.type) {
|
|
594
|
+
case 'column':
|
|
595
|
+
visitQColumn(c.on.column);
|
|
596
|
+
break;
|
|
597
|
+
default:
|
|
598
|
+
visitQualifiedName(c.on.name);
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
ret.push(' IS ', literal(c.comment), ' ');
|
|
602
|
+
},
|
|
603
|
+
|
|
604
|
+
extract: v => {
|
|
605
|
+
ret.push('EXTRACT (', v.field.name.toUpperCase(), ' FROM ');
|
|
606
|
+
m.expr(v.from);
|
|
607
|
+
ret.push(') ');
|
|
608
|
+
},
|
|
609
|
+
|
|
610
|
+
createColumn: c => {
|
|
611
|
+
ret.push(name(c.name), ' ');
|
|
612
|
+
m.dataType(c.dataType);
|
|
613
|
+
ret.push(' ');
|
|
614
|
+
if (c.collate) {
|
|
615
|
+
ret.push('COLLATE ');
|
|
616
|
+
visitQualifiedName(c.collate);
|
|
617
|
+
}
|
|
618
|
+
for (const cst of c.constraints ?? []) {
|
|
619
|
+
m.constraint(cst);
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
|
|
623
|
+
begin: beg => {
|
|
624
|
+
ret.push('BEGIN ');
|
|
625
|
+
if (beg.isolationLevel) {
|
|
626
|
+
ret.push('ISOLATION LEVEL ', beg.isolationLevel.toUpperCase(), ' ');
|
|
627
|
+
}
|
|
628
|
+
if (beg.writeable) {
|
|
629
|
+
ret.push(beg.writeable.toUpperCase(), ' ');
|
|
630
|
+
}
|
|
631
|
+
if (typeof beg.deferrable === 'boolean') {
|
|
632
|
+
if (!beg.deferrable) {
|
|
633
|
+
ret.push('NOT ');
|
|
634
|
+
}
|
|
635
|
+
ret.push('DEFERRABLE ');
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
|
|
639
|
+
alterSequence: cs => {
|
|
640
|
+
ret.push('ALTER SEQUENCE ');
|
|
641
|
+
if (cs.ifExists) {
|
|
642
|
+
ret.push('IF EXISTS ');
|
|
643
|
+
}
|
|
644
|
+
visitQualifiedName(cs.name);
|
|
645
|
+
switch (cs.change.type) {
|
|
646
|
+
case 'set options':
|
|
647
|
+
visitSeqOpts(m, cs.change);
|
|
648
|
+
break;
|
|
649
|
+
case 'rename':
|
|
650
|
+
ret.push('RENAME TO ', name(cs.change.newName), ' ');
|
|
651
|
+
break;
|
|
652
|
+
case 'set schema':
|
|
653
|
+
ret.push('SET SCHEMA ', name(cs.change.newSchema), ' ');
|
|
654
|
+
break;
|
|
655
|
+
case 'owner to':
|
|
656
|
+
const own = cs.change.owner;
|
|
657
|
+
ret.push('OWNER TO ', name(cs.change.owner), ' ');
|
|
658
|
+
break;
|
|
659
|
+
default:
|
|
660
|
+
throw NotSupported.never(cs.change);
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
|
|
664
|
+
createSequence: cs => {
|
|
665
|
+
ret.push('CREATE ');
|
|
666
|
+
if (cs.temp) {
|
|
667
|
+
ret.push('TEMPORARY ');
|
|
668
|
+
}
|
|
669
|
+
ret.push('SEQUENCE ');
|
|
670
|
+
if (cs.ifNotExists) {
|
|
671
|
+
ret.push('IF NOT EXISTS ');
|
|
672
|
+
}
|
|
673
|
+
visitQualifiedName(cs.name);
|
|
674
|
+
visitSeqOpts(m, cs.options);
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
drop: val => {
|
|
679
|
+
ret.push(val.type.toUpperCase(), ' ');
|
|
680
|
+
if (val.concurrently) {
|
|
681
|
+
ret.push('CONCURRENTLY ');
|
|
682
|
+
}
|
|
683
|
+
if (val.ifExists) {
|
|
684
|
+
ret.push('IF EXISTS ');
|
|
685
|
+
}
|
|
686
|
+
list(val.names, x => m.tableRef(x), false);
|
|
687
|
+
if (val.cascade) {
|
|
688
|
+
ret.push(val.cascade.toUpperCase(), ' ');
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
constraint: cst => {
|
|
693
|
+
if (cst.constraintName) {
|
|
694
|
+
ret.push(' CONSTRAINT ', name(cst.constraintName), ' ');
|
|
695
|
+
}
|
|
696
|
+
addConstraint(cst, m);
|
|
697
|
+
},
|
|
698
|
+
|
|
699
|
+
do: d => {
|
|
700
|
+
ret.push('DO');
|
|
701
|
+
if (d.language) {
|
|
702
|
+
ret.push(' LANGUAGE ', d.language.name);
|
|
703
|
+
}
|
|
704
|
+
ret.push(' $$', d.code, '$$');
|
|
705
|
+
},
|
|
706
|
+
|
|
707
|
+
createFunction: c => {
|
|
708
|
+
ret.push(c.orReplace ? 'CREATE OR REPLACE FUNCTION ' : 'CREATE FUNCTION ');
|
|
709
|
+
|
|
710
|
+
visitQualifiedName(c.name);
|
|
711
|
+
|
|
712
|
+
// args
|
|
713
|
+
list(c.arguments, a => {
|
|
714
|
+
if (a.mode) {
|
|
715
|
+
ret.push(a.mode, ' ');
|
|
716
|
+
}
|
|
717
|
+
if (a.name) {
|
|
718
|
+
ret.push(name(a.name), ' ');
|
|
719
|
+
}
|
|
720
|
+
m.dataType(a.type);
|
|
721
|
+
if (a.default) {
|
|
722
|
+
ret.push(" = ");
|
|
723
|
+
m.expr(a.default);
|
|
724
|
+
}
|
|
725
|
+
}, true);
|
|
726
|
+
|
|
727
|
+
// ret type
|
|
728
|
+
if (c.returns) {
|
|
729
|
+
switch (c.returns.kind) {
|
|
730
|
+
case 'table':
|
|
731
|
+
ret.push(' RETURNS TABLE ');
|
|
732
|
+
list(c.returns.columns, t => {
|
|
733
|
+
ret.push(name(t.name), ' ');
|
|
734
|
+
m.dataType(t.type);
|
|
735
|
+
}, true);
|
|
736
|
+
break;
|
|
737
|
+
case undefined:
|
|
738
|
+
case null:
|
|
739
|
+
case 'array':
|
|
740
|
+
ret.push(' RETURNS ');
|
|
741
|
+
m.dataType(c.returns);
|
|
742
|
+
break;
|
|
743
|
+
default:
|
|
744
|
+
throw NotSupported.never(c.returns);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
ret.push(' AS $$', c.code ?? '', '$$');
|
|
749
|
+
|
|
750
|
+
// function settings
|
|
751
|
+
if (c.language) {
|
|
752
|
+
ret.push('LANGUAGE ', c.language.name, ' ');
|
|
753
|
+
}
|
|
754
|
+
if (c.purity) {
|
|
755
|
+
ret.push(c.purity.toUpperCase(), ' ');
|
|
756
|
+
}
|
|
757
|
+
if (typeof c.leakproof === 'boolean') {
|
|
758
|
+
ret.push(c.leakproof ? 'LEAKPROOF ' : 'NOT LEAKPROOF ');
|
|
759
|
+
}
|
|
760
|
+
switch (c.onNullInput) {
|
|
761
|
+
case 'call':
|
|
762
|
+
ret.push('CALLED ON NULL INPUT ');
|
|
763
|
+
break;
|
|
764
|
+
case 'null':
|
|
765
|
+
ret.push('RETURNS NULL ON NULL INPUT ');
|
|
766
|
+
break;
|
|
767
|
+
case 'strict':
|
|
768
|
+
ret.push('STRICT ');
|
|
769
|
+
break;
|
|
770
|
+
case null:
|
|
771
|
+
case undefined:
|
|
772
|
+
break;
|
|
773
|
+
default:
|
|
774
|
+
throw NotSupported.never(c.onNullInput);
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
dropFunction: d => {
|
|
780
|
+
ret.push('DROP FUNCTION ');
|
|
781
|
+
if (d.ifExists) {
|
|
782
|
+
ret.push('IF EXISTS ');
|
|
783
|
+
}
|
|
784
|
+
visitQualifiedName(d.name);
|
|
785
|
+
|
|
786
|
+
if (d.arguments) {
|
|
787
|
+
list(d.arguments, a => {
|
|
788
|
+
if (a.name) {
|
|
789
|
+
visitQualifiedName(a.name);
|
|
790
|
+
ret.push(' ');
|
|
791
|
+
}
|
|
792
|
+
m.dataType(a.type);
|
|
793
|
+
}, true);
|
|
794
|
+
}
|
|
795
|
+
ret.push(' ');
|
|
796
|
+
},
|
|
797
|
+
|
|
798
|
+
with: w => {
|
|
799
|
+
ret.push('WITH ');
|
|
800
|
+
list(w.bind, b => {
|
|
801
|
+
ret.push(name(b.alias), ' AS (');
|
|
802
|
+
m.statement(b.statement);
|
|
803
|
+
ret.push(') ');
|
|
804
|
+
}, false);
|
|
805
|
+
|
|
806
|
+
m.statement(w.in);
|
|
807
|
+
},
|
|
808
|
+
|
|
809
|
+
withRecursive: val => {
|
|
810
|
+
ret.push('WITH RECURSIVE '
|
|
811
|
+
, name(val.alias)
|
|
812
|
+
, '('
|
|
813
|
+
, ...val.columnNames.map(name).join(', ')
|
|
814
|
+
, ') AS (');
|
|
815
|
+
m.union(val.bind);
|
|
816
|
+
ret.push(') ');
|
|
817
|
+
m.statement(val.in);
|
|
818
|
+
},
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
setGlobal: g => {
|
|
822
|
+
ret.push('SET ')
|
|
823
|
+
if (g.scope) {
|
|
824
|
+
ret.push(g.scope.toUpperCase() + ' ');
|
|
825
|
+
}
|
|
826
|
+
ret.push(name(g.variable), ' = ');
|
|
827
|
+
visitSetVal(g.set);
|
|
828
|
+
},
|
|
829
|
+
|
|
830
|
+
setTimezone: g => {
|
|
831
|
+
ret.push('SET TIME ZONE ');
|
|
832
|
+
switch (g.to.type) {
|
|
833
|
+
case 'default':
|
|
834
|
+
case 'local':
|
|
835
|
+
ret.push(g.to.type.toUpperCase(), ' ');
|
|
836
|
+
break;
|
|
837
|
+
case 'value':
|
|
838
|
+
ret.push(typeof g.to.value === 'string'
|
|
839
|
+
? literal(g.to.value)
|
|
840
|
+
: g.to.value.toString(10));
|
|
841
|
+
break;
|
|
842
|
+
case 'interval':
|
|
843
|
+
ret.push('INTERVAL ', literal(g.to.value), ' HOUR TO MINUTE');
|
|
844
|
+
break;
|
|
845
|
+
default:
|
|
846
|
+
throw NotSupported.never(g.to);
|
|
847
|
+
}
|
|
848
|
+
},
|
|
849
|
+
|
|
850
|
+
setNames: g => {
|
|
851
|
+
ret.push('SET NAMES ');
|
|
852
|
+
switch (g.to.type) {
|
|
853
|
+
case 'value':
|
|
854
|
+
ret.push(literal(g.to.value));
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
|
|
859
|
+
dataType: d => {
|
|
860
|
+
if (d?.kind === 'array') {
|
|
861
|
+
m.dataType(d.arrayOf!)
|
|
862
|
+
ret.push('[]');
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
if (!d?.name) {
|
|
866
|
+
ret.push('unkown');
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
let appendConfig = true;
|
|
870
|
+
if (d.schema) {
|
|
871
|
+
visitQualifiedName(d, d.doubleQuoted);
|
|
872
|
+
} else {
|
|
873
|
+
// see https://www.postgresql.org/docs/13/datatype.html
|
|
874
|
+
// & issue https://github.com/oguimbal/pgsql-ast-parser/issues/38
|
|
875
|
+
if (d.doubleQuoted) {
|
|
876
|
+
visitQualifiedName(d, true);
|
|
877
|
+
} else {
|
|
878
|
+
switch (d.name) {
|
|
879
|
+
case 'double precision':
|
|
880
|
+
case 'character varying':
|
|
881
|
+
case 'bit varying':
|
|
882
|
+
ret.push(d.name, ' ');
|
|
883
|
+
break;
|
|
884
|
+
case 'time without time zone':
|
|
885
|
+
case 'timestamp without time zone':
|
|
886
|
+
case 'time with time zone':
|
|
887
|
+
case 'timestamp with time zone':
|
|
888
|
+
const parts = d.name.split(' ');
|
|
889
|
+
|
|
890
|
+
ret.push(parts.shift()!);
|
|
891
|
+
if (d.config?.length) {
|
|
892
|
+
list(d.config, v => ret.push(v.toString(10)), true);
|
|
893
|
+
}
|
|
894
|
+
ret.push(' ');
|
|
895
|
+
|
|
896
|
+
ret.push(parts.join(' '), ' ');
|
|
897
|
+
appendConfig = false;
|
|
898
|
+
break;
|
|
899
|
+
default:
|
|
900
|
+
visitQualifiedName(d);
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
if (appendConfig && d.config?.length) {
|
|
907
|
+
list(d.config, v => ret.push(v.toString(10)), true);
|
|
908
|
+
}
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
createIndex: c => {
|
|
912
|
+
ret.push(c.unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ');
|
|
913
|
+
if (c.concurrently) {
|
|
914
|
+
ret.push('CONCURRENTLY ');
|
|
915
|
+
}
|
|
916
|
+
if (c.ifNotExists) {
|
|
917
|
+
ret.push(' IF NOT EXISTS ');
|
|
918
|
+
}
|
|
919
|
+
if (c.indexName) {
|
|
920
|
+
ret.push(name(c.indexName), ' ');
|
|
921
|
+
}
|
|
922
|
+
ret.push('ON ');
|
|
923
|
+
m.tableRef(c.table);
|
|
924
|
+
if (c.using) {
|
|
925
|
+
ret.push('USING ', name(c.using), ' ');
|
|
926
|
+
}
|
|
927
|
+
list(c.expressions, e => {
|
|
928
|
+
m.expr(e.expression);
|
|
929
|
+
ret.push(' ');
|
|
930
|
+
if (e.collate) {
|
|
931
|
+
ret.push('COLLATE ');
|
|
932
|
+
visitQualifiedName(e.collate);
|
|
933
|
+
}
|
|
934
|
+
if (e.opclass) {
|
|
935
|
+
visitQualifiedName(e.opclass);
|
|
936
|
+
}
|
|
937
|
+
if (e.order) {
|
|
938
|
+
ret.push(e.order, ' ');
|
|
939
|
+
}
|
|
940
|
+
if (e.nulls) {
|
|
941
|
+
ret.push('nulls ', e.nulls, ' ');
|
|
942
|
+
}
|
|
943
|
+
}, true);
|
|
944
|
+
if (c.with) {
|
|
945
|
+
ret.push('WITH ');
|
|
946
|
+
list(c.with, w => {
|
|
947
|
+
ret.push(w.parameter, ' = ', literal(w.value));
|
|
948
|
+
}, true);
|
|
949
|
+
}
|
|
950
|
+
if (c.tablespace) {
|
|
951
|
+
ret.push('TABLESPACE ', ident(c.tablespace));
|
|
952
|
+
}
|
|
953
|
+
if (c.where) {
|
|
954
|
+
ret.push(' WHERE ');
|
|
955
|
+
m.expr(c.where);
|
|
956
|
+
}
|
|
957
|
+
ret.push(' ');
|
|
958
|
+
},
|
|
959
|
+
|
|
960
|
+
createTable: t => {
|
|
961
|
+
ret.push('CREATE ');
|
|
962
|
+
if (t.locality) {
|
|
963
|
+
ret.push(t.locality.toUpperCase(), ' ');
|
|
964
|
+
}
|
|
965
|
+
if (t.temporary) {
|
|
966
|
+
ret.push('TEMPORARY ');
|
|
967
|
+
}
|
|
968
|
+
if (t.unlogged) {
|
|
969
|
+
ret.push('UNLOGGED ');
|
|
970
|
+
}
|
|
971
|
+
ret.push(t.ifNotExists ? 'TABLE IF NOT EXISTS ' : 'TABLE ');
|
|
972
|
+
m.tableRef(t.name);
|
|
973
|
+
ret.push('(');
|
|
974
|
+
list(t.columns, c => {
|
|
975
|
+
switch (c.kind) {
|
|
976
|
+
case 'column':
|
|
977
|
+
return m.createColumn(c);
|
|
978
|
+
case 'like table':
|
|
979
|
+
return m.likeTable(c);
|
|
980
|
+
default:
|
|
981
|
+
throw NotSupported.never(c);
|
|
982
|
+
}
|
|
983
|
+
}, false);
|
|
984
|
+
if (t.constraints) {
|
|
985
|
+
ret.push(', ');
|
|
986
|
+
list(t.constraints, c => {
|
|
987
|
+
const cname = c.constraintName;
|
|
988
|
+
if (cname) {
|
|
989
|
+
ret.push('CONSTRAINT ', name(cname), ' ');
|
|
990
|
+
}
|
|
991
|
+
addConstraint(c, m);
|
|
992
|
+
}, false)
|
|
993
|
+
}
|
|
994
|
+
ret.push(') ');
|
|
995
|
+
if (t.inherits?.length) {
|
|
996
|
+
ret.push(' INHERITS ');
|
|
997
|
+
list(t.inherits, i => visitQualifiedName(i), true);
|
|
998
|
+
}
|
|
999
|
+
},
|
|
1000
|
+
|
|
1001
|
+
likeTable: l => {
|
|
1002
|
+
ret.push(' LIKE ');
|
|
1003
|
+
m.tableRef(l.like);
|
|
1004
|
+
ret.push(' ');
|
|
1005
|
+
for (const { verb, option } of l.options) {
|
|
1006
|
+
ret.push(verb.toUpperCase(), ' ', option.toUpperCase(), ' ');
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
|
|
1010
|
+
createSchema: s => {
|
|
1011
|
+
ret.push(s.ifNotExists ? 'CREATE SCHEMA IF NOT EXISTS ' : 'CREATE SCHEMA ');
|
|
1012
|
+
ret.push(name(s.name));
|
|
1013
|
+
},
|
|
1014
|
+
|
|
1015
|
+
truncateTable: t => {
|
|
1016
|
+
ret.push('TRUNCATE TABLE ');
|
|
1017
|
+
let first = true;
|
|
1018
|
+
for (const tbl of t.tables) {
|
|
1019
|
+
if (!first) {
|
|
1020
|
+
ret.push(', ');
|
|
1021
|
+
}
|
|
1022
|
+
first = false;
|
|
1023
|
+
m.tableRef(tbl);
|
|
1024
|
+
}
|
|
1025
|
+
if (t.identity) {
|
|
1026
|
+
switch (t.identity) {
|
|
1027
|
+
case 'restart':
|
|
1028
|
+
ret.push(' RESTART IDENTITY ');
|
|
1029
|
+
break;
|
|
1030
|
+
case 'continue':
|
|
1031
|
+
ret.push(' CONTINUE IDENTITY ');
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
if (t.cascade) {
|
|
1036
|
+
ret.push(' ', t.cascade, ' ');
|
|
1037
|
+
}
|
|
1038
|
+
},
|
|
1039
|
+
|
|
1040
|
+
delete: t => {
|
|
1041
|
+
ret.push('DELETE FROM ');
|
|
1042
|
+
m.tableRef(t.from);
|
|
1043
|
+
if (t.where) {
|
|
1044
|
+
ret.push(' WHERE ');
|
|
1045
|
+
m.expr(t.where);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
if (t.returning) {
|
|
1049
|
+
ret.push(' RETURNING ');
|
|
1050
|
+
list(t.returning, r => m.selectionColumn(r), false);
|
|
1051
|
+
}
|
|
1052
|
+
ret.push(' ');
|
|
1053
|
+
},
|
|
1054
|
+
|
|
1055
|
+
dropColumn: t => {
|
|
1056
|
+
ret.push(' DROP COLUMN ');
|
|
1057
|
+
if (t.ifExists) {
|
|
1058
|
+
ret.push(' IF EXISTS ');
|
|
1059
|
+
}
|
|
1060
|
+
ret.push(name(t.column));
|
|
1061
|
+
if (t.behaviour) {
|
|
1062
|
+
ret.push(' ', t.behaviour);
|
|
1063
|
+
}
|
|
1064
|
+
ret.push(' ');
|
|
1065
|
+
},
|
|
1066
|
+
|
|
1067
|
+
dropConstraint: t => {
|
|
1068
|
+
ret.push(' DROP CONSTRAINT ');
|
|
1069
|
+
if (t.ifExists) {
|
|
1070
|
+
ret.push(' IF EXISTS ');
|
|
1071
|
+
}
|
|
1072
|
+
ret.push(name(t.constraint));
|
|
1073
|
+
if (t.behaviour) {
|
|
1074
|
+
ret.push(' ', t.behaviour.toUpperCase(), ' ');
|
|
1075
|
+
}
|
|
1076
|
+
},
|
|
1077
|
+
|
|
1078
|
+
from: t => m.super().from(t),
|
|
1079
|
+
|
|
1080
|
+
fromCall: s => {
|
|
1081
|
+
|
|
1082
|
+
join(m, s.join, () => {
|
|
1083
|
+
if (s.lateral) {
|
|
1084
|
+
ret.push("LATERAL ")
|
|
1085
|
+
}
|
|
1086
|
+
m.call(s);
|
|
1087
|
+
if (s.withOrdinality) {
|
|
1088
|
+
ret.push(' WITH ORDINALITY')
|
|
1089
|
+
}
|
|
1090
|
+
if (s.alias) {
|
|
1091
|
+
ret.push(' AS ', name<Name>(s.alias), ' ');
|
|
1092
|
+
const len = s.alias.columns?.length ?? 0;
|
|
1093
|
+
if (len > 0) {
|
|
1094
|
+
ret.push('(')
|
|
1095
|
+
for (let ix = 0; ix < len; ++ix) {
|
|
1096
|
+
if (ix !== 0) {
|
|
1097
|
+
ret.push(', ')
|
|
1098
|
+
}
|
|
1099
|
+
ret.push(name(s.alias.columns![ix]));
|
|
1100
|
+
}
|
|
1101
|
+
ret.push(')')
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
ret.push(' ');
|
|
1107
|
+
},
|
|
1108
|
+
|
|
1109
|
+
fromStatement: s => {
|
|
1110
|
+
|
|
1111
|
+
// todo: use 's.db' if defined
|
|
1112
|
+
join(m, s.join, () => {
|
|
1113
|
+
if (s.lateral) {
|
|
1114
|
+
ret.push("LATERAL ")
|
|
1115
|
+
}
|
|
1116
|
+
ret.push('(');
|
|
1117
|
+
m.select(s.statement);
|
|
1118
|
+
ret.push(') ');
|
|
1119
|
+
if (s.alias) {
|
|
1120
|
+
ret.push(' AS ', ident(s.alias));
|
|
1121
|
+
if (s.columnNames) {
|
|
1122
|
+
list(s.columnNames, c => ret.push(name(c)), true);
|
|
1123
|
+
}
|
|
1124
|
+
ret.push(' ');
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
ret.push(' ');
|
|
1129
|
+
},
|
|
1130
|
+
|
|
1131
|
+
values: s => {
|
|
1132
|
+
ret.push('VALUES ');
|
|
1133
|
+
list(s.values, vlist => {
|
|
1134
|
+
list(vlist, e => {
|
|
1135
|
+
m.expr(e);
|
|
1136
|
+
}, true);
|
|
1137
|
+
}, false);
|
|
1138
|
+
},
|
|
1139
|
+
|
|
1140
|
+
fromTable: s => {
|
|
1141
|
+
join(m, s.join, () => {
|
|
1142
|
+
m.tableRef(s.name);
|
|
1143
|
+
if (s.name.columnNames) {
|
|
1144
|
+
if (!s.name.alias) {
|
|
1145
|
+
throw new Error('Cannot specify aliased column names without an alias');
|
|
1146
|
+
}
|
|
1147
|
+
list(s.name.columnNames, c => ret.push(name(c)), true);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
},
|
|
1151
|
+
|
|
1152
|
+
join: j => {
|
|
1153
|
+
throw new Error('Should not happen 💀');
|
|
1154
|
+
},
|
|
1155
|
+
|
|
1156
|
+
insert: i => {
|
|
1157
|
+
ret.push('INSERT INTO ');
|
|
1158
|
+
m.tableRef(i.into);
|
|
1159
|
+
|
|
1160
|
+
if (i.columns) {
|
|
1161
|
+
ret.push(
|
|
1162
|
+
'('
|
|
1163
|
+
, i.columns.map(name).join(', ')
|
|
1164
|
+
, ')'
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
ret.push(' ');
|
|
1168
|
+
if (i.overriding) {
|
|
1169
|
+
ret.push('OVERRIDING ', i.overriding.toUpperCase(), ' VALUE ');
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
m.select(i.insert);
|
|
1173
|
+
ret.push(' ');
|
|
1174
|
+
|
|
1175
|
+
if (i.onConflict) {
|
|
1176
|
+
ret.push('ON CONFLICT ');
|
|
1177
|
+
const on = i.onConflict.on;
|
|
1178
|
+
switch (on?.type) {
|
|
1179
|
+
case 'on expr':
|
|
1180
|
+
list(on.exprs, e => m.expr(e), true);
|
|
1181
|
+
break;
|
|
1182
|
+
case 'on constraint':
|
|
1183
|
+
ret.push('ON CONSTRAINT ');
|
|
1184
|
+
visitQualifiedName(on.constraint);
|
|
1185
|
+
case null:
|
|
1186
|
+
case undefined:
|
|
1187
|
+
break;
|
|
1188
|
+
default:
|
|
1189
|
+
throw NotSupported.never(on);
|
|
1190
|
+
}
|
|
1191
|
+
if (i.onConflict.do === 'do nothing') {
|
|
1192
|
+
ret.push(' DO NOTHING');
|
|
1193
|
+
} else {
|
|
1194
|
+
ret.push(' DO UPDATE SET ');
|
|
1195
|
+
list(i.onConflict.do.sets, s => m.set(s), false);
|
|
1196
|
+
if (i.onConflict.where) {
|
|
1197
|
+
ret.push(' WHERE ');
|
|
1198
|
+
m.expr(i.onConflict.where);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
ret.push(' ');
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
if (i.returning) {
|
|
1205
|
+
ret.push(' RETURNING ');
|
|
1206
|
+
list(i.returning, r => m.selectionColumn(r), false);
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
|
|
1210
|
+
raise: r => {
|
|
1211
|
+
ret.push('RAISE ');
|
|
1212
|
+
if (r.level) {
|
|
1213
|
+
ret.push(r.level.toUpperCase(), ' ');
|
|
1214
|
+
}
|
|
1215
|
+
ret.push(literal(r.format), ' ');
|
|
1216
|
+
|
|
1217
|
+
if (r.formatExprs?.length) {
|
|
1218
|
+
ret.push(', ');
|
|
1219
|
+
list(r.formatExprs, e => m.expr(e), false);
|
|
1220
|
+
}
|
|
1221
|
+
if (r.using?.length) {
|
|
1222
|
+
ret.push(' USING ');
|
|
1223
|
+
list(r.using, ({ type, value }) => {
|
|
1224
|
+
ret.push(type.toUpperCase(), '=');
|
|
1225
|
+
m.expr(value);
|
|
1226
|
+
}, false);
|
|
1227
|
+
}
|
|
1228
|
+
ret.push(' ');
|
|
1229
|
+
},
|
|
1230
|
+
|
|
1231
|
+
default: () => {
|
|
1232
|
+
ret.push(' DEFAULT ');
|
|
1233
|
+
},
|
|
1234
|
+
|
|
1235
|
+
member: e => {
|
|
1236
|
+
m.expr(e.operand);
|
|
1237
|
+
ret.push(e.op);
|
|
1238
|
+
ret.push(typeof e.member === 'number'
|
|
1239
|
+
? e.member.toString(10)
|
|
1240
|
+
: literal(e.member));
|
|
1241
|
+
},
|
|
1242
|
+
|
|
1243
|
+
ref: r => {
|
|
1244
|
+
if (r.table) {
|
|
1245
|
+
visitQualifiedName(r.table);
|
|
1246
|
+
ret.push('.');
|
|
1247
|
+
}
|
|
1248
|
+
ret.push(r.name === '*' ? '*' : ident(r.name));
|
|
1249
|
+
},
|
|
1250
|
+
|
|
1251
|
+
parameter: p => {
|
|
1252
|
+
ret.push(p.name);
|
|
1253
|
+
},
|
|
1254
|
+
|
|
1255
|
+
renameColumn: r => {
|
|
1256
|
+
ret.push(' RENAME COLUMN '
|
|
1257
|
+
, name(r.column)
|
|
1258
|
+
, ' TO '
|
|
1259
|
+
, name(r.to));
|
|
1260
|
+
},
|
|
1261
|
+
|
|
1262
|
+
renameConstraint: r => {
|
|
1263
|
+
ret.push(' RENAME CONSTRAINT '
|
|
1264
|
+
, name(r.constraint)
|
|
1265
|
+
, ' TO '
|
|
1266
|
+
, name(r.to));
|
|
1267
|
+
},
|
|
1268
|
+
|
|
1269
|
+
renameTable: r => {
|
|
1270
|
+
ret.push(' RENAME TO '
|
|
1271
|
+
, name(r.to));
|
|
1272
|
+
},
|
|
1273
|
+
|
|
1274
|
+
createView: c => {
|
|
1275
|
+
ret.push('CREATE ');
|
|
1276
|
+
if (c.orReplace) {
|
|
1277
|
+
ret.push('OR REPLACE ');
|
|
1278
|
+
}
|
|
1279
|
+
if (c.temp) {
|
|
1280
|
+
ret.push('TEMP ');
|
|
1281
|
+
}
|
|
1282
|
+
if (c.recursive) {
|
|
1283
|
+
ret.push('RECURSIVE ');
|
|
1284
|
+
}
|
|
1285
|
+
ret.push('VIEW ');
|
|
1286
|
+
m.tableRef(c.name);
|
|
1287
|
+
if (c.columnNames) {
|
|
1288
|
+
list(c.columnNames, c => ret.push(name(c)), true);
|
|
1289
|
+
}
|
|
1290
|
+
const opts = c.parameters && Object.entries(c.parameters);
|
|
1291
|
+
if (opts?.length) {
|
|
1292
|
+
ret.push(' WITH ');
|
|
1293
|
+
list(opts, ([k, v]) => ret.push(k, '=', v), false);
|
|
1294
|
+
}
|
|
1295
|
+
ret.push(' AS ');
|
|
1296
|
+
m.select(c.query);
|
|
1297
|
+
if (c.checkOption) {
|
|
1298
|
+
ret.push(' WITH ', c.checkOption.toUpperCase(), ' CHECK OPTION');
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
|
|
1302
|
+
createMaterializedView: c => {
|
|
1303
|
+
ret.push('CREATE MATERIALIZED VIEW ');
|
|
1304
|
+
if (c.ifNotExists) {
|
|
1305
|
+
ret.push('IF NOT EXISTS ');
|
|
1306
|
+
}
|
|
1307
|
+
m.tableRef(c.name);
|
|
1308
|
+
if (c.columnNames) {
|
|
1309
|
+
list(c.columnNames, c => ret.push(name(c)), true);
|
|
1310
|
+
}
|
|
1311
|
+
const opts = c.parameters && Object.entries(c.parameters);
|
|
1312
|
+
if (opts?.length) {
|
|
1313
|
+
ret.push(' WITH ');
|
|
1314
|
+
list(opts, ([k, v]) => ret.push(k, '=', v), false);
|
|
1315
|
+
}
|
|
1316
|
+
if (c.tablespace) {
|
|
1317
|
+
ret.push(' TABLESPACE ', name(c.tablespace));
|
|
1318
|
+
}
|
|
1319
|
+
ret.push(' AS ');
|
|
1320
|
+
m.select(c.query);
|
|
1321
|
+
if (typeof c.withData === 'boolean') {
|
|
1322
|
+
ret.push(c.withData ? ' WITH DATA' : ' WITH NO DATA');
|
|
1323
|
+
}
|
|
1324
|
+
},
|
|
1325
|
+
|
|
1326
|
+
refreshMaterializedView: val => {
|
|
1327
|
+
ret.push('REFRESH MATERIALIZED VIEW ');
|
|
1328
|
+
if (val.concurrently) {
|
|
1329
|
+
ret.push('CONCURRENTLY ');
|
|
1330
|
+
}
|
|
1331
|
+
m.tableRef(val.name);
|
|
1332
|
+
if (typeof val.withData === 'boolean') {
|
|
1333
|
+
ret.push(val.withData ? ' WITH DATA' : ' WITH NO DATA');
|
|
1334
|
+
}
|
|
1335
|
+
},
|
|
1336
|
+
|
|
1337
|
+
select: s => m.super().select(s),
|
|
1338
|
+
|
|
1339
|
+
selection: s => {
|
|
1340
|
+
ret.push('SELECT ');
|
|
1341
|
+
|
|
1342
|
+
if (s.distinct) {
|
|
1343
|
+
if (typeof s.distinct === 'string') {
|
|
1344
|
+
ret.push(s.distinct.toUpperCase());
|
|
1345
|
+
} else {
|
|
1346
|
+
ret.push(' DISTINCT ON ');
|
|
1347
|
+
list(s.distinct, v => m.expr(v), true);
|
|
1348
|
+
}
|
|
1349
|
+
ret.push(' ');
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
if (s.columns) {
|
|
1353
|
+
list(s.columns, c => m.selectionColumn(c), false);
|
|
1354
|
+
}
|
|
1355
|
+
ret.push(' ');
|
|
1356
|
+
if (s.from) {
|
|
1357
|
+
ret.push('FROM ');
|
|
1358
|
+
const tblCnt = s.from.length
|
|
1359
|
+
for (let i = 0; i < tblCnt; i++) {
|
|
1360
|
+
const f = s.from[i];
|
|
1361
|
+
if (i > 0 && !f.join) {
|
|
1362
|
+
// implicit cross join (https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FROM)
|
|
1363
|
+
ret.push(',')
|
|
1364
|
+
}
|
|
1365
|
+
m.from(f);
|
|
1366
|
+
}
|
|
1367
|
+
ret.push(' ');
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
if (s.where) {
|
|
1371
|
+
ret.push('WHERE ');
|
|
1372
|
+
m.expr(s.where);
|
|
1373
|
+
ret.push(' ');
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if (s.groupBy) {
|
|
1377
|
+
ret.push('GROUP BY ');
|
|
1378
|
+
list(s.groupBy, e => m.expr(e), false);
|
|
1379
|
+
ret.push(' ');
|
|
1380
|
+
|
|
1381
|
+
if (s.having) {
|
|
1382
|
+
ret.push(' HAVING ');
|
|
1383
|
+
m.expr(s.having);
|
|
1384
|
+
ret.push(' ');
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
if (s.orderBy) {
|
|
1389
|
+
visitOrderBy(m, s.orderBy);
|
|
1390
|
+
ret.push(' ');
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
if (s.limit) {
|
|
1394
|
+
if (s.limit.offset) {
|
|
1395
|
+
ret.push(`OFFSET `);
|
|
1396
|
+
m.expr(s.limit.offset);
|
|
1397
|
+
|
|
1398
|
+
}
|
|
1399
|
+
if (s.limit.limit) {
|
|
1400
|
+
ret.push(`LIMIT `);
|
|
1401
|
+
m.expr(s.limit.limit);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
if (s.for) {
|
|
1406
|
+
ret.push('FOR ', s.for.type.toUpperCase());
|
|
1407
|
+
if (s.skip) {
|
|
1408
|
+
ret.push(' ', s.skip.type.toUpperCase());
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
},
|
|
1412
|
+
|
|
1413
|
+
show: s => {
|
|
1414
|
+
ret.push('SHOW ', name(s.variable));
|
|
1415
|
+
},
|
|
1416
|
+
|
|
1417
|
+
prepare: s => {
|
|
1418
|
+
ret.push('PREPARE ', name(s.name));
|
|
1419
|
+
if (s.args?.length) {
|
|
1420
|
+
list(s.args, a => m.dataType(a), true);
|
|
1421
|
+
}
|
|
1422
|
+
ret.push(' AS ');
|
|
1423
|
+
m.statement(s.statement);
|
|
1424
|
+
},
|
|
1425
|
+
|
|
1426
|
+
deallocate: s => {
|
|
1427
|
+
ret.push('DEALLOCATE ');
|
|
1428
|
+
if ('name' in s.target) {
|
|
1429
|
+
ret.push(s.target.name);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
ret.push('ALL')
|
|
1433
|
+
},
|
|
1434
|
+
|
|
1435
|
+
arraySelect: s => {
|
|
1436
|
+
ret.push('array(');
|
|
1437
|
+
m.select(s.select);
|
|
1438
|
+
ret.push(')');
|
|
1439
|
+
},
|
|
1440
|
+
|
|
1441
|
+
union: s => {
|
|
1442
|
+
ret.push('(');
|
|
1443
|
+
m.statement(s.left);
|
|
1444
|
+
ret.push(') ', s.type.toUpperCase(), ' ');
|
|
1445
|
+
if (s.right.type === 'union' || s.right.type === 'union all') {
|
|
1446
|
+
m.union(s.right);
|
|
1447
|
+
} else {
|
|
1448
|
+
ret.push('(');
|
|
1449
|
+
m.statement(s.right);
|
|
1450
|
+
ret.push(')');
|
|
1451
|
+
}
|
|
1452
|
+
},
|
|
1453
|
+
|
|
1454
|
+
selectionColumn: c => {
|
|
1455
|
+
m.expr(c.expr);
|
|
1456
|
+
if (c.alias) {
|
|
1457
|
+
ret.push(' AS ', name(c.alias));
|
|
1458
|
+
}
|
|
1459
|
+
ret.push(' ');
|
|
1460
|
+
},
|
|
1461
|
+
|
|
1462
|
+
set: s => {
|
|
1463
|
+
ret.push(name(s.column), ' = ');
|
|
1464
|
+
m.expr(s.value);
|
|
1465
|
+
ret.push(' ');
|
|
1466
|
+
},
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
statement: s => m.super().statement(s),
|
|
1470
|
+
|
|
1471
|
+
tableRef: r => {
|
|
1472
|
+
visitQualifiedName(r);
|
|
1473
|
+
if (r.alias) {
|
|
1474
|
+
ret.push(' AS ', ident(r.alias));
|
|
1475
|
+
}
|
|
1476
|
+
ret.push(' ');
|
|
1477
|
+
},
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
ternary: t => {
|
|
1481
|
+
m.expr(t.value);
|
|
1482
|
+
ret.push(' ', t.op, ' ');
|
|
1483
|
+
m.expr(t.lo);
|
|
1484
|
+
ret.push(' AND ');
|
|
1485
|
+
m.expr(t.hi);
|
|
1486
|
+
ret.push(' ');
|
|
1487
|
+
},
|
|
1488
|
+
|
|
1489
|
+
transaction: t => {
|
|
1490
|
+
ret.push(t.type);
|
|
1491
|
+
},
|
|
1492
|
+
|
|
1493
|
+
unary: t => {
|
|
1494
|
+
switch (t.op) {
|
|
1495
|
+
case '+':
|
|
1496
|
+
case '-':
|
|
1497
|
+
// prefix ops
|
|
1498
|
+
visitOp(t);
|
|
1499
|
+
m.expr(t.operand);
|
|
1500
|
+
break;
|
|
1501
|
+
case 'NOT':
|
|
1502
|
+
// prefix ops
|
|
1503
|
+
ret.push(t.op);
|
|
1504
|
+
ret.push(' ');
|
|
1505
|
+
m.expr(t.operand);
|
|
1506
|
+
break;
|
|
1507
|
+
default:
|
|
1508
|
+
// postfix ops
|
|
1509
|
+
m.expr(t.operand);
|
|
1510
|
+
ret.push(' ');
|
|
1511
|
+
ret.push(t.op);
|
|
1512
|
+
}
|
|
1513
|
+
},
|
|
1514
|
+
|
|
1515
|
+
update: u => {
|
|
1516
|
+
ret.push('UPDATE ');
|
|
1517
|
+
m.tableRef(u.table);
|
|
1518
|
+
ret.push(' SET ');
|
|
1519
|
+
list(u.sets, s => m.set(s), false);
|
|
1520
|
+
ret.push(' ');
|
|
1521
|
+
if (u.from) {
|
|
1522
|
+
ret.push('FROM ');
|
|
1523
|
+
m.from(u.from);
|
|
1524
|
+
ret.push(' ');
|
|
1525
|
+
}
|
|
1526
|
+
if (u.where) {
|
|
1527
|
+
ret.push('WHERE ');
|
|
1528
|
+
m.expr(u.where);
|
|
1529
|
+
ret.push(' ');
|
|
1530
|
+
}
|
|
1531
|
+
if (u.returning) {
|
|
1532
|
+
ret.push(' RETURNING ');
|
|
1533
|
+
list(u.returning, r => m.selectionColumn(r), false);
|
|
1534
|
+
ret.push(' ');
|
|
1535
|
+
}
|
|
1536
|
+
},
|
|
1537
|
+
|
|
1538
|
+
}))
|
|
1539
|
+
|
|
1540
|
+
export const toSql = {} as IAstToSql;
|
|
1541
|
+
const proto = AstDefaultMapper.prototype as any;
|
|
1542
|
+
for (const k of Object.getOwnPropertyNames(proto)) {
|
|
1543
|
+
const orig = proto[k] as Function;
|
|
1544
|
+
if (k === 'constructor' || k === 'super' || typeof orig !== 'function') {
|
|
1545
|
+
continue;
|
|
1546
|
+
}
|
|
1547
|
+
(toSql as any)[k] = function (...args: []) {
|
|
1548
|
+
try {
|
|
1549
|
+
(visitor as any)[k].apply(visitor, args);
|
|
1550
|
+
return ret.join('').trim();
|
|
1551
|
+
} finally {
|
|
1552
|
+
ret = [];
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
}
|