typeorm 0.3.7-dev.ec05f1d → 0.3.8-dev.0b54222
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +4 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.d.ts +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +4 -3
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/browser/driver/oracle/OracleConnectionOptions.d.ts +1 -1
- package/browser/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/browser/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
- package/browser/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/browser/driver/sap/SapQueryRunner.d.ts +7 -0
- package/browser/driver/sap/SapQueryRunner.js +24 -2
- package/browser/driver/sap/SapQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -1
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +4 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.d.ts +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js +6 -5
- package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/driver/oracle/OracleConnectionOptions.d.ts +1 -1
- package/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
- package/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/driver/sap/SapQueryRunner.d.ts +7 -0
- package/driver/sap/SapQueryRunner.js +24 -2
- package/driver/sap/SapQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/package.json +1 -1
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -1
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
|
@@ -118,7 +118,7 @@ export interface SqlServerConnectionOptions extends BaseDataSourceOptions, SqlSe
|
|
|
118
118
|
*/
|
|
119
119
|
readonly packetSize?: number;
|
|
120
120
|
/**
|
|
121
|
-
* A boolean determining whether to pass time values in UTC or local time. (default:
|
|
121
|
+
* A boolean determining whether to pass time values in UTC or local time. (default: false).
|
|
122
122
|
*/
|
|
123
123
|
readonly useUTC?: boolean;
|
|
124
124
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: true).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: false).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: false).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "typeorm", "private": false, "version": "0.3.
|
|
1
|
+
{ "name": "typeorm", "private": false, "version": "0.3.8-dev.0b54222", "description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.", "license": "MIT", "readmeFilename": "README.md", "author": { "name": "Umed Khudoiberdiev", "email": "pleerock.me@gmail.com" }, "engines": { "node": ">= 12.9.0" }, "exports": { ".": { "types": "./index.d.ts", "node": { "import": "./index.mjs", "require": "./index.js", "types": "./index.d.ts" }, "browser": { "require": "./index.js", "import": "./browser/index.js", "default": "./index.js" } }, "./browser": { "types": "./index.d.ts", "default": "./browser/index.js" }, "./*.js": "./*.js", "./*": { "require": "./*.js", "import": "./*" } }, "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", "browser": { "./browser/connection/ConnectionOptionsReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsXmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/connection/options-reader/ConnectionOptionsYmlReader.js": "./browser/platform/BrowserConnectionOptionsReaderDummy.js", "./browser/driver/aurora-data-api/AuroraDataApiDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/better-sqlite3/BetterSqlite3Driver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/cockroachdb/CockroachDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mongodb/MongoQueryRunner.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/mysql/MysqlDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/oracle/OracleDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/postgres/PostgresDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sap/SapDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlite/SqliteDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/driver/sqlserver/SqlServerDriver.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/entity-manager/MongoEntityManager.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/logger/FileLogger.js": "./browser/platform/BrowserFileLoggerDummy.js", "./browser/platform/PlatformTools.js": "./browser/platform/BrowserPlatformTools.js", "./browser/repository/MongoRepository.js": "./browser/platform/BrowserDisabledDriversDummy.js", "./browser/util/DirectoryExportedClassesLoader.js": "./browser/platform/BrowserDirectoryExportedClassesLoader.js", "./index.js": "./browser/index.js", "./index.mjs": "./browser/index.js" }, "repository": { "type": "git", "url": "https://github.com/typeorm/typeorm.git" }, "bugs": { "url": "https://github.com/typeorm/typeorm/issues" }, "homepage": "https://typeorm.io", "tags": [ "orm", "typescript", "typescript-orm", "mysql", "mysql-orm", "postgresql", "postgresql-orm", "mariadb", "mariadb-orm", "spanner", "sqlite", "sqlite-orm", "sql-server", "sql-server-orm", "oracle", "oracle-orm", "cloud-spanner", "cloud-spanner-orm" ], "devDependencies": { "@types/app-root-path": "^1.2.4", "@types/chai": "^4.2.15", "@types/chai-as-promised": "^7.1.3", "@types/debug": "^4.1.5", "@types/js-yaml": "^4.0.0", "@types/mkdirp": "^1.0.1", "@types/mocha": "^8.2.1", "@types/node": "^14.14.31", "@types/rimraf": "^3.0.0", "@types/sha.js": "^2.4.0", "@types/sinon": "^9.0.10", "@types/source-map-support": "^0.5.3", "@types/uuid": "^8.3.4", "@types/xml2js": "^0.4.8", "@types/yargs": "^17.0.2", "better-sqlite3": "^7.1.2", "chai": "^4.3.0", "chai-as-promised": "^7.1.1", "class-transformer": "^0.4.0", "conventional-changelog-angular": "^5.0.12", "conventional-changelog-cli": "^2.1.1", "del": "^6.0.0", "gulp": "^4.0.2", "gulp-istanbul": "^1.1.3", "gulp-mocha": "^8.0.0", "gulp-rename": "^2.0.0", "gulp-replace": "^1.0.0", "gulp-shell": "^0.8.0", "gulp-sourcemaps": "^3.0.0", "gulp-typescript": "^6.0.0-alpha.1", "gulpclass": "^0.2.0", "husky": "^5.1.1", "mocha": "^8.3.0", "mongodb": "^3.6.4", "mssql": "^7.3.0", "mysql": "^2.18.1", "mysql2": "^2.2.5", "pg": "^8.5.1", "pg-query-stream": "^4.0.0", "prettier": "^2.5.1", "redis": "^3.1.1", "remap-istanbul": "^0.13.0", "rimraf": "^3.0.2", "sinon": "^9.2.4", "sinon-chai": "^3.5.0", "source-map-support": "^0.5.19", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0", "typescript": "^4.6.2" }, "peerDependencies": { "@google-cloud/spanner": "^5.18.0", "@sap/hana-client": "^2.12.25", "better-sqlite3": "^7.1.2", "hdb-pool": "^0.1.6", "ioredis": "^5.0.4", "mongodb": "^3.6.0", "mssql": "^7.3.0", "mysql2": "^2.2.5", "oracledb": "^5.1.0", "pg": "^8.5.1", "pg-native": "^3.0.0", "pg-query-stream": "^4.0.0", "redis": "^3.1.1 || ^4.0.0", "sql.js": "^1.4.0", "sqlite3": "^5.0.3", "ts-node": "^10.7.0", "typeorm-aurora-data-api-driver": "^2.0.0" }, "peerDependenciesMeta": { "@google-cloud/spanner": { "optional": true }, "@sap/hana-client": { "optional": true }, "better-sqlite3": { "optional": true }, "hdb-pool": { "optional": true }, "ioredis": { "optional": true }, "mongodb": { "optional": true }, "mssql": { "optional": true }, "mysql2": { "optional": true }, "oracledb": { "optional": true }, "pg": { "optional": true }, "pg-native": { "optional": true }, "pg-query-stream": { "optional": true }, "redis": { "optional": true }, "sql.js": { "optional": true }, "sqlite3": { "optional": true }, "ts-node": { "optional": true }, "typeorm-aurora-data-api-driver": { "optional": true } }, "dependencies": { "@sqltools/formatter": "^1.2.2", "app-root-path": "^3.0.0", "buffer": "^6.0.3", "chalk": "^4.1.0", "cli-highlight": "^2.1.11", "date-fns": "^2.28.0", "debug": "^4.3.3", "dotenv": "^16.0.0", "glob": "^7.2.0", "js-yaml": "^4.1.0", "mkdirp": "^1.0.4", "reflect-metadata": "^0.1.13", "sha.js": "^2.4.11", "tslib": "^2.3.1", "uuid": "^8.3.2", "xml2js": "^0.4.23", "yargs": "^17.3.1" }, "scripts": { "test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 60000 ./build/compiled/test", "compile": "rimraf ./build && tsc", "watch": "./node_modules/.bin/tsc -w", "package": "gulp package", "pack": "gulp pack", "lint": "prettier --check \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "format": "prettier --write \"./src/**/*.ts\" \"./test/**/*.ts\" \"./sample/**/*.ts\"", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 2" }, "bin": { "typeorm": "./cli.js", "typeorm-ts-node-commonjs": "./cli-ts-node-commonjs.js", "typeorm-ts-node-esm": "./cli-ts-node-esm.js" }, "funding": "https://opencollective.com/typeorm", "collective": { "type": "opencollective", "url": "https://opencollective.com/typeorm", "logo": "https://opencollective.com/opencollective/logo.txt" }, "nyc": { "all": true, "cache": false, "exclude": [ "**/*.d.ts" ], "extension": [ ".ts" ], "include": [ "build/compiled/src/**", "src/**" ], "reporter": "json" } }
|
|
@@ -365,7 +365,8 @@ class RawSqlResultsToEntityTransformer {
|
|
|
365
365
|
}
|
|
366
366
|
return OrmUtils_1.OrmUtils.mergeDeep(idMap, column.createValueMap(value));
|
|
367
367
|
}
|
|
368
|
-
if (column.
|
|
368
|
+
if (!column.isPrimary &&
|
|
369
|
+
column.referencedColumn.referencedColumn) {
|
|
369
370
|
// if column is a relation
|
|
370
371
|
value =
|
|
371
372
|
column.referencedColumn.referencedColumn.createValueMap(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts"],"names":[],"mappings":";;;AAOA,kDAA8C;AAI9C,0DAAsD;AACtD,wDAAoD;AAEpD;;;GAGG;AACH,MAAa,gCAAgC;IAOzC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACc,aAAiC,EACjC,MAAc,EACd,oBAA4C,EAC5C,uBAAkD,EAClD,WAAyB;QAJzB,kBAAa,GAAb,aAAa,CAAoB;QACjC,WAAM,GAAN,MAAM,CAAQ;QACd,yBAAoB,GAApB,oBAAoB,CAAwB;QAC5C,4BAAuB,GAAvB,uBAAuB,CAA2B;QAClD,gBAAW,GAAX,WAAW,CAAc;IACpC,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;;OAGG;IACH,SAAS,CAAC,UAAiB,EAAE,KAAY;QACrC,MA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BACJ;gBAED,OAAO,GAAG,CAAA;YACd,CAAC,EAAE,EAAE,CAAC,CAAA;QACV,CAAC,CACJ,CAAA;IACL,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,QAA0B,EAAE,IAAmB;QACjE,MAAM,gBAAgB,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACrE,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IAC3C,CAAC;CACJ;AAxnBD,4EAwnBC","file":"RawSqlResultsToEntityTransformer.js","sourcesContent":["import { Driver } from \"../../driver/Driver\"\nimport { RelationIdLoadResult } from \"../relation-id/RelationIdLoadResult\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { Alias } from \"../Alias\"\nimport { RelationCountLoadResult } from \"../relation-count/RelationCountLoadResult\"\nimport { RelationMetadata } from \"../../metadata/RelationMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { QueryExpressionMap } from \"../QueryExpressionMap\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { QueryRunner } from \"../..\"\nimport { DriverUtils } from \"../../driver/DriverUtils\"\nimport { ObjectUtils } from \"../../util/ObjectUtils\"\n\n/**\n * Transforms raw sql results returned from the database into entity object.\n * Entity is constructed based on its entity metadata.\n */\nexport class RawSqlResultsToEntityTransformer {\n /**\n * Contains a hashmap for every rawRelationIdResults given.\n * In the hashmap you will find the idMaps of a result under the hash of this.hashEntityIds for the result.\n */\n private relationIdMaps: Array<{ [idHash: string]: any[] }>\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected expressionMap: QueryExpressionMap,\n protected driver: Driver,\n protected rawRelationIdResults: RelationIdLoadResult[],\n protected rawRelationCountResults: RelationCountLoadResult[],\n protected queryRunner?: QueryRunner,\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Since db returns a duplicated rows of the data where accuracies of the same object can be duplicated\n * we need to group our result and we must have some unique id (primary key in our case)\n */\n transform(rawResults: any[], alias: Alias): any[] {\n const group = this.group(rawResults, alias)\n const entities: any[] = []\n group.forEach((results) => {\n const entity = this.transformRawResultsGroup(results, alias)\n if (\n entity !== undefined &&\n !Object.values(entity).every((value) => value === null)\n )\n entities.push(entity)\n })\n return entities\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Groups given raw results by ids of given alias.\n */\n protected group(rawResults: any[], alias: Alias): Map<string, any[]> {\n const map = new Map()\n const keys: string[] = []\n if (alias.metadata.tableType === \"view\") {\n keys.push(\n ...alias.metadata.columns.map((column) =>\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n ),\n ),\n )\n } else {\n keys.push(\n ...alias.metadata.primaryColumns.map((column) =>\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n ),\n ),\n )\n }\n rawResults.forEach((rawResult) => {\n const id = keys\n .map((key) => {\n const keyValue = rawResult[key]\n\n if (Buffer.isBuffer(keyValue)) {\n return keyValue.toString(\"hex\")\n }\n\n if (ObjectUtils.isObject(keyValue)) {\n return JSON.stringify(keyValue)\n }\n\n return keyValue\n })\n .join(\"_\") // todo: check partial\n\n const items = map.get(id)\n if (!items) {\n map.set(id, [rawResult])\n } else {\n items.push(rawResult)\n }\n })\n return map\n }\n\n /**\n * Transforms set of data results into single entity.\n */\n protected transformRawResultsGroup(\n rawResults: any[],\n alias: Alias,\n ): ObjectLiteral | undefined {\n // let hasColumns = false; // , hasEmbeddedColumns = false, hasParentColumns = false, hasParentEmbeddedColumns = false;\n let metadata = alias.metadata\n\n if (metadata.discriminatorColumn) {\n const discriminatorValues = rawResults.map(\n (result) =>\n result[\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n alias.metadata.discriminatorColumn!.databaseName,\n )\n ],\n )\n const discriminatorMetadata = metadata.childEntityMetadatas.find(\n (childEntityMetadata) => {\n return (\n typeof discriminatorValues.find(\n (value) =>\n value ===\n childEntityMetadata.discriminatorValue,\n ) !== \"undefined\"\n )\n },\n )\n if (discriminatorMetadata) metadata = discriminatorMetadata\n }\n let entity: any = metadata.create(this.queryRunner, {\n fromDeserializer: true,\n pojo: this.expressionMap.options.indexOf(\"create-pojo\") !== -1,\n })\n\n // get value from columns selections and put them into newly created entity\n const hasColumns = this.transformColumns(\n rawResults,\n alias,\n entity,\n metadata,\n )\n const hasRelations = this.transformJoins(\n rawResults,\n entity,\n alias,\n metadata,\n )\n const hasRelationIds = this.transformRelationIds(\n rawResults,\n alias,\n entity,\n metadata,\n )\n const hasRelationCounts = this.transformRelationCounts(\n rawResults,\n alias,\n entity,\n )\n\n // if we have at least one selected column then return this entity\n // since entity must have at least primary columns to be really selected and transformed into entity\n if (hasColumns) return entity\n\n // if we don't have any selected column we should not return entity,\n // except for the case when entity only contain a primary column as a relation to another entity\n // in this case its absolutely possible our entity to not have any columns except a single relation\n const hasOnlyVirtualPrimaryColumns =\n metadata.primaryColumns.filter(\n (column) => column.isVirtual === false,\n ).length === 0 // todo: create metadata.hasOnlyVirtualPrimaryColumns\n if (\n hasOnlyVirtualPrimaryColumns &&\n (hasRelations || hasRelationIds || hasRelationCounts)\n )\n return entity\n\n return undefined\n }\n\n // get value from columns selections and put them into object\n protected transformColumns(\n rawResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n metadata: EntityMetadata,\n ): boolean {\n let hasData = false\n metadata.columns.forEach((column) => {\n // if table inheritance is used make sure this column is not child's column\n if (\n metadata.childEntityMetadatas.length > 0 &&\n metadata.childEntityMetadatas.findIndex(\n (childMetadata) => childMetadata.target === column.target,\n ) !== -1\n )\n return\n\n const value =\n rawResults[0][\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n )\n ]\n if (value === undefined || column.isVirtual) return\n\n // if user does not selected the whole entity or he used partial selection and does not select this particular column\n // then we don't add this column and its value into the entity\n if (\n !this.expressionMap.selects.find(\n (select) =>\n select.selection === alias.name ||\n select.selection ===\n alias.name + \".\" + column.propertyPath,\n )\n )\n return\n\n column.setEntityValue(\n entity,\n this.driver.prepareHydratedValue(value, column),\n )\n if (value !== null)\n // we don't mark it as has data because if we will have all nulls in our object - we don't need such object\n hasData = true\n })\n return hasData\n }\n\n /**\n * Transforms joined entities in the given raw results by a given alias and stores to the given (parent) entity\n */\n protected transformJoins(\n rawResults: any[],\n entity: ObjectLiteral,\n alias: Alias,\n metadata: EntityMetadata,\n ) {\n let hasData = false\n\n // let discriminatorValue: string = \"\";\n // if (metadata.discriminatorColumn)\n // discriminatorValue = rawResults[0][DriverUtils.buildAlias(this.connection.driver, alias.name, alias.metadata.discriminatorColumn!.databaseName)];\n\n this.expressionMap.joinAttributes.forEach((join) => {\n // todo: we have problem here - when inner joins are used without selects it still create empty array\n\n // skip joins without metadata\n if (!join.metadata) return\n\n // if simple left or inner join was performed without selection then we don't need to do anything\n if (!join.isSelected) return\n\n // this check need to avoid setting properties than not belong to entity when single table inheritance used. (todo: check if we still need it)\n // const metadata = metadata.childEntityMetadatas.find(childEntityMetadata => discriminatorValue === childEntityMetadata.discriminatorValue);\n if (\n join.relation &&\n !metadata.relations.find(\n (relation) => relation === join.relation,\n )\n )\n return\n\n // some checks to make sure this join is for current alias\n if (join.mapToProperty) {\n if (join.mapToPropertyParentAlias !== alias.name) return\n } else {\n if (\n !join.relation ||\n join.parentAlias !== alias.name ||\n join.relationPropertyPath !== join.relation!.propertyPath\n )\n return\n }\n\n // transform joined data into entities\n let result: any = this.transform(rawResults, join.alias)\n result = !join.isMany ? result[0] : result\n result = !join.isMany && result === undefined ? null : result // this is needed to make relations to return null when its joined but nothing was found in the database\n if (result === undefined)\n // if nothing was joined then simply return\n return\n\n // if join was mapped to some property then save result to that property\n if (join.mapToPropertyPropertyName) {\n entity[join.mapToPropertyPropertyName] = result // todo: fix embeds\n } else {\n // otherwise set to relation\n join.relation!.setEntityValue(entity, result)\n }\n\n hasData = true\n })\n return hasData\n }\n\n protected transformRelationIds(\n rawSqlResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n metadata: EntityMetadata,\n ): boolean {\n let hasData = false\n this.rawRelationIdResults.forEach((rawRelationIdResult, index) => {\n if (\n rawRelationIdResult.relationIdAttribute.parentAlias !==\n alias.name\n )\n return\n\n const relation = rawRelationIdResult.relationIdAttribute.relation\n const valueMap = this.createValueMapFromJoinColumns(\n relation,\n rawRelationIdResult.relationIdAttribute.parentAlias,\n rawSqlResults,\n )\n if (valueMap === undefined || valueMap === null) {\n return\n }\n\n // prepare common data for this call\n this.prepareDataForTransformRelationIds()\n\n // Extract idMaps from prepared data by hash\n const hash = this.hashEntityIds(relation, valueMap)\n const idMaps = this.relationIdMaps[index][hash] || []\n\n // Map data to properties\n const properties =\n rawRelationIdResult.relationIdAttribute.mapToPropertyPropertyPath.split(\n \".\",\n )\n const mapToProperty = (\n properties: string[],\n map: ObjectLiteral,\n value: any,\n ): any => {\n const property = properties.shift()\n if (property && properties.length === 0) {\n map[property] = value\n return map\n }\n if (property && properties.length > 0) {\n mapToProperty(properties, map[property], value)\n } else {\n return map\n }\n }\n if (relation.isOneToOne || relation.isManyToOne) {\n if (idMaps[0] !== undefined) {\n mapToProperty(properties, entity, idMaps[0])\n hasData = true\n }\n } else {\n mapToProperty(properties, entity, idMaps)\n hasData = hasData || idMaps.length > 0\n }\n })\n\n return hasData\n }\n\n protected transformRelationCounts(\n rawSqlResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n ): boolean {\n let hasData = false\n this.rawRelationCountResults\n .filter(\n (rawRelationCountResult) =>\n rawRelationCountResult.relationCountAttribute\n .parentAlias === alias.name,\n )\n .forEach((rawRelationCountResult) => {\n const relation =\n rawRelationCountResult.relationCountAttribute.relation\n let referenceColumnName: string\n\n if (relation.isOneToMany) {\n referenceColumnName =\n relation.inverseRelation!.joinColumns[0]\n .referencedColumn!.databaseName // todo: fix joinColumns[0]\n } else {\n referenceColumnName = relation.isOwning\n ? relation.joinColumns[0].referencedColumn!.databaseName\n : relation.inverseRelation!.joinColumns[0]\n .referencedColumn!.databaseName\n }\n\n const referenceColumnValue =\n rawSqlResults[0][\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n referenceColumnName,\n )\n ] // we use zero index since its grouped data // todo: selection with alias for entity columns wont work\n if (\n referenceColumnValue !== undefined &&\n referenceColumnValue !== null\n ) {\n entity[\n rawRelationCountResult.relationCountAttribute.mapToPropertyPropertyName\n ] = 0\n rawRelationCountResult.results\n .filter(\n (result) =>\n result[\"parentId\"] === referenceColumnValue,\n )\n .forEach((result) => {\n entity[\n rawRelationCountResult.relationCountAttribute.mapToPropertyPropertyName\n ] = parseInt(result[\"cnt\"])\n hasData = true\n })\n }\n })\n\n return hasData\n }\n\n private createValueMapFromJoinColumns(\n relation: RelationMetadata,\n parentAlias: string,\n rawSqlResults: any[],\n ): ObjectLiteral {\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.entityMetadata.primaryColumns.map(\n (joinColumn) => joinColumn,\n )\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.joinColumns.map(\n (joinColumn) => joinColumn,\n )\n } else {\n if (relation.isOwning) {\n columns = relation.joinColumns.map((joinColumn) => joinColumn)\n } else {\n columns = relation.inverseRelation!.inverseJoinColumns.map(\n (joinColumn) => joinColumn,\n )\n }\n }\n return columns.reduce((valueMap, column) => {\n rawSqlResults.forEach((rawSqlResult) => {\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n valueMap[column.databaseName] =\n this.driver.prepareHydratedValue(\n rawSqlResult[\n DriverUtils.buildAlias(\n this.driver,\n parentAlias,\n column.databaseName,\n )\n ],\n column,\n )\n } else {\n valueMap[column.databaseName] =\n this.driver.prepareHydratedValue(\n rawSqlResult[\n DriverUtils.buildAlias(\n this.driver,\n parentAlias,\n column.referencedColumn!.databaseName,\n )\n ],\n column,\n )\n }\n })\n return valueMap\n }, {} as ObjectLiteral)\n }\n\n private extractEntityPrimaryIds(\n relation: RelationMetadata,\n relationIdRawResult: any,\n ) {\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.entityMetadata.primaryColumns.map(\n (joinColumn) => joinColumn,\n )\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.joinColumns.map(\n (joinColumn) => joinColumn,\n )\n } else {\n if (relation.isOwning) {\n columns = relation.joinColumns.map((joinColumn) => joinColumn)\n } else {\n columns = relation.inverseRelation!.inverseJoinColumns.map(\n (joinColumn) => joinColumn,\n )\n }\n }\n return columns.reduce((data, column) => {\n data[column.databaseName] = relationIdRawResult[column.databaseName]\n return data\n }, {} as ObjectLiteral)\n }\n\n /*private removeVirtualColumns(entity: ObjectLiteral, alias: Alias) {\n const virtualColumns = this.expressionMap.selects\n .filter(select => select.virtual)\n .map(select => select.selection.replace(alias.name + \".\", \"\"));\n\n virtualColumns.forEach(virtualColumn => delete entity[virtualColumn]);\n }*/\n\n /** Prepare data to run #transformRelationIds, as a lot of result independent data is needed in every call */\n private prepareDataForTransformRelationIds() {\n // Return early if the relationIdMaps were already calculated\n if (this.relationIdMaps) {\n return\n }\n\n // Ensure this prepare function is only called once\n this.relationIdMaps = this.rawRelationIdResults.map(\n (rawRelationIdResult) => {\n const relation =\n rawRelationIdResult.relationIdAttribute.relation\n\n // Calculate column metadata\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.joinColumns\n } else if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n columns = relation.inverseEntityMetadata.primaryColumns\n } else {\n // ManyToMany\n if (relation.isOwning) {\n columns = relation.inverseJoinColumns\n } else {\n columns = relation.inverseRelation!.joinColumns\n }\n }\n\n // Calculate the idMaps for the rawRelationIdResult\n return rawRelationIdResult.results.reduce((agg, result) => {\n let idMap = columns.reduce((idMap, column) => {\n let value = result[column.databaseName]\n if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n if (\n column.isVirtual &&\n column.referencedColumn &&\n column.referencedColumn.propertyName !==\n column.propertyName\n ) {\n // if column is a relation\n value =\n column.referencedColumn.createValueMap(\n value,\n )\n }\n\n return OrmUtils.mergeDeep(\n idMap,\n column.createValueMap(value),\n )\n }\n if (column.referencedColumn!.referencedColumn) {\n // if column is a relation\n value =\n column.referencedColumn!.referencedColumn!.createValueMap(\n value,\n )\n }\n\n return OrmUtils.mergeDeep(\n idMap,\n column.referencedColumn!.createValueMap(value),\n )\n }, {} as ObjectLiteral)\n\n if (\n columns.length === 1 &&\n !rawRelationIdResult.relationIdAttribute.disableMixedMap\n ) {\n if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n idMap = columns[0].getEntityValue(idMap)\n } else {\n idMap =\n columns[0].referencedColumn!.getEntityValue(\n idMap,\n )\n }\n }\n\n // If an idMap is found, set it in the aggregator under the correct hash\n if (idMap !== undefined) {\n const hash = this.hashEntityIds(relation, result)\n\n if (agg[hash]) {\n agg[hash].push(idMap)\n } else {\n agg[hash] = [idMap]\n }\n }\n\n return agg\n }, {})\n },\n )\n }\n\n /**\n * Use a simple JSON.stringify to create a simple hash of the primary ids of an entity.\n * As this.extractEntityPrimaryIds always creates the primary id object in the same order, if the same relation is\n * given, a simple JSON.stringify should be enough to get a unique hash per entity!\n */\n private hashEntityIds(relation: RelationMetadata, data: ObjectLiteral) {\n const entityPrimaryIds = this.extractEntityPrimaryIds(relation, data)\n return JSON.stringify(entityPrimaryIds)\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts"],"names":[],"mappings":";;;AAOA,kDAA8C;AAI9C,0DAAsD;AACtD,wDAAoD;AAEpD;;;GAGG;AACH,MAAa,gCAAgC;IAOzC,4EAA4E;IAC5E,cAAc;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C,CAAC,CAAC,CAAC,gBAAiB,CAAC,cAAc,CACvC,KAAK,CACR,CAAA;qBACR;iBACJ;gBAED,wEAAwE;gBACxE,IAAI,KAAK,KAAK,SAAS,EAAE;oBACrB,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;oBAEjD,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE;wBACX,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;qBACxB;yBAAM;wBACH,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;qBACtB;iBACJ;gBAED,OAAO,GAAG,CAAA;YACd,CAAC,EAAE,EAAE,CAAC,CAAA;QACV,CAAC,CACJ,CAAA;IACL,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,QAA0B,EAAE,IAAmB;QACjE,MAAM,gBAAgB,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACrE,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAA;IAC3C,CAAC;CACJ;AA3nBD,4EA2nBC","file":"RawSqlResultsToEntityTransformer.js","sourcesContent":["import { Driver } from \"../../driver/Driver\"\nimport { RelationIdLoadResult } from \"../relation-id/RelationIdLoadResult\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ColumnMetadata } from \"../../metadata/ColumnMetadata\"\nimport { Alias } from \"../Alias\"\nimport { RelationCountLoadResult } from \"../relation-count/RelationCountLoadResult\"\nimport { RelationMetadata } from \"../../metadata/RelationMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { QueryExpressionMap } from \"../QueryExpressionMap\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { QueryRunner } from \"../..\"\nimport { DriverUtils } from \"../../driver/DriverUtils\"\nimport { ObjectUtils } from \"../../util/ObjectUtils\"\n\n/**\n * Transforms raw sql results returned from the database into entity object.\n * Entity is constructed based on its entity metadata.\n */\nexport class RawSqlResultsToEntityTransformer {\n /**\n * Contains a hashmap for every rawRelationIdResults given.\n * In the hashmap you will find the idMaps of a result under the hash of this.hashEntityIds for the result.\n */\n private relationIdMaps: Array<{ [idHash: string]: any[] }>\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n protected expressionMap: QueryExpressionMap,\n protected driver: Driver,\n protected rawRelationIdResults: RelationIdLoadResult[],\n protected rawRelationCountResults: RelationCountLoadResult[],\n protected queryRunner?: QueryRunner,\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Since db returns a duplicated rows of the data where accuracies of the same object can be duplicated\n * we need to group our result and we must have some unique id (primary key in our case)\n */\n transform(rawResults: any[], alias: Alias): any[] {\n const group = this.group(rawResults, alias)\n const entities: any[] = []\n group.forEach((results) => {\n const entity = this.transformRawResultsGroup(results, alias)\n if (\n entity !== undefined &&\n !Object.values(entity).every((value) => value === null)\n )\n entities.push(entity)\n })\n return entities\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Groups given raw results by ids of given alias.\n */\n protected group(rawResults: any[], alias: Alias): Map<string, any[]> {\n const map = new Map()\n const keys: string[] = []\n if (alias.metadata.tableType === \"view\") {\n keys.push(\n ...alias.metadata.columns.map((column) =>\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n ),\n ),\n )\n } else {\n keys.push(\n ...alias.metadata.primaryColumns.map((column) =>\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n ),\n ),\n )\n }\n rawResults.forEach((rawResult) => {\n const id = keys\n .map((key) => {\n const keyValue = rawResult[key]\n\n if (Buffer.isBuffer(keyValue)) {\n return keyValue.toString(\"hex\")\n }\n\n if (ObjectUtils.isObject(keyValue)) {\n return JSON.stringify(keyValue)\n }\n\n return keyValue\n })\n .join(\"_\") // todo: check partial\n\n const items = map.get(id)\n if (!items) {\n map.set(id, [rawResult])\n } else {\n items.push(rawResult)\n }\n })\n return map\n }\n\n /**\n * Transforms set of data results into single entity.\n */\n protected transformRawResultsGroup(\n rawResults: any[],\n alias: Alias,\n ): ObjectLiteral | undefined {\n // let hasColumns = false; // , hasEmbeddedColumns = false, hasParentColumns = false, hasParentEmbeddedColumns = false;\n let metadata = alias.metadata\n\n if (metadata.discriminatorColumn) {\n const discriminatorValues = rawResults.map(\n (result) =>\n result[\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n alias.metadata.discriminatorColumn!.databaseName,\n )\n ],\n )\n const discriminatorMetadata = metadata.childEntityMetadatas.find(\n (childEntityMetadata) => {\n return (\n typeof discriminatorValues.find(\n (value) =>\n value ===\n childEntityMetadata.discriminatorValue,\n ) !== \"undefined\"\n )\n },\n )\n if (discriminatorMetadata) metadata = discriminatorMetadata\n }\n let entity: any = metadata.create(this.queryRunner, {\n fromDeserializer: true,\n pojo: this.expressionMap.options.indexOf(\"create-pojo\") !== -1,\n })\n\n // get value from columns selections and put them into newly created entity\n const hasColumns = this.transformColumns(\n rawResults,\n alias,\n entity,\n metadata,\n )\n const hasRelations = this.transformJoins(\n rawResults,\n entity,\n alias,\n metadata,\n )\n const hasRelationIds = this.transformRelationIds(\n rawResults,\n alias,\n entity,\n metadata,\n )\n const hasRelationCounts = this.transformRelationCounts(\n rawResults,\n alias,\n entity,\n )\n\n // if we have at least one selected column then return this entity\n // since entity must have at least primary columns to be really selected and transformed into entity\n if (hasColumns) return entity\n\n // if we don't have any selected column we should not return entity,\n // except for the case when entity only contain a primary column as a relation to another entity\n // in this case its absolutely possible our entity to not have any columns except a single relation\n const hasOnlyVirtualPrimaryColumns =\n metadata.primaryColumns.filter(\n (column) => column.isVirtual === false,\n ).length === 0 // todo: create metadata.hasOnlyVirtualPrimaryColumns\n if (\n hasOnlyVirtualPrimaryColumns &&\n (hasRelations || hasRelationIds || hasRelationCounts)\n )\n return entity\n\n return undefined\n }\n\n // get value from columns selections and put them into object\n protected transformColumns(\n rawResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n metadata: EntityMetadata,\n ): boolean {\n let hasData = false\n metadata.columns.forEach((column) => {\n // if table inheritance is used make sure this column is not child's column\n if (\n metadata.childEntityMetadatas.length > 0 &&\n metadata.childEntityMetadatas.findIndex(\n (childMetadata) => childMetadata.target === column.target,\n ) !== -1\n )\n return\n\n const value =\n rawResults[0][\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n column.databaseName,\n )\n ]\n if (value === undefined || column.isVirtual) return\n\n // if user does not selected the whole entity or he used partial selection and does not select this particular column\n // then we don't add this column and its value into the entity\n if (\n !this.expressionMap.selects.find(\n (select) =>\n select.selection === alias.name ||\n select.selection ===\n alias.name + \".\" + column.propertyPath,\n )\n )\n return\n\n column.setEntityValue(\n entity,\n this.driver.prepareHydratedValue(value, column),\n )\n if (value !== null)\n // we don't mark it as has data because if we will have all nulls in our object - we don't need such object\n hasData = true\n })\n return hasData\n }\n\n /**\n * Transforms joined entities in the given raw results by a given alias and stores to the given (parent) entity\n */\n protected transformJoins(\n rawResults: any[],\n entity: ObjectLiteral,\n alias: Alias,\n metadata: EntityMetadata,\n ) {\n let hasData = false\n\n // let discriminatorValue: string = \"\";\n // if (metadata.discriminatorColumn)\n // discriminatorValue = rawResults[0][DriverUtils.buildAlias(this.connection.driver, alias.name, alias.metadata.discriminatorColumn!.databaseName)];\n\n this.expressionMap.joinAttributes.forEach((join) => {\n // todo: we have problem here - when inner joins are used without selects it still create empty array\n\n // skip joins without metadata\n if (!join.metadata) return\n\n // if simple left or inner join was performed without selection then we don't need to do anything\n if (!join.isSelected) return\n\n // this check need to avoid setting properties than not belong to entity when single table inheritance used. (todo: check if we still need it)\n // const metadata = metadata.childEntityMetadatas.find(childEntityMetadata => discriminatorValue === childEntityMetadata.discriminatorValue);\n if (\n join.relation &&\n !metadata.relations.find(\n (relation) => relation === join.relation,\n )\n )\n return\n\n // some checks to make sure this join is for current alias\n if (join.mapToProperty) {\n if (join.mapToPropertyParentAlias !== alias.name) return\n } else {\n if (\n !join.relation ||\n join.parentAlias !== alias.name ||\n join.relationPropertyPath !== join.relation!.propertyPath\n )\n return\n }\n\n // transform joined data into entities\n let result: any = this.transform(rawResults, join.alias)\n result = !join.isMany ? result[0] : result\n result = !join.isMany && result === undefined ? null : result // this is needed to make relations to return null when its joined but nothing was found in the database\n if (result === undefined)\n // if nothing was joined then simply return\n return\n\n // if join was mapped to some property then save result to that property\n if (join.mapToPropertyPropertyName) {\n entity[join.mapToPropertyPropertyName] = result // todo: fix embeds\n } else {\n // otherwise set to relation\n join.relation!.setEntityValue(entity, result)\n }\n\n hasData = true\n })\n return hasData\n }\n\n protected transformRelationIds(\n rawSqlResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n metadata: EntityMetadata,\n ): boolean {\n let hasData = false\n this.rawRelationIdResults.forEach((rawRelationIdResult, index) => {\n if (\n rawRelationIdResult.relationIdAttribute.parentAlias !==\n alias.name\n )\n return\n\n const relation = rawRelationIdResult.relationIdAttribute.relation\n const valueMap = this.createValueMapFromJoinColumns(\n relation,\n rawRelationIdResult.relationIdAttribute.parentAlias,\n rawSqlResults,\n )\n if (valueMap === undefined || valueMap === null) {\n return\n }\n\n // prepare common data for this call\n this.prepareDataForTransformRelationIds()\n\n // Extract idMaps from prepared data by hash\n const hash = this.hashEntityIds(relation, valueMap)\n const idMaps = this.relationIdMaps[index][hash] || []\n\n // Map data to properties\n const properties =\n rawRelationIdResult.relationIdAttribute.mapToPropertyPropertyPath.split(\n \".\",\n )\n const mapToProperty = (\n properties: string[],\n map: ObjectLiteral,\n value: any,\n ): any => {\n const property = properties.shift()\n if (property && properties.length === 0) {\n map[property] = value\n return map\n }\n if (property && properties.length > 0) {\n mapToProperty(properties, map[property], value)\n } else {\n return map\n }\n }\n if (relation.isOneToOne || relation.isManyToOne) {\n if (idMaps[0] !== undefined) {\n mapToProperty(properties, entity, idMaps[0])\n hasData = true\n }\n } else {\n mapToProperty(properties, entity, idMaps)\n hasData = hasData || idMaps.length > 0\n }\n })\n\n return hasData\n }\n\n protected transformRelationCounts(\n rawSqlResults: any[],\n alias: Alias,\n entity: ObjectLiteral,\n ): boolean {\n let hasData = false\n this.rawRelationCountResults\n .filter(\n (rawRelationCountResult) =>\n rawRelationCountResult.relationCountAttribute\n .parentAlias === alias.name,\n )\n .forEach((rawRelationCountResult) => {\n const relation =\n rawRelationCountResult.relationCountAttribute.relation\n let referenceColumnName: string\n\n if (relation.isOneToMany) {\n referenceColumnName =\n relation.inverseRelation!.joinColumns[0]\n .referencedColumn!.databaseName // todo: fix joinColumns[0]\n } else {\n referenceColumnName = relation.isOwning\n ? relation.joinColumns[0].referencedColumn!.databaseName\n : relation.inverseRelation!.joinColumns[0]\n .referencedColumn!.databaseName\n }\n\n const referenceColumnValue =\n rawSqlResults[0][\n DriverUtils.buildAlias(\n this.driver,\n alias.name,\n referenceColumnName,\n )\n ] // we use zero index since its grouped data // todo: selection with alias for entity columns wont work\n if (\n referenceColumnValue !== undefined &&\n referenceColumnValue !== null\n ) {\n entity[\n rawRelationCountResult.relationCountAttribute.mapToPropertyPropertyName\n ] = 0\n rawRelationCountResult.results\n .filter(\n (result) =>\n result[\"parentId\"] === referenceColumnValue,\n )\n .forEach((result) => {\n entity[\n rawRelationCountResult.relationCountAttribute.mapToPropertyPropertyName\n ] = parseInt(result[\"cnt\"])\n hasData = true\n })\n }\n })\n\n return hasData\n }\n\n private createValueMapFromJoinColumns(\n relation: RelationMetadata,\n parentAlias: string,\n rawSqlResults: any[],\n ): ObjectLiteral {\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.entityMetadata.primaryColumns.map(\n (joinColumn) => joinColumn,\n )\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.joinColumns.map(\n (joinColumn) => joinColumn,\n )\n } else {\n if (relation.isOwning) {\n columns = relation.joinColumns.map((joinColumn) => joinColumn)\n } else {\n columns = relation.inverseRelation!.inverseJoinColumns.map(\n (joinColumn) => joinColumn,\n )\n }\n }\n return columns.reduce((valueMap, column) => {\n rawSqlResults.forEach((rawSqlResult) => {\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n valueMap[column.databaseName] =\n this.driver.prepareHydratedValue(\n rawSqlResult[\n DriverUtils.buildAlias(\n this.driver,\n parentAlias,\n column.databaseName,\n )\n ],\n column,\n )\n } else {\n valueMap[column.databaseName] =\n this.driver.prepareHydratedValue(\n rawSqlResult[\n DriverUtils.buildAlias(\n this.driver,\n parentAlias,\n column.referencedColumn!.databaseName,\n )\n ],\n column,\n )\n }\n })\n return valueMap\n }, {} as ObjectLiteral)\n }\n\n private extractEntityPrimaryIds(\n relation: RelationMetadata,\n relationIdRawResult: any,\n ) {\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.entityMetadata.primaryColumns.map(\n (joinColumn) => joinColumn,\n )\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.joinColumns.map(\n (joinColumn) => joinColumn,\n )\n } else {\n if (relation.isOwning) {\n columns = relation.joinColumns.map((joinColumn) => joinColumn)\n } else {\n columns = relation.inverseRelation!.inverseJoinColumns.map(\n (joinColumn) => joinColumn,\n )\n }\n }\n return columns.reduce((data, column) => {\n data[column.databaseName] = relationIdRawResult[column.databaseName]\n return data\n }, {} as ObjectLiteral)\n }\n\n /*private removeVirtualColumns(entity: ObjectLiteral, alias: Alias) {\n const virtualColumns = this.expressionMap.selects\n .filter(select => select.virtual)\n .map(select => select.selection.replace(alias.name + \".\", \"\"));\n\n virtualColumns.forEach(virtualColumn => delete entity[virtualColumn]);\n }*/\n\n /** Prepare data to run #transformRelationIds, as a lot of result independent data is needed in every call */\n private prepareDataForTransformRelationIds() {\n // Return early if the relationIdMaps were already calculated\n if (this.relationIdMaps) {\n return\n }\n\n // Ensure this prepare function is only called once\n this.relationIdMaps = this.rawRelationIdResults.map(\n (rawRelationIdResult) => {\n const relation =\n rawRelationIdResult.relationIdAttribute.relation\n\n // Calculate column metadata\n let columns: ColumnMetadata[]\n if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.joinColumns\n } else if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n columns = relation.inverseEntityMetadata.primaryColumns\n } else {\n // ManyToMany\n if (relation.isOwning) {\n columns = relation.inverseJoinColumns\n } else {\n columns = relation.inverseRelation!.joinColumns\n }\n }\n\n // Calculate the idMaps for the rawRelationIdResult\n return rawRelationIdResult.results.reduce((agg, result) => {\n let idMap = columns.reduce((idMap, column) => {\n let value = result[column.databaseName]\n if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n if (\n column.isVirtual &&\n column.referencedColumn &&\n column.referencedColumn.propertyName !==\n column.propertyName\n ) {\n // if column is a relation\n value =\n column.referencedColumn.createValueMap(\n value,\n )\n }\n\n return OrmUtils.mergeDeep(\n idMap,\n column.createValueMap(value),\n )\n }\n if (\n !column.isPrimary &&\n column.referencedColumn!.referencedColumn\n ) {\n // if column is a relation\n value =\n column.referencedColumn!.referencedColumn!.createValueMap(\n value,\n )\n }\n\n return OrmUtils.mergeDeep(\n idMap,\n column.referencedColumn!.createValueMap(value),\n )\n }, {} as ObjectLiteral)\n\n if (\n columns.length === 1 &&\n !rawRelationIdResult.relationIdAttribute.disableMixedMap\n ) {\n if (\n relation.isOneToMany ||\n relation.isOneToOneNotOwner\n ) {\n idMap = columns[0].getEntityValue(idMap)\n } else {\n idMap =\n columns[0].referencedColumn!.getEntityValue(\n idMap,\n )\n }\n }\n\n // If an idMap is found, set it in the aggregator under the correct hash\n if (idMap !== undefined) {\n const hash = this.hashEntityIds(relation, result)\n\n if (agg[hash]) {\n agg[hash].push(idMap)\n } else {\n agg[hash] = [idMap]\n }\n }\n\n return agg\n }, {})\n },\n )\n }\n\n /**\n * Use a simple JSON.stringify to create a simple hash of the primary ids of an entity.\n * As this.extractEntityPrimaryIds always creates the primary id object in the same order, if the same relation is\n * given, a simple JSON.stringify should be enough to get a unique hash per entity!\n */\n private hashEntityIds(relation: RelationMetadata, data: ObjectLiteral) {\n const entityPrimaryIds = this.extractEntityPrimaryIds(relation, data)\n return JSON.stringify(entityPrimaryIds)\n }\n}\n"],"sourceRoot":"../.."}
|