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AAC,CAAC;wBACrD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,6BAAa,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;wBAChE,qBAAM,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAA;;wBAAhD,WAAW,GAAG,SAAkC;wBACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;wBAC9D,OAAO,CAAC,GAAG,CAAC,6BAAa,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;wBAEpF,qBAAM,WAAW,CAAC,OAAO,EAAE,EAAA;;wBAA3B,SAA2B,CAAC;wBAC5B,qBAAM,UAAU,CAAC,KAAK,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;;;;6BAGrB,WAAW,EAAX,wBAAW;wBAAE,qBAAO,WAA2B,CAAC,OAAO,EAAE,EAAA;;wBAA5C,SAA4C,CAAC;;;6BAC1D,UAAU,EAAV,yBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC,CAAC;wBAChE,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IACL,mBAAC;AAAD,CAzDA,AAyDC,IAAA;AAzDY,oCAAY","file":"QueryCommand.js","sourcesContent":["import {createConnection} from \"../index\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport * as yargs from \"yargs\";\nconst chalk = require(\"chalk\");\n\n/**\n * Executes an sql query on the given connection.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query\";\n describe = \"Executes given SQL query on a default connection. Specify connection name to run query on a specific connection.\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"c\", {\n alias: \"connection\",\n default: \"default\",\n describe: \"Name of the connection on which to run a query.\"\n })\n .option(\"f\", {\n alias: \"config\",\n default: \"ormconfig\",\n describe: \"Name of the file with connection configuration.\"\n });\n }\n\n async handler(args: yargs.Arguments) {\n\n let connection: Connection|undefined = undefined;\n let queryRunner: QueryRunner|undefined = undefined;\n try {\n\n // create a connection\n const connectionOptionsReader = new ConnectionOptionsReader({\n root: process.cwd(),\n configName: args.config as any\n });\n const connectionOptions = await connectionOptionsReader.get(args.connection as any);\n Object.assign(connectionOptions, {\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false\n });\n connection = await createConnection(connectionOptions);\n\n // create a query runner and execute query using it\n queryRunner = connection.createQueryRunner(\"master\");\n console.log(chalk.green(\"Running query: \") + PlatformTools.highlightSql(args._[1]));\n const queryResult = await queryRunner.query(args._[1]);\n console.log(chalk.green(\"Query has been executed. Result: \"));\n console.log(PlatformTools.highlightJson(JSON.stringify(queryResult, undefined, 2)));\n\n await queryRunner.release();\n await connection.close();\n\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release();\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during query execution:\"));\n console.error(err);\n process.exit(1);\n }\n }\n}\n"],"sourceRoot":".."}
|