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C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC,CAAC;4BAC5G,sBAAO;yBACV;wBAED,qBAAM,UAAU,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAA;;wBAAzC,SAAyC,CAAC;wBAC1C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC,CAAC;6BAEvD,UAAU,EAAV,wBAAU;wBAAE,qBAAM,UAAU,CAAC,KAAK,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;;;;;6BAGrC,UAAU,EAAV,wBAAU;wBAAE,qBAAO,UAAyB,CAAC,KAAK,EAAE,EAAA;;wBAAxC,SAAwC,CAAC;;;wBAEzD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC;wBAC5D,OAAO,CAAC,KAAK,CAAC,KAAG,CAAC,CAAC;wBACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;;;KAEvB;IAEL,wBAAC;AAAD,CAxDA,AAwDC,IAAA;AAxDY,8CAAiB","file":"CacheClearCommand.js","sourcesContent":["import {createConnection} from \"../index\";\nimport {ConnectionOptionsReader} from \"../connection/ConnectionOptionsReader\";\nimport {Connection} from \"../connection/Connection\";\nimport * as yargs from \"yargs\";\nconst chalk = require(\"chalk\");\n\n/**\n * Clear cache command.\n */\nexport class CacheClearCommand implements yargs.CommandModule {\n\n command = \"cache:clear\";\n describe = \"Clears all data stored in query runner cache.\";\n\n builder(args: yargs.Argv) {\n return args\n .option(\"connection\", {\n alias: \"c\",\n default: \"default\",\n describe: \"Name of the connection on which run a query.\"\n })\n .option(\"config\", {\n alias: \"f\",\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 try {\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 subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"]\n });\n connection = await createConnection(connectionOptions);\n\n if (!connection.queryResultCache) {\n console.log(chalk.black.bgRed(\"Cache is not enabled. To use cache enable it in connection configuration.\"));\n return;\n }\n\n await connection.queryResultCache.clear();\n console.log(chalk.green(\"Cache was successfully cleared\"));\n\n if (connection) await connection.close();\n\n } catch (err) {\n if (connection) await (connection as Connection).close();\n\n console.log(chalk.black.bgRed(\"Error during cache clear:\"));\n console.error(err);\n process.exit(1);\n }\n }\n\n}\n"],"sourceRoot":".."}
|