Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix CLI query command TypeError #7043

Merged

Conversation

peterjroberts
Copy link
Contributor

@peterjroberts peterjroberts commented Nov 9, 2020

Fix TypeError in CLI query command.

Description of change

Switch to using the named query property for the CLI query command. #6899 modified the command definition with a named positional argument. This leads to an error in 0.2.29 when executing e.g. When executing npx typeorm query -f path/to/ormconfig.js "query" "SELECT 1":

Error during query execution:
TypeError: Cannot read property 'replace' of undefined
    at escape (/projectPath/node_modules/highlight.js/lib/highlight.js:71:18)
    at Object.highlight (/projectPath/node_modules/highlight.js/lib/highlight.js:799:18)
    at Object.highlight (/projectPath/node_modules/cli-highlight/dist/index.js:76:21)
    at Function.PlatformTools.highlightSql (/projectPath/node_modules/typeorm/platform/PlatformTools.js:186:32)
    at Object.<anonymous> (/projectPath/node_modules/typeorm/commands/QueryCommand.js:64:110)
    at step (/projectPath/node_modules/tslib/tslib.js:141:27)
    at Object.next (/projectPath/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/projectPath/node_modules/tslib/tslib.js:112:62)

Example args object in last working cli query version 0.2.26:

{
  _: [ 'query', 'SELECT 1' ],
  f: 'build/db/ormconfig.js',
  config: 'build/db/ormconfig.js',
  c: 'default',
  connection: 'default',
  '$0': 'node_modules/typeorm/cli'
}

Example args object in 0.2.29:

 {
  _: [ 'query' ],
  f: 'build/db/ormconfig.js',
  config: 'build/db/ormconfig.js',
  c: 'default',
  connection: 'default',
  '$0': 'node_modules/typeorm/cli',
  query: 'SELECT 1'
}

Fixes #7044

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change- I cannot see any existing tests for the CLI
  • Documentation has been updated to reflect this change N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

Switch to using named args property now that it is explicitly defined in the command.
@imnotjames imnotjames merged commit b35397e into typeorm:master Nov 9, 2020
@imnotjames
Copy link
Contributor

Thanks for the contribution! Seems to work for me when I grabbed this change

@peterjroberts peterjroberts deleted the fix-cli-query-undefined-param branch November 11, 2020 09:06
edcolvin pushed a commit to edcolvin/typeorm that referenced this pull request Nov 12, 2020
Switch to using named args property now that it is explicitly defined in the command.
nebkat pushed a commit to nebkat/typeorm that referenced this pull request Jan 9, 2021
Switch to using named args property now that it is explicitly defined in the command.
nebkat pushed a commit to nebkat/typeorm that referenced this pull request Jan 9, 2021
Switch to using named args property now that it is explicitly defined in the command.
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
Switch to using named args property now that it is explicitly defined in the command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError when executing query through CLI
2 participants