typeorm 0.3.6-dev.ef025bd → 0.3.7-dev.60a7960

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.
Files changed (51) hide show
  1. package/browser/driver/expo/ExpoQueryRunner.js +8 -21
  2. package/browser/driver/expo/ExpoQueryRunner.js.map +1 -1
  3. package/browser/entity-schema/EntitySchemaOptions.d.ts +7 -0
  4. package/browser/entity-schema/EntitySchemaOptions.js.map +1 -1
  5. package/browser/entity-schema/EntitySchemaRelationIdOptions.d.ts +15 -0
  6. package/browser/entity-schema/EntitySchemaRelationIdOptions.js +3 -0
  7. package/browser/entity-schema/EntitySchemaRelationIdOptions.js.map +1 -0
  8. package/browser/entity-schema/EntitySchemaTransformer.js +14 -0
  9. package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
  10. package/browser/find-options/FindOptionsWhere.d.ts +1 -1
  11. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  12. package/browser/index.d.ts +2 -0
  13. package/browser/index.js.map +1 -1
  14. package/browser/metadata-args/RelationIdMetadataArgs.d.ts +1 -1
  15. package/browser/metadata-args/RelationIdMetadataArgs.js.map +1 -1
  16. package/browser/query-builder/QueryBuilder.js +12 -10
  17. package/browser/query-builder/QueryBuilder.js.map +1 -1
  18. package/commands/CacheClearCommand.js +2 -2
  19. package/commands/CacheClearCommand.js.map +1 -1
  20. package/commands/InitCommand.js +24 -4
  21. package/commands/InitCommand.js.map +1 -1
  22. package/commands/MigrationRevertCommand.js +2 -2
  23. package/commands/MigrationRevertCommand.js.map +1 -1
  24. package/commands/MigrationRunCommand.js +2 -2
  25. package/commands/MigrationRunCommand.js.map +1 -1
  26. package/commands/MigrationShowCommand.js +2 -2
  27. package/commands/MigrationShowCommand.js.map +1 -1
  28. package/commands/QueryCommand.js +2 -2
  29. package/commands/QueryCommand.js.map +1 -1
  30. package/commands/SchemaDropCommand.js +2 -2
  31. package/commands/SchemaDropCommand.js.map +1 -1
  32. package/commands/SchemaSyncCommand.js +2 -2
  33. package/commands/SchemaSyncCommand.js.map +1 -1
  34. package/driver/expo/ExpoQueryRunner.js +8 -21
  35. package/driver/expo/ExpoQueryRunner.js.map +1 -1
  36. package/entity-schema/EntitySchemaOptions.d.ts +7 -0
  37. package/entity-schema/EntitySchemaOptions.js.map +1 -1
  38. package/entity-schema/EntitySchemaRelationIdOptions.d.ts +15 -0
  39. package/entity-schema/EntitySchemaRelationIdOptions.js +4 -0
  40. package/entity-schema/EntitySchemaRelationIdOptions.js.map +1 -0
  41. package/entity-schema/EntitySchemaTransformer.js +14 -0
  42. package/entity-schema/EntitySchemaTransformer.js.map +1 -1
  43. package/find-options/FindOptionsWhere.d.ts +1 -1
  44. package/find-options/FindOptionsWhere.js.map +1 -1
  45. package/index.d.ts +2 -0
  46. package/index.js.map +1 -1
  47. package/metadata-args/RelationIdMetadataArgs.d.ts +1 -1
  48. package/metadata-args/RelationIdMetadataArgs.js.map +1 -1
  49. package/package.json +1 -1
  50. package/query-builder/QueryBuilder.js +12 -10
  51. package/query-builder/QueryBuilder.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IA+qB3E,CAAC;IA7qBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,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,MAAK;SACZ;QAED,IAAI,OAAO,EAAE;YACT,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,SAAS,CAAA;YAC/C,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;SACtD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAprBD,kCAorBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\ndatabase: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^4.0.3\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^1.13.1\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^4.0.4\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/InitCommand.ts"],"names":[],"mappings":";;;;AAAA,iDAA6C;AAC7C,mDAA4B;AAE5B,0DAAyB;AACzB,iDAAoC;AACpC,oCAAuC;AACvC,6DAAyD;AAEzD;;GAEG;AACH,MAAa,WAAW;IAAxB;QACI,YAAO,GAAG,MAAM,CAAA;QAChB,aAAQ,GACJ,+CAA+C;YAC/C,wEAAwE;YACxE,mEAAmE,CAAA;IAmsB3E,CAAC;IAjsBG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,GAAG,EAAE;YACT,KAAK,EAAE,MAAM;YACb,QAAQ,EAAE,gCAAgC;SAC7C,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,2CAA2C;SACxD,CAAC;aACD,MAAM,CAAC,SAAS,EAAE;YACf,QAAQ,EACJ,8FAA8F;SACrG,CAAC;aACD,MAAM,CAAC,QAAQ,EAAE;YACd,QAAQ,EACJ,4EAA4E;SACnF,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,oDAAoD;SACjE,CAAC;aACD,MAAM,CAAC,IAAI,EAAE;YACV,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,CAAC,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G,SAAS,CAAA;SACtD;QAED,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,WAAW,CAAC,OAAO,GAAG,EAAE,CAAA;QAElD,IAAI,YAAY;YACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,wCAAwC;gBAC9F,OAAO,EAAE,qBAAqB;aACjC,CAAC,CAAA;;YAEF,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC/B,KAAK,EAAE,8CAA8C,CAAC,sBAAsB;gBAC5E,OAAO,EAAE,0BAA0B;aACtC,CAAC,CAAA;QAEN,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACpD,CAAC;CACJ;AAxsBD,kCAwsBC","file":"InitCommand.js","sourcesContent":["import { CommandUtils } from \"./CommandUtils\"\nimport * as path from \"path\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { exec } from \"child_process\"\nimport { TypeORMError } from \"../error\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\n\n/**\n * Generates a new project with TypeORM.\n */\nexport class InitCommand implements yargs.CommandModule {\n command = \"init\"\n describe =\n \"Generates initial TypeORM project structure. \" +\n \"If name specified then creates files inside directory called as name. \" +\n \"If its not specified then creates files inside current directory.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"n\", {\n alias: \"name\",\n describe: \"Name of the project directory.\",\n })\n .option(\"db\", {\n alias: \"database\",\n describe: \"Database type you'll use in your project.\",\n })\n .option(\"express\", {\n describe:\n \"Indicates if express server sample code should be included in the project. False by default.\",\n })\n .option(\"docker\", {\n describe:\n \"Set to true if docker-compose must be generated as well. False by default.\",\n })\n .option(\"pm\", {\n alias: \"manager\",\n choices: [\"npm\", \"yarn\"],\n default: \"npm\",\n describe: \"Install packages, expected values are npm or yarn.\",\n })\n .option(\"ms\", {\n alias: \"module\",\n choices: [\"commonjs\", \"esm\"],\n default: \"commonjs\",\n describe:\n \"Module system to use for project, expected values are commonjs or esm.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n try {\n const database: string = (args.database as any) || \"postgres\"\n const isExpress = args.express !== undefined ? true : false\n const isDocker = args.docker !== undefined ? true : false\n const basePath = process.cwd() + (args.name ? \"/\" + args.name : \"\")\n const projectName = args.name\n ? path.basename(args.name as any)\n : undefined\n const installNpm = args.pm === \"yarn\" ? false : true\n const projectIsEsm = args.ms === \"esm\"\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.getPackageJsonTemplate(projectName, projectIsEsm),\n false,\n )\n if (isDocker)\n await CommandUtils.createFile(\n basePath + \"/docker-compose.yml\",\n InitCommand.getDockerComposeTemplate(database),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/.gitignore\",\n InitCommand.getGitIgnoreFile(),\n )\n await CommandUtils.createFile(\n basePath + \"/README.md\",\n InitCommand.getReadmeTemplate({ docker: isDocker }),\n false,\n )\n await CommandUtils.createFile(\n basePath + \"/tsconfig.json\",\n InitCommand.getTsConfigTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/entity/User.ts\",\n InitCommand.getUserEntityTemplate(database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/data-source.ts\",\n InitCommand.getAppDataSourceTemplate(projectIsEsm, database),\n )\n await CommandUtils.createFile(\n basePath + \"/src/index.ts\",\n InitCommand.getAppIndexTemplate(isExpress, projectIsEsm),\n )\n await CommandUtils.createDirectories(basePath + \"/src/migration\")\n\n // generate extra files for express application\n if (isExpress) {\n await CommandUtils.createFile(\n basePath + \"/src/routes.ts\",\n InitCommand.getRoutesTemplate(projectIsEsm),\n )\n await CommandUtils.createFile(\n basePath + \"/src/controller/UserController.ts\",\n InitCommand.getControllerTemplate(projectIsEsm),\n )\n }\n\n const packageJsonContents = await CommandUtils.readFile(\n basePath + \"/package.json\",\n )\n await CommandUtils.createFile(\n basePath + \"/package.json\",\n InitCommand.appendPackageJson(\n packageJsonContents,\n database,\n isExpress,\n projectIsEsm,\n ),\n )\n\n if (args.name) {\n console.log(\n chalk.green(\n `Project created inside ${chalk.blue(\n basePath,\n )} directory.`,\n ),\n )\n } else {\n console.log(\n chalk.green(`Project created inside current directory.`),\n )\n }\n\n console.log(chalk.green(`Please wait, installing dependencies...`))\n if (args.pm && installNpm) {\n await InitCommand.executeCommand(\"npm install\", basePath)\n } else {\n await InitCommand.executeCommand(\"yarn install\", basePath)\n }\n\n console.log(chalk.green(`Done! Start playing with a new project!`))\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during project initialization:\", err)\n process.exit(1)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Static Methods\n // -------------------------------------------------------------------------\n\n protected static executeCommand(command: string, cwd: string) {\n return new Promise<string>((ok, fail) => {\n exec(command, { cwd }, (error: any, stdout: any, stderr: any) => {\n if (stdout) return ok(stdout)\n if (stderr) return fail(stderr)\n if (error) return fail(error)\n ok(\"\")\n })\n })\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getAppDataSourceTemplate(\n isEsm: boolean,\n database: string,\n ): string {\n let dbSettings = \"\"\n switch (database) {\n case \"mysql\":\n dbSettings = `type: \"mysql\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"mariadb\":\n dbSettings = `type: \"mariadb\",\n host: \"localhost\",\n port: 3306,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"sqlite\":\n dbSettings = `type: \"sqlite\",\n database: \"database.sqlite\",`\n break\n case \"better-sqlite3\":\n dbSettings = `type: \"better-sqlite3\",\n database: \"database.sqlite\",`\n break\n case \"postgres\":\n dbSettings = `type: \"postgres\",\n host: \"localhost\",\n port: 5432,\n username: \"test\",\n password: \"test\",\n database: \"test\",`\n break\n case \"cockroachdb\":\n dbSettings = `type: \"cockroachdb\",\n host: \"localhost\",\n port: 26257,\n username: \"root\",\n password: \"\",\n database: \"defaultdb\",`\n break\n case \"mssql\":\n dbSettings = `type: \"mssql\",\n host: \"localhost\",\n username: \"sa\",\n password: \"Admin12345\",\n database: \"tempdb\",`\n break\n case \"oracle\":\n dbSettings = `type: \"oracle\",\nhost: \"localhost\",\nusername: \"system\",\npassword: \"oracle\",\nport: 1521,\nsid: \"xe.oracle.docker\",`\n break\n case \"mongodb\":\n dbSettings = `type: \"mongodb\",\n database: \"test\",`\n break\n case \"spanner\":\n dbSettings = `type: \"spanner\",\n projectId: \"test\",\n instanceId: \"test\",\n databaseId: \"test\",`\n break\n }\n return `import \"reflect-metadata\"\nimport { DataSource } from \"typeorm\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport const AppDataSource = new DataSource({\n ${dbSettings}\n synchronize: true,\n logging: false,\n entities: [User],\n migrations: [],\n subscribers: [],\n})\n`\n }\n\n /**\n * Gets contents of the ormconfig file.\n */\n protected static getTsConfigTemplate(esmModule: boolean): string {\n if (esmModule)\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es2021\"],\n target: \"es2021\",\n module: \"es2022\",\n moduleResolution: \"node\",\n allowSyntheticDefaultImports: true,\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n else\n return JSON.stringify(\n {\n compilerOptions: {\n lib: [\"es5\", \"es6\"],\n target: \"es5\",\n module: \"commonjs\",\n moduleResolution: \"node\",\n outDir: \"./build\",\n emitDecoratorMetadata: true,\n experimentalDecorators: true,\n sourceMap: true,\n },\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the .gitignore file.\n */\n protected static getGitIgnoreFile(): string {\n return `.idea/\n.vscode/\nnode_modules/\nbuild/\ntmp/\ntemp/`\n }\n\n /**\n * Gets contents of the user entity.\n */\n protected static getUserEntityTemplate(database: string): string {\n return `import { Entity, ${\n database === \"mongodb\"\n ? \"ObjectIdColumn, ObjectID\"\n : \"PrimaryGeneratedColumn\"\n }, Column } from \"typeorm\"\n\n@Entity()\nexport class User {\n\n ${\n database === \"mongodb\"\n ? \"@ObjectIdColumn()\"\n : \"@PrimaryGeneratedColumn()\"\n }\n id: ${database === \"mongodb\" ? \"ObjectID\" : \"number\"}\n\n @Column()\n firstName: string\n\n @Column()\n lastName: string\n\n @Column()\n age: number\n\n}\n`\n }\n\n /**\n * Gets contents of the route file (used when express is enabled).\n */\n protected static getRoutesTemplate(isEsm: boolean): string {\n return `import { UserController } from \"./controller/UserController${\n isEsm ? \".js\" : \"\"\n }\"\n\nexport const Routes = [{\n method: \"get\",\n route: \"/users\",\n controller: UserController,\n action: \"all\"\n}, {\n method: \"get\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"one\"\n}, {\n method: \"post\",\n route: \"/users\",\n controller: UserController,\n action: \"save\"\n}, {\n method: \"delete\",\n route: \"/users/:id\",\n controller: UserController,\n action: \"remove\"\n}]`\n }\n\n /**\n * Gets contents of the user controller file (used when express is enabled).\n */\n protected static getControllerTemplate(isEsm: boolean): string {\n return `import { getRepository } from \"typeorm\"\nimport { NextFunction, Request, Response } from \"express\"\nimport { User } from \"../entity/User${isEsm ? \".js\" : \"\"}\"\n\nexport class UserController {\n\n private userRepository = getRepository(User)\n\n async all(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.find()\n }\n\n async one(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.findOne(request.params.id)\n }\n\n async save(request: Request, response: Response, next: NextFunction) {\n return this.userRepository.save(request.body)\n }\n\n async remove(request: Request, response: Response, next: NextFunction) {\n let userToRemove = await this.userRepository.findOneBy({ id: request.params.id })\n await this.userRepository.remove(userToRemove)\n }\n\n}`\n }\n\n /**\n * Gets contents of the main (index) application file.\n */\n protected static getAppIndexTemplate(\n express: boolean,\n isEsm: boolean,\n ): string {\n if (express) {\n return `import ${!isEsm ? \"* as \" : \"\"}express from \"express\"\nimport ${!isEsm ? \"* as \" : \"\"}bodyParser from \"body-parser\"\nimport { Request, Response } from \"express\"\nimport { AppDataSource } from \"./data-source${isEsm ? \".js\" : \"\"}\"\nimport { Routes } from \"./routes${isEsm ? \".js\" : \"\"}\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n // create express app\n const app = express()\n app.use(bodyParser.json())\n\n // register express routes from defined application routes\n Routes.forEach(route => {\n (app as any)[route.method](route.route, (req: Request, res: Response, next: Function) => {\n const result = (new (route.controller as any))[route.action](req, res, next)\n if (result instanceof Promise) {\n result.then(result => result !== null && result !== undefined ? res.send(result) : undefined)\n\n } else if (result !== null && result !== undefined) {\n res.json(result)\n }\n })\n })\n\n // setup express app here\n // ...\n\n // start express server\n app.listen(3000)\n\n // insert new users for test\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Timber\",\n lastName: \"Saw\",\n age: 27\n })\n )\n\n await AppDataSource.manager.save(\n AppDataSource.manager.create(User, {\n firstName: \"Phantom\",\n lastName: \"Assassin\",\n age: 24\n })\n )\n\n console.log(\"Express server has started on port 3000. Open http://localhost:3000/users to see results\")\n\n}).catch(error => console.log(error))\n`\n } else {\n return `import { AppDataSource } from \"./data-source${\n isEsm ? \".js\" : \"\"\n }\"\nimport { User } from \"./entity/User${isEsm ? \".js\" : \"\"}\"\n\nAppDataSource.initialize().then(async () => {\n\n console.log(\"Inserting a new user into the database...\")\n const user = new User()\n user.firstName = \"Timber\"\n user.lastName = \"Saw\"\n user.age = 25\n await AppDataSource.manager.save(user)\n console.log(\"Saved a new user with id: \" + user.id)\n\n console.log(\"Loading users from the database...\")\n const users = await AppDataSource.manager.find(User)\n console.log(\"Loaded users: \", users)\n\n console.log(\"Here you can setup and run express / fastify / any other framework.\")\n\n}).catch(error => console.log(error))\n`\n }\n }\n\n /**\n * Gets contents of the new package.json file.\n */\n protected static getPackageJsonTemplate(\n projectName?: string,\n projectIsEsm?: boolean,\n ): string {\n return JSON.stringify(\n {\n name: projectName || \"typeorm-sample\",\n version: \"0.0.1\",\n description: \"Awesome project developed with TypeORM.\",\n type: projectIsEsm ? \"module\" : \"commonjs\",\n devDependencies: {},\n dependencies: {},\n scripts: {},\n },\n undefined,\n 3,\n )\n }\n\n /**\n * Gets contents of the new docker-compose.yml file.\n */\n protected static getDockerComposeTemplate(database: string): string {\n switch (database) {\n case \"mysql\":\n return `version: '3'\nservices:\n\n mysql:\n image: \"mysql:5.7.10\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"mariadb\":\n return `version: '3'\nservices:\n\n mariadb:\n image: \"mariadb:10.1.16\"\n ports:\n - \"3306:3306\"\n environment:\n MYSQL_ROOT_PASSWORD: \"admin\"\n MYSQL_USER: \"test\"\n MYSQL_PASSWORD: \"test\"\n MYSQL_DATABASE: \"test\"\n\n`\n case \"postgres\":\n return `version: '3'\nservices:\n\n postgres:\n image: \"postgres:9.6.1\"\n ports:\n - \"5432:5432\"\n environment:\n POSTGRES_USER: \"test\"\n POSTGRES_PASSWORD: \"test\"\n POSTGRES_DB: \"test\"\n\n`\n case \"cockroachdb\":\n return `version: '3'\nservices:\n\n cockroachdb:\n image: \"cockroachdb/cockroach:v2.1.4\"\n command: start --insecure\n ports:\n - \"26257:26257\"\n\n`\n case \"sqlite\":\n case \"better-sqlite3\":\n return `version: '3'\nservices:\n`\n case \"oracle\":\n throw new TypeORMError(\n `You cannot initialize a project with docker for Oracle driver yet.`,\n ) // todo: implement for oracle as well\n\n case \"mssql\":\n return `version: '3'\nservices:\n\n mssql:\n image: \"microsoft/mssql-server-linux:rc2\"\n ports:\n - \"1433:1433\"\n environment:\n SA_PASSWORD: \"Admin12345\"\n ACCEPT_EULA: \"Y\"\n\n`\n case \"mongodb\":\n return `version: '3'\nservices:\n\n mongodb:\n image: \"mongo:4.0.6\"\n container_name: \"typeorm-mongodb\"\n ports:\n - \"27017:27017\"\n\n`\n case \"spanner\":\n return `version: '3'\nservices:\n\n spanner:\n image: gcr.io/cloud-spanner-emulator/emulator:1.4.1\n ports:\n - \"9010:9010\"\n - \"9020:9020\"\n\n`\n }\n return \"\"\n }\n\n /**\n * Gets contents of the new readme.md file.\n */\n protected static getReadmeTemplate(options: { docker: boolean }): string {\n let template = `# Awesome Project Build with TypeORM\n\nSteps to run this project:\n\n1. Run \\`npm i\\` command\n`\n\n if (options.docker) {\n template += `2. Run \\`docker-compose up\\` command\n`\n } else {\n template += `2. Setup database settings inside \\`data-source.ts\\` file\n`\n }\n\n template += `3. Run \\`npm start\\` command\n`\n return template\n }\n\n /**\n * Appends to a given package.json template everything needed.\n */\n protected static appendPackageJson(\n packageJsonContents: string,\n database: string,\n express: boolean,\n projectIsEsm: boolean /*, docker: boolean*/,\n ): string {\n const packageJson = JSON.parse(packageJsonContents)\n\n if (!packageJson.devDependencies) packageJson.devDependencies = {}\n Object.assign(packageJson.devDependencies, {\n \"ts-node\": \"10.7.0\",\n \"@types/node\": \"^16.11.10\",\n typescript: \"4.5.2\",\n })\n\n if (!packageJson.dependencies) packageJson.dependencies = {}\n Object.assign(packageJson.dependencies, {\n typeorm: require(\"../package.json\").version,\n \"reflect-metadata\": \"^0.1.13\",\n })\n\n switch (database) {\n case \"mysql\":\n case \"mariadb\":\n packageJson.dependencies[\"mysql\"] = \"^2.14.1\"\n break\n case \"postgres\":\n case \"cockroachdb\":\n packageJson.dependencies[\"pg\"] = \"^8.4.0\"\n break\n case \"sqlite\":\n packageJson.dependencies[\"sqlite3\"] = \"^5.0.2\"\n break\n case \"better-sqlite3\":\n packageJson.dependencies[\"better-sqlite3\"] = \"^7.0.0\"\n break\n case \"oracle\":\n packageJson.dependencies[\"oracledb\"] = \"^5.1.0\"\n break\n case \"mssql\":\n packageJson.dependencies[\"mssql\"] = \"^6.3.0\"\n break\n case \"mongodb\":\n packageJson.dependencies[\"mongodb\"] = \"^3.0.8\"\n break\n case \"spanner\":\n packageJson.dependencies[\"@google-cloud/spanner\"] = \"^5.18.0\"\n break\n }\n\n if (express) {\n packageJson.dependencies[\"express\"] = \"^4.17.2\"\n packageJson.dependencies[\"body-parser\"] = \"^1.19.1\"\n }\n\n if (!packageJson.scripts) packageJson.scripts = {}\n\n if (projectIsEsm)\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"node --loader ts-node/esm src/index.ts\",\n typeorm: \"typeorm-ts-node-esm\",\n })\n else\n Object.assign(packageJson.scripts, {\n start: /*(docker ? \"docker-compose up && \" : \"\") + */ \"ts-node src/index.ts\",\n typeorm: \"typeorm-ts-node-commonjs\",\n })\n\n return JSON.stringify(packageJson, undefined, 3)\n }\n}\n"],"sourceRoot":".."}
@@ -61,9 +61,9 @@ class MigrationRevertCommand {
61
61
  await dataSource.destroy();
62
62
  }
63
63
  catch (err) {
64
- if (dataSource)
65
- await dataSource.destroy();
66
64
  PlatformTools_1.PlatformTools.logCmdErr("Error during migration revert:", err);
65
+ if (dataSource && dataSource.isInitialized)
66
+ await dataSource.destroy();
67
67
  process_1.default.exit(1);
68
68
  }
69
69
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,kBAAkB,CAAA;QAC5B,aAAQ,GAAG,kCAAkC,CAAA;IA+DjD,CAAC;IA7DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EACJ,0FAA0F;SACjG,CAAC,CAAA;IACV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AC;CACJ;AAjED,wDAiEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,kBA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T,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;YAC3C,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;YAE9D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAnED,wDAmEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -63,9 +63,9 @@ class MigrationRunCommand {
63
63
  process.exit(0);
64
64
  }
65
65
  catch (err) {
66
- if (dataSource)
67
- await dataSource.destroy();
68
66
  PlatformTools_1.PlatformTools.logCmdErr("Error during migration run:", err);
67
+ if (dataSource && dataSource.isInitialized)
68
+ await dataSource.destroy();
69
69
  process.exit(1);
70
70
  }
71
71
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AAEzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GAAG,8BAA8B,CAAA;IAkE7C,CAAC;IAhEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EACJ,uFAAuF;SAC9F,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;aACxC,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAE7B,MAAM,OAAO,GAAG;gBACZ,WAAW,EACP,MAAA,UAAU,CAAC,OAAO,CAAC,yBAAyB,mCAC3C,KAAiC;aACzC,CAAA;YAED,QAAQ,IAAI,CAAC,CAAC,EAAE;gBACZ,KAAK,KAAK;oBACN,OAAO,CAAC,WAAW,GAAG,KAAK,CAAA;oBAC3B,MAAK;gBACT,KAAK,MAAM,CAAC;gBACZ,KAAK,OAAO;oBACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,KAAK,MAAM;oBACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;YACvC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,4BAA4B;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApED,kDAoEC","file":"MigrationRunCommand.js","sourcesContent":["import path from \"path\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Runs migration command.\n */\nexport class MigrationRunCommand implements yargs.CommandModule {\n command = \"migration:run\"\n describe = \"Runs all pending migrations.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration run. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.runMigrations(options)\n await dataSource.destroy()\n\n // exit process if no errors\n process.exit(0)\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRunCommand.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAkC;AAElC,6DAAyD;AAEzD,iDAA6C;AAE7C;;GAEG;AACH,MAAa,mBAAmB;IAAhC;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GAAG,8BAA8B,CAAA;IAoE7C,CAAC;IAlEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAA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AAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;YAE3D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAtED,kDAsEC","file":"MigrationRunCommand.js","sourcesContent":["import path from \"path\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport { DataSource } from \"../data-source\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Runs migration command.\n */\nexport class MigrationRunCommand implements yargs.CommandModule {\n command = \"migration:run\"\n describe = \"Runs all pending migrations.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration run. Enabled by default.\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.runMigrations(options)\n await dataSource.destroy()\n\n // exit process if no errors\n process.exit(0)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration run:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -38,9 +38,9 @@ class MigrationShowCommand {
38
38
  process.exit(0);
39
39
  }
40
40
  catch (err) {
41
- if (dataSource)
42
- await dataSource.destroy();
43
41
  PlatformTools_1.PlatformTools.logCmdErr("Error during migration show:", err);
42
+ if (dataSource && dataSource.isInitialized)
43
+ await dataSource.destroy();
44
44
  process.exit(1);
45
45
  }
46
46
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationShowCommand.ts"],"names":[],"mappings":";;;;AACA,yDAAkC;AAElC,6DAAyD;AACzD,wDAAuB;AACvB,iDAA6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACI,YAAO,GAAG,gBAAgB,CAAA;QAC1B,aAAQ,GAAG,2DAA2D,CAAA;IAmC1E,CAAC;IAjCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,cAAc,EAAE,CAAA;YACjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAC1C,6BAAa,CAAC,SAAS,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;YAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AArCD,oDAqCC","file":"MigrationShowCommand.js","sourcesContent":["import { DataSource } from \"../data-source\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows all migrations and whether they have been run or not.\n */\nexport class MigrationShowCommand implements yargs.CommandModule {\n command = \"migration:show\"\n describe = \"Show all migrations and whether they have been run or not\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"],\n })\n await dataSource.initialize()\n await dataSource.showMigrations()\n await dataSource.destroy()\n\n process.exit(0)\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during migration show:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationShowCommand.ts"],"names":[],"mappings":";;;;AACA,yDAAkC;AAElC,6DAAyD;AACzD,wDAAuB;AACvB,iDAA6C;AAE7C;;GAEG;AACH,MAAa,oBAAoB;IAAjC;QACI,YAAO,GAAG,gBAAgB,CAAA;QAC1B,aAAQ,GAAG,2DAA2D,CAAA;IAsC1E,CAAC;IApCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,EAAE;gBACf,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,cAAc,EAAE,CAAA;YACjC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAA;YAE5D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAxCD,oDAwCC","file":"MigrationShowCommand.js","sourcesContent":["import { DataSource } from \"../data-source\"\nimport * as process from \"process\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Shows all migrations and whether they have been run or not.\n */\nexport class MigrationShowCommand implements yargs.CommandModule {\n command = \"migration:show\"\n describe = \"Show all migrations and whether they have been run or not\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"schema\"],\n })\n await dataSource.initialize()\n await dataSource.showMigrations()\n await dataSource.destroy()\n\n process.exit(0)\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration show:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -56,11 +56,11 @@ class QueryCommand {
56
56
  await dataSource.destroy();
57
57
  }
58
58
  catch (err) {
59
+ PlatformTools_1.PlatformTools.logCmdErr("Error during query execution:", err);
59
60
  if (queryRunner)
60
61
  await queryRunner.release();
61
- if (dataSource)
62
+ if (dataSource && dataSource.isInitialized)
62
63
  await dataSource.destroy();
63
- PlatformTools_1.PlatformTools.logCmdErr("Error during query execution:", err);
64
64
  process_1.default.exit(1);
65
65
  }
66
66
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AAEzD,0DAAyB;AACzB,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY;IAAzB;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GACJ,kHAAkH,CAAA;IAiE1H,CAAC;IA/DG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UA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6BAAa,CAAC,aAAa,CACvB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAC5C,CACJ,CAAA;aACJ;YAED,MAAM,WAAW,CAAC,OAAO,EAAE,CAAA;YAC3B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,WAAW;gBAAE,MAAO,WAA2B,CAAC,OAAO,EAAE,CAAA;YAC7D,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1C,6BAAa,CAAC,SAAS,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;YAC7D,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AApED,oCAoEC","file":"QueryCommand.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Executes an SQL query on the given dataSource.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\"\n describe =\n \"Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\",\n })\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let queryRunner: QueryRunner | undefined = undefined\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n // create a query runner and execute query using it\n queryRunner = dataSource.createQueryRunner()\n const query = args.query as string\n console.log(\n chalk.green(\"Running query: \") +\n PlatformTools.highlightSql(query),\n )\n const queryResult = await queryRunner.query(query)\n\n if (typeof queryResult === \"undefined\") {\n console.log(\n chalk.green(\n \"Query has been executed. No result was returned.\",\n ),\n )\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"))\n console.log(\n PlatformTools.highlightJson(\n JSON.stringify(queryResult, undefined, 2),\n ),\n )\n }\n\n await queryRunner.release()\n await dataSource.destroy()\n } catch (err) {\n if (queryRunner) await (queryRunner as QueryRunner).release()\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during query execution:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/QueryCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AAEzD,0DAAyB;AACzB,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,YAAY;IAAzB;QACI,YAAO,GAAG,eAAe,CAAA;QACzB,aAAQ,GACJ,kHAAkH,CAAA;IAmE1H,CAAC;IAjEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,UAAU,CAAC,OAAO,EAAE;YACjB,QAAQ,EAAE,sBAAsB;YAChC,IAAI,EAAE,QAAQ;SACjB,CAAC;aACD,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACV,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,WAAW,GAA4B,SAAS,CAAA;QACpD,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,C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AC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAtED,oCAsEC","file":"QueryCommand.js","sourcesContent":["import { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Executes an SQL query on the given dataSource.\n */\nexport class QueryCommand implements yargs.CommandModule {\n command = \"query [query]\"\n describe =\n \"Executes given SQL query on a default dataSource. Specify connection name to run query on a specific dataSource.\"\n\n builder(args: yargs.Argv) {\n return args\n .positional(\"query\", {\n describe: \"The SQL Query to run\",\n type: \"string\",\n })\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let queryRunner: QueryRunner | undefined = undefined\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: false,\n })\n await dataSource.initialize()\n\n // create a query runner and execute query using it\n queryRunner = dataSource.createQueryRunner()\n const query = args.query as string\n console.log(\n chalk.green(\"Running query: \") +\n PlatformTools.highlightSql(query),\n )\n const queryResult = await queryRunner.query(query)\n\n if (typeof queryResult === \"undefined\") {\n console.log(\n chalk.green(\n \"Query has been executed. No result was returned.\",\n ),\n )\n } else {\n console.log(chalk.green(\"Query has been executed. Result: \"))\n console.log(\n PlatformTools.highlightJson(\n JSON.stringify(queryResult, undefined, 2),\n ),\n )\n }\n\n await queryRunner.release()\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during query execution:\", err)\n\n if (queryRunner) await (queryRunner as QueryRunner).release()\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -39,9 +39,9 @@ class SchemaDropCommand {
39
39
  console.log(chalk_1.default.green("Database schema has been successfully dropped."));
40
40
  }
41
41
  catch (err) {
42
- if (dataSource)
43
- await dataSource.destroy();
44
42
  PlatformTools_1.PlatformTools.logCmdErr("Error during schema drop:", err);
43
+ if (dataSource && dataSource.isInitialized)
44
+ await dataSource.destroy();
45
45
  process_1.default.exit(1);
46
46
  }
47
47
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/SchemaDropCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GACJ,+DAA+D;YAC/D,kEAAkE,CAAA;IAoC1E,CAAC;IAlCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;aAC/B,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,YAAY,EAAE,CAAA;YAC/B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAChE,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,UAAU;gBAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAC1C,6BAAa,CAAC,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;YACzD,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AAxCD,8CAwCC","file":"SchemaDropCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Drops all tables of the database from the given dataSource.\n */\nexport class SchemaDropCommand implements yargs.CommandModule {\n command = \"schema:drop\"\n describe =\n \"Drops all tables in the database on your default dataSource. \" +\n \"To drop table of a concrete connection's database use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.dropDatabase()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Database schema has been successfully dropped.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n PlatformTools.logCmdErr(\"Error during schema drop:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/Schema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AAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AA3CD,8CA2CC","file":"SchemaDropCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Drops all tables of the database from the given dataSource.\n */\nexport class SchemaDropCommand implements yargs.CommandModule {\n command = \"schema:drop\"\n describe =\n \"Drops all tables in the database on your default dataSource. \" +\n \"To drop table of a concrete connection's database use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.dropDatabase()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Database schema has been successfully dropped.\"),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during schema drop:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -39,9 +39,9 @@ class SchemaSyncCommand {
39
39
  console.log(chalk_1.default.green("Schema synchronization finished successfully."));
40
40
  }
41
41
  catch (err) {
42
- if (dataSource)
43
- await dataSource.destroy();
44
42
  PlatformTools_1.PlatformTools.logCmdErr("Error during schema synchronization:", err);
43
+ if (dataSource && dataSource.isInitialized)
44
+ await dataSource.destroy();
45
45
  process_1.default.exit(1);
46
46
  }
47
47
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/SchemaSyncCommand.ts"],"names":[],"mappings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AAzCD,8CAyCC","file":"SchemaSyncCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Synchronizes database schema with entities.\n */\nexport class SchemaSyncCommand implements yargs.CommandModule {\n command = \"schema:sync\"\n describe =\n \"Synchronizes your entities with database schema. It runs schema update queries on all connections you have. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.synchronize()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Schema synchronization finished successfully.\"),\n )\n } catch (err) {\n if (dataSource) await dataSource.destroy()\n\n PlatformTools.logCmdErr(\"Error during schema synchronization:\", err)\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/SchemaSyncCommand.ts"],"names":[],"mappings":";;;;AAEA,0DAAyB;AACzB,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,iBAAiB;IAA9B;QACI,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GACJ,8GAA8G;YAC9G,+DAA+D,CAAA;IAuCvE,CAAC;IArCG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YAC7B,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAqB;QAC/B,IAAI,UAAU,GAA2B,SAAS,CAAA;QAClD,IAAI;YACA,UAAU,GAAG,MAAM,2BAAY,CAAC,cAAc,CAC1C,cAAI,CAAC,OAAO,CAAC,iBAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAoB,CAAC,CACzD,CAAA;YACD,UAAU,CAAC,UAAU,CAAC;gBAClB,WAAW,EAAE,KAAK;gBAClB,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;aAC/B,CAAC,CAAA;YACF,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;YAC7B,MAAM,UAAU,CAAC,WAAW,EAAE,CAAA;YAC9B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE1B,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAC/D,CAAA;SACJ;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAA;YAEpE,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AA3CD,8CA2CC","file":"SchemaSyncCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport chalk from \"chalk\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Synchronizes database schema with entities.\n */\nexport class SchemaSyncCommand implements yargs.CommandModule {\n command = \"schema:sync\"\n describe =\n \"Synchronizes your entities with database schema. It runs schema update queries on all connections you have. \" +\n \"To run update queries on a concrete connection use -c option.\"\n\n builder(args: yargs.Argv) {\n return args.option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"schema\"],\n })\n await dataSource.initialize()\n await dataSource.synchronize()\n await dataSource.destroy()\n\n console.log(\n chalk.green(\"Schema synchronization finished successfully.\"),\n )\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during schema synchronization:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -40,9 +40,6 @@ class ExpoQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRun
40
40
  this.isTransactionActive = false;
41
41
  throw err;
42
42
  }
43
- if (this.transactionDepth > 0) {
44
- await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`);
45
- }
46
43
  this.transactionDepth += 1;
47
44
  await this.broadcaster.broadcast("AfterTransactionStart");
48
45
  }
@@ -59,13 +56,8 @@ class ExpoQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRun
59
56
  typeof this.transaction === "undefined")
60
57
  throw new TransactionNotStartedError_1.TransactionNotStartedError();
61
58
  await this.broadcaster.broadcast("BeforeTransactionCommit");
62
- if (this.transactionDepth > 1) {
63
- await this.query(`RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`);
64
- }
65
- else {
66
- this.transaction = undefined;
67
- this.isTransactionActive = false;
68
- }
59
+ this.transaction = undefined;
60
+ this.isTransactionActive = false;
69
61
  this.transactionDepth -= 1;
70
62
  await this.broadcaster.broadcast("AfterTransactionCommit");
71
63
  }
@@ -81,13 +73,8 @@ class ExpoQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRun
81
73
  typeof this.transaction === "undefined")
82
74
  throw new TransactionNotStartedError_1.TransactionNotStartedError();
83
75
  await this.broadcaster.broadcast("BeforeTransactionRollback");
84
- if (this.transactionDepth > 1) {
85
- await this.query(`ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`);
86
- }
87
- else {
88
- this.transaction = undefined;
89
- this.isTransactionActive = false;
90
- }
76
+ this.transaction = undefined;
77
+ this.isTransactionActive = false;
91
78
  this.transactionDepth -= 1;
92
79
  await this.broadcaster.broadcast("AfterTransactionRollback");
93
80
  }
@@ -135,10 +122,6 @@ class ExpoQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRun
135
122
  this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);
136
123
  }
137
124
  const result = new QueryResult_1.QueryResult();
138
- // return id of inserted row, if query was insert statement.
139
- if (query.substr(0, 11) === "INSERT INTO") {
140
- result.raw = raw.insertId;
141
- }
142
125
  if (raw === null || raw === void 0 ? void 0 : raw.hasOwnProperty("rowsAffected")) {
143
126
  result.affected = raw.rowsAffected;
144
127
  }
@@ -150,6 +133,10 @@ class ExpoQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRun
150
133
  result.raw = resultSet;
151
134
  result.records = resultSet;
152
135
  }
136
+ // return id of inserted row, if query was insert statement.
137
+ if (query.startsWith("INSERT INTO")) {
138
+ result.raw = raw.insertId;
139
+ }
153
140
  if (useStructuredResult) {
154
141
  ok(result);
155
142
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/expo/ExpoQueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,mEAA+D;AAC/D,4FAAwF;AACxF,uFAAmF;AAEnF,8DAA0D;AAC1D,gEAA4D;AAqB5D;;GAEG;AACH,MAAa,eAAgB,SAAQ,qDAAyB;IAW1D,4EAA4E;IAC5E,cAAc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AM;wBACH,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;qBACjB;gBACL,CAAC,EACD,CAAC,CAAe,EAAE,GAAQ,EAAE,EAAE;oBAC1B,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CACvC,GAAG,EACH,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;oBACD,IAAI,CAAC,IAAI,mCAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,CAAA;gBACtD,CAAC,CACJ,CAAA;YACL,CAAC,EACD,KAAK,EAAE,GAAQ,EAAE,EAAE;gBACf,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAA;gBAChC,IAAI,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,EACD,GAAG,EAAE;gBACD,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAA;gBAChC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;YAChC,CAAC,CACJ,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AArOD,0CAqOC","file":"ExpoQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { TransactionNotStartedError } from \"../../error/TransactionNotStartedError\"\nimport { ExpoDriver } from \"./ExpoDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n// Needed to satisfy the Typescript compiler\ninterface IResultSet {\n insertId: number | undefined\n rowsAffected: number\n rows: {\n length: number\n item: (idx: number) => any\n _array: any[]\n }\n}\ninterface ITransaction {\n executeSql: (\n sql: string,\n args: any[] | undefined,\n ok: (tsx: ITransaction, resultSet: IResultSet) => void,\n fail: (tsx: ITransaction, err: any) => void,\n ) => void\n}\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class ExpoQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: ExpoDriver\n\n /**\n * Database transaction object\n */\n private transaction?: ITransaction\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: ExpoDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Starts transaction. Within Expo, all database operations happen in a\n * transaction context, so issuing a `BEGIN TRANSACTION` command is\n * redundant and will result in the following error:\n *\n * `Error: Error code 1: cannot start a transaction within a transaction`\n *\n * Instead, we keep track of a `Transaction` object in `this.transaction`\n * and continue using the same object until we wish to commit the\n * transaction.\n */\n async startTransaction(): Promise<void> {\n this.isTransactionActive = true\n try {\n await this.broadcaster.broadcast(\"BeforeTransactionStart\")\n } catch (err) {\n this.isTransactionActive = false\n throw err\n }\n\n if (this.transactionDepth > 0) {\n await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`)\n }\n this.transactionDepth += 1\n\n await this.broadcaster.broadcast(\"AfterTransactionStart\")\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n * Since Expo will automatically commit the transaction once all the\n * callbacks of the transaction object have been completed, \"committing\" a\n * transaction in this driver's context means that we delete the transaction\n * object and set the stage for the next transaction.\n */\n async commitTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionCommit\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionCommit\")\n }\n\n /**\n * Rollbacks transaction.\n * Error will be thrown if transaction was not started.\n * This method's functionality is identical to `commitTransaction()` because\n * the transaction lifecycle is handled within the Expo transaction object.\n * Issuing separate statements for `COMMIT` or `ROLLBACK` aren't necessary.\n */\n async rollbackTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionRollback\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionRollback\")\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = OFF\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = ON\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n return new Promise<any>(async (ok, fail) => {\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n // All Expo SQL queries are executed in a transaction context\n databaseConnection.transaction(\n async (transaction: ITransaction) => {\n if (typeof this.transaction === \"undefined\") {\n await this.startTransaction()\n this.transaction = transaction\n }\n this.transaction.executeSql(\n query,\n parameters,\n (t: ITransaction, raw: IResultSet) => {\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime =\n queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n // return id of inserted row, if query was insert statement.\n if (query.substr(0, 11) === \"INSERT INTO\") {\n result.raw = raw.insertId\n }\n\n if (raw?.hasOwnProperty(\"rowsAffected\")) {\n result.affected = raw.rowsAffected\n }\n\n if (raw?.hasOwnProperty(\"rows\")) {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.raw = resultSet\n result.records = resultSet\n }\n\n if (useStructuredResult) {\n ok(result)\n } else {\n ok(result.raw)\n }\n },\n (t: ITransaction, err: any) => {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n fail(new QueryFailedError(query, parameters, err))\n },\n )\n },\n async (err: any) => {\n await this.rollbackTransaction()\n fail(err)\n },\n () => {\n this.isTransactionActive = false\n this.transaction = undefined\n },\n )\n })\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/expo/ExpoQueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,mEAA+D;AAC/D,4FAAwF;AACxF,uFAAmF;AAEnF,8DAA0D;AAC1D,gEAA4D;AAqB5D;;GAEG;AACH,MAAa,eAAgB,SAAQ,qDAAyB;IAW1D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAkB;QAC1B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,gBAAgB;QAClB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAA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AC,EAAE,EAAE;4BACtC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;yBACnC;wBAED,MAAM,CAAC,GAAG,GAAG,SAAS,CAAA;wBACtB,MAAM,CAAC,OAAO,GAAG,SAAS,CAAA;qBAC7B;oBAED,4DAA4D;oBAC5D,IAAI,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;wBACjC,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAA;qBAC5B;oBAED,IAAI,mBAAmB,EAAE;wBACrB,EAAE,CAAC,MAAM,CAAC,CAAA;qBACb;yBAAM;wBACH,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;qBACjB;gBACL,CAAC,EACD,CAAC,CAAe,EAAE,GAAQ,EAAE,EAAE;oBAC1B,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CACvC,GAAG,EACH,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;oBACD,IAAI,CAAC,IAAI,mCAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,CAAA;gBACtD,CAAC,CACJ,CAAA;YACL,CAAC,EACD,KAAK,EAAE,GAAQ,EAAE,EAAE;gBACf,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAA;gBAChC,IAAI,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,EACD,GAAG,EAAE;gBACD,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAA;gBAChC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;YAChC,CAAC,CACJ,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAxND,0CAwNC","file":"ExpoQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { TransactionNotStartedError } from \"../../error/TransactionNotStartedError\"\nimport { ExpoDriver } from \"./ExpoDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n// Needed to satisfy the Typescript compiler\ninterface IResultSet {\n insertId: number | undefined\n rowsAffected: number\n rows: {\n length: number\n item: (idx: number) => any\n _array: any[]\n }\n}\ninterface ITransaction {\n executeSql: (\n sql: string,\n args: any[] | undefined,\n ok: (tsx: ITransaction, resultSet: IResultSet) => void,\n fail: (tsx: ITransaction, err: any) => void,\n ) => void\n}\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class ExpoQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: ExpoDriver\n\n /**\n * Database transaction object\n */\n private transaction?: ITransaction\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: ExpoDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Starts transaction. Within Expo, all database operations happen in a\n * transaction context, so issuing a `BEGIN TRANSACTION` command is\n * redundant and will result in the following error:\n *\n * `Error: Error code 1: cannot start a transaction within a transaction`\n *\n * Instead, we keep track of a `Transaction` object in `this.transaction`\n * and continue using the same object until we wish to commit the\n * transaction.\n */\n async startTransaction(): Promise<void> {\n this.isTransactionActive = true\n try {\n await this.broadcaster.broadcast(\"BeforeTransactionStart\")\n } catch (err) {\n this.isTransactionActive = false\n throw err\n }\n\n this.transactionDepth += 1\n\n await this.broadcaster.broadcast(\"AfterTransactionStart\")\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n * Since Expo will automatically commit the transaction once all the\n * callbacks of the transaction object have been completed, \"committing\" a\n * transaction in this driver's context means that we delete the transaction\n * object and set the stage for the next transaction.\n */\n async commitTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionCommit\")\n\n this.transaction = undefined\n this.isTransactionActive = false\n\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionCommit\")\n }\n\n /**\n * Rollbacks transaction.\n * Error will be thrown if transaction was not started.\n * This method's functionality is identical to `commitTransaction()` because\n * the transaction lifecycle is handled within the Expo transaction object.\n * Issuing separate statements for `COMMIT` or `ROLLBACK` aren't necessary.\n */\n async rollbackTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionRollback\")\n\n this.transaction = undefined\n this.isTransactionActive = false\n\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionRollback\")\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = OFF\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = ON\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n return new Promise<any>(async (ok, fail) => {\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n // All Expo SQL queries are executed in a transaction context\n databaseConnection.transaction(\n async (transaction: ITransaction) => {\n if (typeof this.transaction === \"undefined\") {\n await this.startTransaction()\n this.transaction = transaction\n }\n this.transaction.executeSql(\n query,\n parameters,\n (t: ITransaction, raw: IResultSet) => {\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime =\n queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n if (raw?.hasOwnProperty(\"rowsAffected\")) {\n result.affected = raw.rowsAffected\n }\n\n if (raw?.hasOwnProperty(\"rows\")) {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.raw = resultSet\n result.records = resultSet\n }\n\n // return id of inserted row, if query was insert statement.\n if (query.startsWith(\"INSERT INTO\")) {\n result.raw = raw.insertId\n }\n\n if (useStructuredResult) {\n ok(result)\n } else {\n ok(result.raw)\n }\n },\n (t: ITransaction, err: any) => {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n fail(new QueryFailedError(query, parameters, err))\n },\n )\n },\n async (err: any) => {\n await this.rollbackTransaction()\n fail(err)\n },\n () => {\n this.isTransactionActive = false\n this.transaction = undefined\n },\n )\n })\n }\n}\n"],"sourceRoot":"../.."}
@@ -7,6 +7,7 @@ import { TableType } from "../metadata/types/TableTypes";
7
7
  import { EntitySchemaUniqueOptions } from "./EntitySchemaUniqueOptions";
8
8
  import { EntitySchemaCheckOptions } from "./EntitySchemaCheckOptions";
9
9
  import { EntitySchemaExclusionOptions } from "./EntitySchemaExclusionOptions";
10
+ import { EntitySchemaRelationIdOptions } from "./EntitySchemaRelationIdOptions";
10
11
  /**
11
12
  * Interface for entity metadata mappings stored inside "schemas" instead of models decorated by decorators.
12
13
  */
@@ -55,6 +56,12 @@ export declare class EntitySchemaOptions<T> {
55
56
  relations?: {
56
57
  [P in keyof T]?: EntitySchemaRelationOptions;
57
58
  };
59
+ /**
60
+ * Entity relation id options.
61
+ */
62
+ relationIds?: {
63
+ [P in keyof T]?: EntitySchemaRelationIdOptions;
64
+ };
58
65
  /**
59
66
  * Entity indices options.
60
67
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entity-schema/EntitySchemaOptions.ts"],"names":[],"mappings":";;;AAcA;;GAEG;AACH,MAAa,mBAAmB;CAoG/B;AApGD,kDAoGC","file":"EntitySchemaOptions.js","sourcesContent":["import {\n DataSource,\n EntitySchemaEmbeddedColumnOptions,\n SelectQueryBuilder,\n} from \"..\"\nimport { EntitySchemaIndexOptions } from \"./EntitySchemaIndexOptions\"\nimport { EntitySchemaColumnOptions } from \"./EntitySchemaColumnOptions\"\nimport { EntitySchemaRelationOptions } from \"./EntitySchemaRelationOptions\"\nimport { OrderByCondition } from \"../find-options/OrderByCondition\"\nimport { TableType } from \"../metadata/types/TableTypes\"\nimport { EntitySchemaUniqueOptions } from \"./EntitySchemaUniqueOptions\"\nimport { EntitySchemaCheckOptions } from \"./EntitySchemaCheckOptions\"\nimport { EntitySchemaExclusionOptions } from \"./EntitySchemaExclusionOptions\"\n\n/**\n * Interface for entity metadata mappings stored inside \"schemas\" instead of models decorated by decorators.\n */\nexport class EntitySchemaOptions<T> {\n /**\n * Name of the schema it extends.\n */\n extends?: string\n\n /**\n * Target bind to this entity schema. Optional.\n */\n target?: Function\n\n /**\n * Entity name.\n */\n name: string\n\n /**\n * Table name.\n */\n tableName?: string\n\n /**\n * Database name. Used in MySql and Sql Server.\n */\n database?: string\n\n /**\n * Schema name. Used in Postgres and Sql Server.\n */\n schema?: string\n\n /**\n * Table type.\n */\n type?: TableType\n\n /**\n * Specifies a property name by which queries will perform ordering by default when fetching rows.\n */\n orderBy?: OrderByCondition\n\n /**\n * Entity column's options.\n */\n columns: {\n [P in keyof T]?: EntitySchemaColumnOptions\n }\n\n /**\n * Entity relation's options.\n */\n relations?: {\n [P in keyof T]?: EntitySchemaRelationOptions\n }\n\n /**\n * Entity indices options.\n */\n indices?: EntitySchemaIndexOptions[]\n\n /**\n * Entity uniques options.\n */\n uniques?: EntitySchemaUniqueOptions[]\n\n /**\n * Entity check options.\n */\n checks?: EntitySchemaCheckOptions[]\n\n /**\n * Entity exclusion options.\n */\n exclusions?: EntitySchemaExclusionOptions[]\n\n /**\n * Embedded Entities options\n */\n embeddeds?: {\n [P in keyof Partial<T>]: EntitySchemaEmbeddedColumnOptions\n }\n\n /**\n * Indicates if schema synchronization is enabled or disabled for this entity.\n * If it will be set to false then schema sync will and migrations ignore this entity.\n * By default schema synchronization is enabled for all entities.\n */\n synchronize?: boolean\n\n /**\n * If set to 'true' this option disables Sqlite's default behaviour of secretly creating\n * an integer primary key column named 'rowid' on table creation.\n * @see https://www.sqlite.org/withoutrowid.html.\n */\n withoutRowid?: boolean\n\n /**\n * View expression.\n */\n expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>)\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/entity-schema/EntitySchemaOptions.ts"],"names":[],"mappings":";;;AAeA;;GAEG;AACH,MAAa,mBAAmB;CA2G/B;AA3GD,kDA2GC","file":"EntitySchemaOptions.js","sourcesContent":["import {\n DataSource,\n EntitySchemaEmbeddedColumnOptions,\n SelectQueryBuilder,\n} from \"..\"\nimport { EntitySchemaIndexOptions } from \"./EntitySchemaIndexOptions\"\nimport { EntitySchemaColumnOptions } from \"./EntitySchemaColumnOptions\"\nimport { EntitySchemaRelationOptions } from \"./EntitySchemaRelationOptions\"\nimport { OrderByCondition } from \"../find-options/OrderByCondition\"\nimport { TableType } from \"../metadata/types/TableTypes\"\nimport { EntitySchemaUniqueOptions } from \"./EntitySchemaUniqueOptions\"\nimport { EntitySchemaCheckOptions } from \"./EntitySchemaCheckOptions\"\nimport { EntitySchemaExclusionOptions } from \"./EntitySchemaExclusionOptions\"\nimport { EntitySchemaRelationIdOptions } from \"./EntitySchemaRelationIdOptions\"\n\n/**\n * Interface for entity metadata mappings stored inside \"schemas\" instead of models decorated by decorators.\n */\nexport class EntitySchemaOptions<T> {\n /**\n * Name of the schema it extends.\n */\n extends?: string\n\n /**\n * Target bind to this entity schema. Optional.\n */\n target?: Function\n\n /**\n * Entity name.\n */\n name: string\n\n /**\n * Table name.\n */\n tableName?: string\n\n /**\n * Database name. Used in MySql and Sql Server.\n */\n database?: string\n\n /**\n * Schema name. Used in Postgres and Sql Server.\n */\n schema?: string\n\n /**\n * Table type.\n */\n type?: TableType\n\n /**\n * Specifies a property name by which queries will perform ordering by default when fetching rows.\n */\n orderBy?: OrderByCondition\n\n /**\n * Entity column's options.\n */\n columns: {\n [P in keyof T]?: EntitySchemaColumnOptions\n }\n\n /**\n * Entity relation's options.\n */\n relations?: {\n [P in keyof T]?: EntitySchemaRelationOptions\n }\n\n /**\n * Entity relation id options.\n */\n relationIds?: {\n [P in keyof T]?: EntitySchemaRelationIdOptions\n }\n\n /**\n * Entity indices options.\n */\n indices?: EntitySchemaIndexOptions[]\n\n /**\n * Entity uniques options.\n */\n uniques?: EntitySchemaUniqueOptions[]\n\n /**\n * Entity check options.\n */\n checks?: EntitySchemaCheckOptions[]\n\n /**\n * Entity exclusion options.\n */\n exclusions?: EntitySchemaExclusionOptions[]\n\n /**\n * Embedded Entities options\n */\n embeddeds?: {\n [P in keyof Partial<T>]: EntitySchemaEmbeddedColumnOptions\n }\n\n /**\n * Indicates if schema synchronization is enabled or disabled for this entity.\n * If it will be set to false then schema sync will and migrations ignore this entity.\n * By default schema synchronization is enabled for all entities.\n */\n synchronize?: boolean\n\n /**\n * If set to 'true' this option disables Sqlite's default behaviour of secretly creating\n * an integer primary key column named 'rowid' on table creation.\n * @see https://www.sqlite.org/withoutrowid.html.\n */\n withoutRowid?: boolean\n\n /**\n * View expression.\n */\n expression?: string | ((connection: DataSource) => SelectQueryBuilder<any>)\n}\n"],"sourceRoot":".."}
@@ -0,0 +1,15 @@
1
+ import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
2
+ export interface EntitySchemaRelationIdOptions {
3
+ /**
4
+ * Name of relation.
5
+ */
6
+ relationName: string;
7
+ /**
8
+ * Alias of the joined (destination) table.
9
+ */
10
+ alias?: string;
11
+ /**
12
+ * Extra condition applied to "ON" section of join.
13
+ */
14
+ queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;
15
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=EntitySchemaRelationIdOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entity-schema/EntitySchemaRelationIdOptions.ts"],"names":[],"mappings":"","file":"EntitySchemaRelationIdOptions.js","sourcesContent":["import { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\n\nexport interface EntitySchemaRelationIdOptions {\n /**\n * Name of relation.\n */\n relationName: string\n\n /**\n * Alias of the joined (destination) table.\n */\n alias?: string\n\n /**\n * Extra condition applied to \"ON\" section of join.\n */\n queryBuilderFactory?: (\n qb: SelectQueryBuilder<any>,\n ) => SelectQueryBuilder<any>\n}\n"],"sourceRoot":".."}