mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
This reverts commit 8150525354a7a66e68152ef7bd894ad93266d2af.
This commit is contained in:
parent
8150525354
commit
adce6985d8
@ -251,7 +251,7 @@ await timber.remove()
|
||||
|
||||
- for **MongoDB** (experimental)
|
||||
|
||||
`npm install mongodb@^4.10.0 --save`
|
||||
`npm install mongodb@^3.6.0 --save`
|
||||
|
||||
- for **NativeScript**, **react-native** and **Cordova**
|
||||
|
||||
|
||||
390
package-lock.json
generated
390
package-lock.json
generated
@ -40,8 +40,7 @@
|
||||
"@types/js-yaml": "^4.0.0",
|
||||
"@types/mkdirp": "^1.0.1",
|
||||
"@types/mocha": "^8.2.1",
|
||||
"@types/mongodb": "^4.0.7",
|
||||
"@types/node": "^18.8.3",
|
||||
"@types/node": "^14.14.31",
|
||||
"@types/rimraf": "^3.0.0",
|
||||
"@types/sha.js": "^2.4.0",
|
||||
"@types/sinon": "^9.0.10",
|
||||
@ -67,7 +66,7 @@
|
||||
"gulpclass": "^0.2.0",
|
||||
"husky": "^5.1.1",
|
||||
"mocha": "^8.3.0",
|
||||
"mongodb": "^4.10.0",
|
||||
"mongodb": "^3.6.4",
|
||||
"mssql": "^7.3.0",
|
||||
"mysql": "^2.18.1",
|
||||
"mysql2": "^2.2.5",
|
||||
@ -98,7 +97,7 @@
|
||||
"better-sqlite3": "^7.1.2 || ^8.0.0",
|
||||
"hdb-pool": "^0.1.6",
|
||||
"ioredis": "^5.0.4",
|
||||
"mongodb": "^4.10.0",
|
||||
"mongodb": "^3.6.0",
|
||||
"mssql": "^7.3.0",
|
||||
"mysql2": "^2.2.5 || ^3.0.1",
|
||||
"oracledb": "^5.1.0",
|
||||
@ -1310,16 +1309,6 @@
|
||||
"integrity": "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/mongodb": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-4.0.7.tgz",
|
||||
"integrity": "sha512-lPUYPpzA43baXqnd36cZ9xxorprybxXDzteVKCPAdp14ppHtFJHnXYvNpmBvtMUTb5fKXVv6sVbzo1LHkWhJlw==",
|
||||
"deprecated": "mongodb provides its own types. @types/mongodb is no longer needed.",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"mongodb": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/ms": {
|
||||
"version": "0.7.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",
|
||||
@ -1327,9 +1316,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
|
||||
"integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
|
||||
"version": "14.17.20",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.20.tgz",
|
||||
"integrity": "sha512-gI5Sl30tmhXsqkNvopFydP7ASc4c2cLfGNQrVKN3X90ADFWFsPEsotm/8JHSUJQKTHbwowAHtcJPeyVhtKv0TQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node-fetch": {
|
||||
@ -1467,22 +1456,6 @@
|
||||
"@types/vinyl": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||
"integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/whatwg-url": {
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz",
|
||||
"integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"@types/webidl-conversions": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/xml2js": {
|
||||
"version": "0.4.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.9.tgz",
|
||||
@ -2477,6 +2450,16 @@
|
||||
"file-uri-to-path": "1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/bl": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
||||
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"readable-stream": "^2.3.5",
|
||||
"safe-buffer": "^5.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
@ -2514,39 +2497,12 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/bson": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz",
|
||||
"integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==",
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz",
|
||||
"integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"buffer": "^5.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/bson/node_modules/buffer": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.1.13"
|
||||
"node": ">=0.6.19"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
@ -5511,12 +5467,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/gulp-replace/node_modules/@types/node": {
|
||||
"version": "14.18.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.31.tgz",
|
||||
"integrity": "sha512-vQAnaReSQkEDa8uwAyQby8bYGKu84R/deEc6mg5T8fX6gzCn8QW6rziSgsti1fNvsrswKUKPnVTi7uoB+u62Mw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/gulp-shell": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/gulp-shell/-/gulp-shell-0.8.0.tgz",
|
||||
@ -6009,10 +5959,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ip": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz",
|
||||
"integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==",
|
||||
"dev": true
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz",
|
||||
"integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/ip-regex": {
|
||||
"version": "2.1.0",
|
||||
@ -8070,74 +8021,42 @@
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb": {
|
||||
"version": "4.10.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
||||
"integrity": "sha512-My2QxLTw0Cc1O9gih0mz4mqo145Jq4rLAQx0Glk/Ha9iYBzYpt4I2QFNRIh35uNFNfe8KFQcdwY1/HKxXBkinw==",
|
||||
"version": "3.7.1",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.1.tgz",
|
||||
"integrity": "sha512-iSVgexYr8ID0ieeNFUbRfQeOZxOchRck6kEDVySQRaa8VIw/1Pm+/LgcpZcl/BWV6nT0L8lP9qyl7dRPJ6mnLw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"bson": "^4.7.0",
|
||||
"denque": "^2.1.0",
|
||||
"mongodb-connection-string-url": "^2.5.3",
|
||||
"socks": "^2.7.0"
|
||||
"bl": "^2.2.1",
|
||||
"bson": "^1.1.4",
|
||||
"denque": "^1.4.1",
|
||||
"optional-require": "^1.0.3",
|
||||
"safe-buffer": "^5.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.9.0"
|
||||
"node": ">=4"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"saslprep": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb-connection-string-url": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.4.tgz",
|
||||
"integrity": "sha512-SeAxuWs0ez3iI3vvmLk/j2y+zHwigTDKQhtdxTgt5ZCOQQS5+HW4g45/Xw5vzzbn7oQXCNQ24Z40AkJsizEy7w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/whatwg-url": "^8.2.1",
|
||||
"whatwg-url": "^11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb-connection-string-url/node_modules/tr46": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz",
|
||||
"integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"punycode": "^2.1.1"
|
||||
"saslprep": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb-connection-string-url/node_modules/webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb-connection-string-url/node_modules/whatwg-url": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz",
|
||||
"integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"tr46": "^3.0.0",
|
||||
"webidl-conversions": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb/node_modules/denque": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
"peerDependenciesMeta": {
|
||||
"aws4": {
|
||||
"optional": true
|
||||
},
|
||||
"bson-ext": {
|
||||
"optional": true
|
||||
},
|
||||
"kerberos": {
|
||||
"optional": true
|
||||
},
|
||||
"mongodb-client-encryption": {
|
||||
"optional": true
|
||||
},
|
||||
"mongodb-extjson": {
|
||||
"optional": true
|
||||
},
|
||||
"snappy": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
@ -8888,6 +8807,18 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/optional-require": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz",
|
||||
"integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"require-at": "^1.0.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/oracledb": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/oracledb/-/oracledb-5.2.0.tgz",
|
||||
@ -10189,6 +10120,15 @@
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-at": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz",
|
||||
"integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
@ -10563,6 +10503,7 @@
|
||||
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
|
||||
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">= 6.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
@ -10722,12 +10663,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/socks": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz",
|
||||
"integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==",
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.6.2.tgz",
|
||||
"integrity": "sha512-zDZhHhZRY9PxRruRMR7kMhnf3I8hDs4S3f9RecfnGxvcBHQcKcIH/oUcEWffsfl1XxdYlA7nnlGbbTvPz9D8gA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"ip": "^2.0.0",
|
||||
"ip": "^1.1.5",
|
||||
"smart-buffer": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
@ -13358,15 +13300,6 @@
|
||||
"integrity": "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/mongodb": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-4.0.7.tgz",
|
||||
"integrity": "sha512-lPUYPpzA43baXqnd36cZ9xxorprybxXDzteVKCPAdp14ppHtFJHnXYvNpmBvtMUTb5fKXVv6sVbzo1LHkWhJlw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"mongodb": "*"
|
||||
}
|
||||
},
|
||||
"@types/ms": {
|
||||
"version": "0.7.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",
|
||||
@ -13374,9 +13307,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "18.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.8.3.tgz",
|
||||
"integrity": "sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==",
|
||||
"version": "14.17.20",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.20.tgz",
|
||||
"integrity": "sha512-gI5Sl30tmhXsqkNvopFydP7ASc4c2cLfGNQrVKN3X90ADFWFsPEsotm/8JHSUJQKTHbwowAHtcJPeyVhtKv0TQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node-fetch": {
|
||||
@ -13513,22 +13446,6 @@
|
||||
"@types/vinyl": "*"
|
||||
}
|
||||
},
|
||||
"@types/webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||
"integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/whatwg-url": {
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz",
|
||||
"integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*",
|
||||
"@types/webidl-conversions": "*"
|
||||
}
|
||||
},
|
||||
"@types/xml2js": {
|
||||
"version": "0.4.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.9.tgz",
|
||||
@ -14291,6 +14208,16 @@
|
||||
"file-uri-to-path": "1.0.0"
|
||||
}
|
||||
},
|
||||
"bl": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
|
||||
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"readable-stream": "^2.3.5",
|
||||
"safe-buffer": "^5.1.1"
|
||||
}
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
@ -14325,25 +14252,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"bson": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-4.7.0.tgz",
|
||||
"integrity": "sha512-VrlEE4vuiO1WTpfof4VmaVolCVYkYTgB9iWgYNOrVlnifpME/06fhFRmONgBhClD5pFC1t9ZWqFUQEQAzY43bA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"buffer": "^5.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.1.13"
|
||||
}
|
||||
}
|
||||
}
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz",
|
||||
"integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==",
|
||||
"dev": true
|
||||
},
|
||||
"buffer": {
|
||||
"version": "6.0.3",
|
||||
@ -16692,14 +16604,6 @@
|
||||
"istextorbinary": "^3.0.0",
|
||||
"replacestream": "^4.0.3",
|
||||
"yargs-parser": ">=5.0.0-security.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "14.18.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.31.tgz",
|
||||
"integrity": "sha512-vQAnaReSQkEDa8uwAyQby8bYGKu84R/deEc6mg5T8fX6gzCn8QW6rziSgsti1fNvsrswKUKPnVTi7uoB+u62Mw==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"gulp-shell": {
|
||||
@ -17071,10 +16975,11 @@
|
||||
"dev": true
|
||||
},
|
||||
"ip": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz",
|
||||
"integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==",
|
||||
"dev": true
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz",
|
||||
"integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ip-regex": {
|
||||
"version": "2.1.0",
|
||||
@ -18695,61 +18600,17 @@
|
||||
"dev": true
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "4.10.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.10.0.tgz",
|
||||
"integrity": "sha512-My2QxLTw0Cc1O9gih0mz4mqo145Jq4rLAQx0Glk/Ha9iYBzYpt4I2QFNRIh35uNFNfe8KFQcdwY1/HKxXBkinw==",
|
||||
"version": "3.7.1",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.1.tgz",
|
||||
"integrity": "sha512-iSVgexYr8ID0ieeNFUbRfQeOZxOchRck6kEDVySQRaa8VIw/1Pm+/LgcpZcl/BWV6nT0L8lP9qyl7dRPJ6mnLw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bson": "^4.7.0",
|
||||
"denque": "^2.1.0",
|
||||
"mongodb-connection-string-url": "^2.5.3",
|
||||
"saslprep": "^1.0.3",
|
||||
"socks": "^2.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"denque": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"mongodb-connection-string-url": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.4.tgz",
|
||||
"integrity": "sha512-SeAxuWs0ez3iI3vvmLk/j2y+zHwigTDKQhtdxTgt5ZCOQQS5+HW4g45/Xw5vzzbn7oQXCNQ24Z40AkJsizEy7w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/whatwg-url": "^8.2.1",
|
||||
"whatwg-url": "^11.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"tr46": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz",
|
||||
"integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"punycode": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
||||
"dev": true
|
||||
},
|
||||
"whatwg-url": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz",
|
||||
"integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"tr46": "^3.0.0",
|
||||
"webidl-conversions": "^7.0.0"
|
||||
}
|
||||
}
|
||||
"bl": "^2.2.1",
|
||||
"bson": "^1.1.4",
|
||||
"denque": "^1.4.1",
|
||||
"optional-require": "^1.0.3",
|
||||
"safe-buffer": "^5.1.2",
|
||||
"saslprep": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
@ -19350,6 +19211,15 @@
|
||||
"is-wsl": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"optional-require": {
|
||||
"version": "1.1.8",
|
||||
"resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz",
|
||||
"integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"require-at": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"oracledb": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/oracledb/-/oracledb-5.2.0.tgz",
|
||||
@ -20363,6 +20233,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"require-at": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz",
|
||||
"integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==",
|
||||
"dev": true
|
||||
},
|
||||
"require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
@ -20643,7 +20519,8 @@
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
|
||||
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"snapdragon": {
|
||||
"version": "0.8.2",
|
||||
@ -20775,12 +20652,13 @@
|
||||
}
|
||||
},
|
||||
"socks": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz",
|
||||
"integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==",
|
||||
"version": "2.6.2",
|
||||
"resolved": "https://registry.npmjs.org/socks/-/socks-2.6.2.tgz",
|
||||
"integrity": "sha512-zDZhHhZRY9PxRruRMR7kMhnf3I8hDs4S3f9RecfnGxvcBHQcKcIH/oUcEWffsfl1XxdYlA7nnlGbbTvPz9D8gA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ip": "^2.0.0",
|
||||
"ip": "^1.1.5",
|
||||
"smart-buffer": "^4.2.0"
|
||||
}
|
||||
},
|
||||
|
||||
12
package.json
12
package.json
@ -98,7 +98,7 @@
|
||||
"@types/js-yaml": "^4.0.0",
|
||||
"@types/mkdirp": "^1.0.1",
|
||||
"@types/mocha": "^8.2.1",
|
||||
"@types/node": "^18.8.3",
|
||||
"@types/node": "^14.14.31",
|
||||
"@types/rimraf": "^3.0.0",
|
||||
"@types/sha.js": "^2.4.0",
|
||||
"@types/sinon": "^9.0.10",
|
||||
@ -124,7 +124,7 @@
|
||||
"gulpclass": "^0.2.0",
|
||||
"husky": "^5.1.1",
|
||||
"mocha": "^8.3.0",
|
||||
"mongodb": "^4.10.0",
|
||||
"mongodb": "^3.6.4",
|
||||
"mssql": "^7.3.0",
|
||||
"mysql": "^2.18.1",
|
||||
"mysql2": "^2.2.5",
|
||||
@ -149,7 +149,7 @@
|
||||
"better-sqlite3": "^7.1.2 || ^8.0.0",
|
||||
"hdb-pool": "^0.1.6",
|
||||
"ioredis": "^5.0.4",
|
||||
"mongodb": "^4.10.0",
|
||||
"mongodb": "^3.6.0",
|
||||
"mssql": "^7.3.0",
|
||||
"mysql2": "^2.2.5 || ^3.0.1",
|
||||
"oracledb": "^5.1.0",
|
||||
@ -235,14 +235,14 @@
|
||||
"yargs": "^17.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "rimraf ./build && tsc && mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test",
|
||||
"test-fast": "mocha --file ./build/compiled/test/utils/test-setup.js --bail --recursive --timeout 90000 ./build/compiled/test",
|
||||
"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 --end-of-line auto \"./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": {
|
||||
|
||||
@ -10,7 +10,6 @@ import {
|
||||
CannotExecuteNotConnectedError,
|
||||
EntityMetadataNotFoundError,
|
||||
QueryRunnerProviderAlreadyReleasedError,
|
||||
TypeORMError,
|
||||
} from "../error"
|
||||
import { TreeRepository } from "../repository/TreeRepository"
|
||||
import { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface"
|
||||
@ -36,6 +35,7 @@ import { RelationLoader } from "../query-builder/RelationLoader"
|
||||
import { ObjectUtils } from "../util/ObjectUtils"
|
||||
import { IsolationLevel } from "../driver/types/IsolationLevel"
|
||||
import { ReplicationMode } from "../driver/types/ReplicationMode"
|
||||
import { TypeORMError } from "../error"
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader"
|
||||
import { DriverUtils } from "../driver/DriverUtils"
|
||||
import { InstanceChecker } from "../util/InstanceChecker"
|
||||
|
||||
@ -1,10 +1,44 @@
|
||||
import { QueryRunner } from "../../query-runner/QueryRunner"
|
||||
import { ObjectLiteral } from "../../common/ObjectLiteral"
|
||||
import { TableColumn } from "../../schema-builder/table/TableColumn"
|
||||
import { Table } from "../../schema-builder/table/Table"
|
||||
import { TableForeignKey } from "../../schema-builder/table/TableForeignKey"
|
||||
import { TableIndex } from "../../schema-builder/table/TableIndex"
|
||||
import { View } from "../../schema-builder/view/View"
|
||||
// import {Connection} from "../../connection/Connection";
|
||||
import {
|
||||
AggregationCursor,
|
||||
BulkWriteOpResultObject,
|
||||
ChangeStream,
|
||||
ChangeStreamOptions,
|
||||
Code,
|
||||
Collection,
|
||||
CollectionAggregationOptions,
|
||||
CollectionBulkWriteOptions,
|
||||
CollectionInsertManyOptions,
|
||||
CollectionInsertOneOptions,
|
||||
CollectionOptions,
|
||||
CollStats,
|
||||
CommandCursor,
|
||||
Cursor,
|
||||
DeleteWriteOpResultObject,
|
||||
FindAndModifyWriteOpResultObject,
|
||||
FindOneAndReplaceOption,
|
||||
GeoHaystackSearchOptions,
|
||||
GeoNearOptions,
|
||||
InsertOneWriteOpResult,
|
||||
InsertWriteOpResult,
|
||||
MapReduceOptions,
|
||||
MongoClient,
|
||||
MongoCountPreferences,
|
||||
MongodbIndexOptions,
|
||||
OrderedBulkOperation,
|
||||
ParallelCollectionScanOptions,
|
||||
ReadPreference,
|
||||
ReplaceOneOptions,
|
||||
UnorderedBulkOperation,
|
||||
UpdateWriteOpResult,
|
||||
} from "./typings"
|
||||
import { DataSource } from "../../data-source/DataSource"
|
||||
import { ReadStream } from "../../platform/PlatformTools"
|
||||
import { MongoEntityManager } from "../../entity-manager/MongoEntityManager"
|
||||
import { SqlInMemory } from "../SqlInMemory"
|
||||
@ -13,53 +47,6 @@ import { Broadcaster } from "../../subscriber/Broadcaster"
|
||||
import { TableCheck } from "../../schema-builder/table/TableCheck"
|
||||
import { TableExclusion } from "../../schema-builder/table/TableExclusion"
|
||||
import { TypeORMError } from "../../error"
|
||||
|
||||
import {
|
||||
BulkWriteResult,
|
||||
AggregationCursor,
|
||||
MongoClient,
|
||||
Collection,
|
||||
FindCursor,
|
||||
Document,
|
||||
AggregateOptions,
|
||||
AnyBulkWriteOperation,
|
||||
BulkWriteOptions,
|
||||
Filter,
|
||||
CountOptions,
|
||||
CountDocumentsOptions,
|
||||
IndexSpecification,
|
||||
CreateIndexesOptions,
|
||||
IndexDescription,
|
||||
DeleteResult,
|
||||
DeleteOptions,
|
||||
CommandOperationOptions,
|
||||
FindOneAndDeleteOptions,
|
||||
ModifyResult,
|
||||
FindOneAndReplaceOptions,
|
||||
UpdateFilter,
|
||||
FindOneAndUpdateOptions,
|
||||
RenameOptions,
|
||||
ReplaceOptions,
|
||||
UpdateResult,
|
||||
CollStats,
|
||||
CollStatsOptions,
|
||||
ChangeStreamOptions,
|
||||
ChangeStream,
|
||||
UpdateOptions,
|
||||
ListIndexesOptions,
|
||||
ListIndexesCursor,
|
||||
OptionalId,
|
||||
InsertOneOptions,
|
||||
InsertOneResult,
|
||||
InsertManyResult,
|
||||
MapFunction,
|
||||
ReduceFunction,
|
||||
MapReduceOptions,
|
||||
UnorderedBulkOperation,
|
||||
OrderedBulkOperation,
|
||||
IndexInformationOptions,
|
||||
} from "mongodb"
|
||||
import { DataSource } from "../../data-source/DataSource"
|
||||
import { ReplicationMode } from "../types/ReplicationMode"
|
||||
|
||||
/**
|
||||
@ -150,8 +137,8 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
/**
|
||||
* Creates a cursor for a query that can be used to iterate over results from MongoDB.
|
||||
*/
|
||||
cursor(collectionName: string, filter: Filter<Document>): FindCursor<any> {
|
||||
return this.getCollection(collectionName).find(filter || {})
|
||||
cursor(collectionName: string, query?: ObjectLiteral): Cursor<any> {
|
||||
return this.getCollection(collectionName).find(query || {})
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,13 +146,10 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
aggregate(
|
||||
collectionName: string,
|
||||
pipeline: Document[],
|
||||
options?: AggregateOptions,
|
||||
pipeline: ObjectLiteral[],
|
||||
options?: CollectionAggregationOptions,
|
||||
): AggregationCursor<any> {
|
||||
return this.getCollection(collectionName).aggregate(
|
||||
pipeline,
|
||||
options || {},
|
||||
)
|
||||
return this.getCollection(collectionName).aggregate(pipeline, options)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,12 +157,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async bulkWrite(
|
||||
collectionName: string,
|
||||
operations: AnyBulkWriteOperation<Document>[],
|
||||
options?: BulkWriteOptions,
|
||||
): Promise<BulkWriteResult> {
|
||||
operations: ObjectLiteral[],
|
||||
options?: CollectionBulkWriteOptions,
|
||||
): Promise<BulkWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).bulkWrite(
|
||||
operations,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -187,26 +171,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async count(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
options?: CountOptions,
|
||||
): Promise<number> {
|
||||
return this.getCollection(collectionName).count(
|
||||
filter || {},
|
||||
options || {},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of matching documents in the db to a query.
|
||||
*/
|
||||
async countDocuments(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
options?: CountDocumentsOptions,
|
||||
query?: ObjectLiteral,
|
||||
options?: MongoCountPreferences,
|
||||
): Promise<any> {
|
||||
return this.getCollection(collectionName).countDocuments(
|
||||
filter || {},
|
||||
options || {},
|
||||
return await this.getCollection(collectionName).countDocuments(
|
||||
query || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -215,12 +185,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async createCollectionIndex(
|
||||
collectionName: string,
|
||||
indexSpec: IndexSpecification,
|
||||
options?: CreateIndexesOptions,
|
||||
fieldOrSpec: string | any,
|
||||
options?: MongodbIndexOptions,
|
||||
): Promise<string> {
|
||||
return this.getCollection(collectionName).createIndex(
|
||||
indexSpec,
|
||||
options || {},
|
||||
return await this.getCollection(collectionName).createIndex(
|
||||
fieldOrSpec,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -230,9 +200,11 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async createCollectionIndexes(
|
||||
collectionName: string,
|
||||
indexSpecs: IndexDescription[],
|
||||
): Promise<string[]> {
|
||||
return this.getCollection(collectionName).createIndexes(indexSpecs)
|
||||
indexSpecs: ObjectLiteral[],
|
||||
): Promise<void> {
|
||||
return await this.getCollection(collectionName).createIndexes(
|
||||
indexSpecs,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,12 +212,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async deleteMany(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
options: DeleteOptions,
|
||||
): Promise<DeleteResult> {
|
||||
return this.getCollection(collectionName).deleteMany(
|
||||
filter,
|
||||
options || {},
|
||||
query: ObjectLiteral,
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).deleteMany(
|
||||
query,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -254,12 +226,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async deleteOne(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
options?: DeleteOptions,
|
||||
): Promise<DeleteResult> {
|
||||
return this.getCollection(collectionName).deleteOne(
|
||||
filter,
|
||||
options || {},
|
||||
query: ObjectLiteral,
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).deleteOne(
|
||||
query,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -268,14 +240,14 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async distinct(
|
||||
collectionName: string,
|
||||
key: any,
|
||||
filter: Filter<Document>,
|
||||
options?: CommandOperationOptions,
|
||||
key: string,
|
||||
query: ObjectLiteral,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
return this.getCollection(collectionName).distinct(
|
||||
return await this.getCollection(collectionName).distinct(
|
||||
key,
|
||||
filter,
|
||||
options || {},
|
||||
query,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -285,19 +257,19 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
async dropCollectionIndex(
|
||||
collectionName: string,
|
||||
indexName: string,
|
||||
options?: CommandOperationOptions,
|
||||
): Promise<Document> {
|
||||
return this.getCollection(collectionName).dropIndex(
|
||||
options?: CollectionOptions,
|
||||
): Promise<any> {
|
||||
return await this.getCollection(collectionName).dropIndex(
|
||||
indexName,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all indexes from the collection.
|
||||
*/
|
||||
async dropCollectionIndexes(collectionName: string): Promise<Document> {
|
||||
return this.getCollection(collectionName).dropIndexes()
|
||||
async dropCollectionIndexes(collectionName: string): Promise<any> {
|
||||
return await this.getCollection(collectionName).dropIndexes()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,12 +277,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async findOneAndDelete(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
options?: FindOneAndDeleteOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
return this.getCollection(collectionName).findOneAndDelete(
|
||||
filter,
|
||||
options || {},
|
||||
query: ObjectLiteral,
|
||||
options?: { projection?: Object; sort?: Object; maxTimeMS?: number },
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).findOneAndDelete(
|
||||
query,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -319,14 +291,14 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async findOneAndReplace(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
replacement: Document,
|
||||
options?: FindOneAndReplaceOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
return this.getCollection(collectionName).findOneAndReplace(
|
||||
filter,
|
||||
query: ObjectLiteral,
|
||||
replacement: Object,
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).findOneAndReplace(
|
||||
query,
|
||||
replacement,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -335,22 +307,74 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async findOneAndUpdate(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: FindOneAndUpdateOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
return this.getCollection(collectionName).findOneAndUpdate(
|
||||
filter,
|
||||
query: ObjectLiteral,
|
||||
update: Object,
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return await this.getCollection(collectionName).findOneAndUpdate(
|
||||
query,
|
||||
update,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a geo search using a geo haystack index on a collection.
|
||||
*/
|
||||
async geoHaystackSearch(
|
||||
collectionName: string,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: GeoHaystackSearchOptions,
|
||||
): Promise<any> {
|
||||
return await this.getCollection(collectionName).geoHaystackSearch(
|
||||
x,
|
||||
y,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the geoNear command to search for items in the collection.
|
||||
*/
|
||||
async geoNear(
|
||||
collectionName: string,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: GeoNearOptions,
|
||||
): Promise<any> {
|
||||
return await this.getCollection(collectionName).geoNear(x, y, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a group command across a collection.
|
||||
*/
|
||||
async group(
|
||||
collectionName: string,
|
||||
keys: Object | Array<any> | Function | Code,
|
||||
condition: Object,
|
||||
initial: Object,
|
||||
reduce: Function | Code,
|
||||
finalize: Function | Code,
|
||||
command: boolean,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
return await this.getCollection(collectionName).group(
|
||||
keys,
|
||||
condition,
|
||||
initial,
|
||||
reduce,
|
||||
finalize,
|
||||
command,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all the indexes on the collection.
|
||||
*/
|
||||
async collectionIndexes(collectionName: string): Promise<Document> {
|
||||
return this.getCollection(collectionName).indexes()
|
||||
async collectionIndexes(collectionName: string): Promise<any> {
|
||||
return await this.getCollection(collectionName).indexes()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,7 +384,7 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
collectionName: string,
|
||||
indexes: string | string[],
|
||||
): Promise<boolean> {
|
||||
return this.getCollection(collectionName).indexExists(indexes)
|
||||
return await this.getCollection(collectionName).indexExists(indexes)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -368,10 +392,10 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async collectionIndexInformation(
|
||||
collectionName: string,
|
||||
options?: IndexInformationOptions,
|
||||
options?: { full: boolean },
|
||||
): Promise<any> {
|
||||
return this.getCollection(collectionName).indexInformation(
|
||||
options || {},
|
||||
return await this.getCollection(collectionName).indexInformation(
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -380,7 +404,7 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
initializeOrderedBulkOp(
|
||||
collectionName: string,
|
||||
options?: BulkWriteOptions,
|
||||
options?: CollectionOptions,
|
||||
): OrderedBulkOperation {
|
||||
return this.getCollection(collectionName).initializeOrderedBulkOp(
|
||||
options,
|
||||
@ -392,7 +416,7 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
initializeUnorderedBulkOp(
|
||||
collectionName: string,
|
||||
options?: BulkWriteOptions,
|
||||
options?: CollectionOptions,
|
||||
): UnorderedBulkOperation {
|
||||
return this.getCollection(collectionName).initializeUnorderedBulkOp(
|
||||
options,
|
||||
@ -404,12 +428,12 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async insertMany(
|
||||
collectionName: string,
|
||||
docs: OptionalId<Document>[],
|
||||
options?: BulkWriteOptions,
|
||||
): Promise<InsertManyResult> {
|
||||
return this.getCollection(collectionName).insertMany(
|
||||
docs: ObjectLiteral[],
|
||||
options?: CollectionInsertManyOptions,
|
||||
): Promise<InsertWriteOpResult> {
|
||||
return await this.getCollection(collectionName).insertMany(
|
||||
docs,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -418,17 +442,17 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async insertOne(
|
||||
collectionName: string,
|
||||
doc: OptionalId<Document>,
|
||||
options?: InsertOneOptions,
|
||||
): Promise<InsertOneResult> {
|
||||
return this.getCollection(collectionName).insertOne(doc, options || {})
|
||||
doc: ObjectLiteral,
|
||||
options?: CollectionInsertOneOptions,
|
||||
): Promise<InsertOneWriteOpResult> {
|
||||
return await this.getCollection(collectionName).insertOne(doc, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the collection is a capped collection.
|
||||
*/
|
||||
async isCapped(collectionName: string): Promise<boolean> {
|
||||
return this.getCollection(collectionName).isCapped()
|
||||
async isCapped(collectionName: string): Promise<any> {
|
||||
return await this.getCollection(collectionName).isCapped()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -436,8 +460,11 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
listCollectionIndexes(
|
||||
collectionName: string,
|
||||
options?: ListIndexesOptions,
|
||||
): ListIndexesCursor {
|
||||
options?: {
|
||||
batchSize?: number
|
||||
readPreference?: ReadPreference | string
|
||||
},
|
||||
): CommandCursor {
|
||||
return this.getCollection(collectionName).listIndexes(options)
|
||||
}
|
||||
|
||||
@ -446,26 +473,46 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async mapReduce(
|
||||
collectionName: string,
|
||||
map: MapFunction,
|
||||
reduce: ReduceFunction | string,
|
||||
map: Function | string,
|
||||
reduce: Function | string,
|
||||
options?: MapReduceOptions,
|
||||
): Promise<Document | Document[]> {
|
||||
return this.getCollection(collectionName).mapReduce(
|
||||
): Promise<any> {
|
||||
return await this.getCollection(collectionName).mapReduce(
|
||||
map,
|
||||
reduce,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
|
||||
* There are no ordering guarantees for returned results.
|
||||
*/
|
||||
async parallelCollectionScan(
|
||||
collectionName: string,
|
||||
options?: ParallelCollectionScanOptions,
|
||||
): Promise<Cursor<any>[]> {
|
||||
return await this.getCollection(collectionName).parallelCollectionScan(
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
async reIndex(collectionName: string): Promise<any> {
|
||||
return await this.getCollection(collectionName).reIndex()
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
async rename(
|
||||
collectionName: string,
|
||||
newName: string,
|
||||
options?: RenameOptions,
|
||||
): Promise<Collection<Document>> {
|
||||
return this.getCollection(collectionName).rename(newName, options || {})
|
||||
options?: { dropTarget?: boolean },
|
||||
): Promise<Collection<any>> {
|
||||
return await this.getCollection(collectionName).rename(newName, options)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -473,14 +520,14 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async replaceOne(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
replacement: Document,
|
||||
options?: ReplaceOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
return this.getCollection(collectionName).replaceOne(
|
||||
filter,
|
||||
replacement,
|
||||
options || {},
|
||||
query: ObjectLiteral,
|
||||
doc: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return await this.getCollection(collectionName).replaceOne(
|
||||
query,
|
||||
doc,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -489,9 +536,9 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async stats(
|
||||
collectionName: string,
|
||||
options?: CollStatsOptions,
|
||||
options?: { scale: number },
|
||||
): Promise<CollStats> {
|
||||
return this.getCollection(collectionName).stats(options || {})
|
||||
return await this.getCollection(collectionName).stats(options)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -499,7 +546,7 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
watch(
|
||||
collectionName: string,
|
||||
pipeline?: Document[],
|
||||
pipeline?: Object[],
|
||||
options?: ChangeStreamOptions,
|
||||
): ChangeStream {
|
||||
return this.getCollection(collectionName).watch(pipeline, options)
|
||||
@ -510,14 +557,14 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async updateMany(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
return this.getCollection(collectionName).updateMany(
|
||||
filter,
|
||||
query: ObjectLiteral,
|
||||
update: ObjectLiteral,
|
||||
options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean },
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return await this.getCollection(collectionName).updateMany(
|
||||
query,
|
||||
update,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
@ -526,14 +573,14 @@ export class MongoQueryRunner implements QueryRunner {
|
||||
*/
|
||||
async updateOne(
|
||||
collectionName: string,
|
||||
filter: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
query: ObjectLiteral,
|
||||
update: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return await this.getCollection(collectionName).updateOne(
|
||||
filter,
|
||||
query,
|
||||
update,
|
||||
options || {},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -4855,31 +4855,14 @@ export interface FindOperatorsUnordered {
|
||||
|
||||
/**
|
||||
* Add a remove operation to the bulk operation.
|
||||
*
|
||||
* @deprecated deprecated since mongodb@4.0, in new code, use delete instead
|
||||
*/
|
||||
remove(): UnorderedBulkOperation
|
||||
|
||||
/**
|
||||
* Add a remove one operation to the bulk operation.
|
||||
*
|
||||
* @deprecated deprecated since mongodb@4.0, in new code, use deleteOne instead
|
||||
*/
|
||||
removeOne(): UnorderedBulkOperation
|
||||
|
||||
/**
|
||||
* Add a delete operation to the bulk operation.
|
||||
*
|
||||
* @deprecated deprecated since mongodb@4.0, in new code, use delete instead
|
||||
*/
|
||||
delete(): UnorderedBulkOperation
|
||||
|
||||
/**
|
||||
* Add a delete one operation to the bulk operation.
|
||||
*
|
||||
*/
|
||||
deleteOne(): UnorderedBulkOperation
|
||||
|
||||
/**
|
||||
* Add a replace one operation to the bulk operation.
|
||||
* @param doc The new document to replace the existing one with.
|
||||
|
||||
@ -1314,7 +1314,7 @@ export class EntityManager {
|
||||
): Repository<Entity> {
|
||||
// find already created repository instance and return it if found
|
||||
const repository = this.repositories.find(
|
||||
(repo) => repo.target === target,
|
||||
(repository) => repository.target === target,
|
||||
)
|
||||
if (repository) return repository
|
||||
|
||||
|
||||
@ -1,78 +1,62 @@
|
||||
import { DataSource } from "../data-source/DataSource"
|
||||
import { EntityManager } from "./EntityManager"
|
||||
import { EntityTarget } from "../common/EntityTarget"
|
||||
|
||||
import {
|
||||
MongoCallback,
|
||||
AggregationCursor,
|
||||
BulkWriteOpResultObject,
|
||||
ChangeStream,
|
||||
ChangeStreamOptions,
|
||||
Code,
|
||||
Collection,
|
||||
CollectionAggregationOptions,
|
||||
CollectionBulkWriteOptions,
|
||||
CollectionInsertManyOptions,
|
||||
CollectionInsertOneOptions,
|
||||
CollectionOptions,
|
||||
CollStats,
|
||||
CommandCursor,
|
||||
Cursor,
|
||||
CursorResult,
|
||||
DeleteWriteOpResultObject,
|
||||
FindAndModifyWriteOpResultObject,
|
||||
FindOneAndReplaceOption,
|
||||
GeoHaystackSearchOptions,
|
||||
GeoNearOptions,
|
||||
InsertOneWriteOpResult,
|
||||
InsertWriteOpResult,
|
||||
MapReduceOptions,
|
||||
MongoCallback,
|
||||
MongoCountPreferences,
|
||||
MongodbIndexOptions,
|
||||
MongoError,
|
||||
ObjectID,
|
||||
OrderedBulkOperation,
|
||||
ParallelCollectionScanOptions,
|
||||
ReadPreference,
|
||||
ReplaceOneOptions,
|
||||
UnorderedBulkOperation,
|
||||
UpdateWriteOpResult,
|
||||
} from "../driver/mongodb/typings"
|
||||
import { ObjectLiteral } from "../common/ObjectLiteral"
|
||||
import { MongoQueryRunner } from "../driver/mongodb/MongoQueryRunner"
|
||||
import { MongoDriver } from "../driver/mongodb/MongoDriver"
|
||||
import { DocumentToEntityTransformer } from "../query-builder/transformer/DocumentToEntityTransformer"
|
||||
import { FindManyOptions } from "../find-options/FindManyOptions"
|
||||
import { FindOptionsUtils } from "../find-options/FindOptionsUtils"
|
||||
// import { PlatformTools } from "../platform/PlatformTools";
|
||||
import { PlatformTools } from "../platform/PlatformTools"
|
||||
import { QueryDeepPartialEntity } from "../query-builder/QueryPartialEntity"
|
||||
import { InsertResult } from "../query-builder/result/InsertResult"
|
||||
import { UpdateResult } from "../query-builder/result/UpdateResult"
|
||||
import { DeleteResult } from "../query-builder/result/DeleteResult"
|
||||
import { EntityMetadata } from "../metadata/EntityMetadata"
|
||||
|
||||
import {
|
||||
BulkWriteResult,
|
||||
AggregationCursor,
|
||||
Collection,
|
||||
FindCursor,
|
||||
Document,
|
||||
AggregateOptions,
|
||||
AnyBulkWriteOperation,
|
||||
BulkWriteOptions,
|
||||
Filter,
|
||||
CountOptions,
|
||||
IndexSpecification,
|
||||
CreateIndexesOptions,
|
||||
IndexDescription,
|
||||
DeleteResult as DeleteResultMongoDb,
|
||||
DeleteOptions,
|
||||
CommandOperationOptions,
|
||||
FindOneAndDeleteOptions,
|
||||
ModifyResult,
|
||||
FindOneAndReplaceOptions,
|
||||
UpdateFilter,
|
||||
FindOneAndUpdateOptions,
|
||||
RenameOptions,
|
||||
ReplaceOptions,
|
||||
UpdateResult as UpdateResultMongoDb,
|
||||
CollStats,
|
||||
CollStatsOptions,
|
||||
ChangeStreamOptions,
|
||||
ChangeStream,
|
||||
UpdateOptions,
|
||||
ListIndexesOptions,
|
||||
ListIndexesCursor,
|
||||
OptionalId,
|
||||
InsertOneOptions,
|
||||
InsertOneResult,
|
||||
InsertManyResult,
|
||||
MapFunction,
|
||||
ReduceFunction,
|
||||
MapReduceOptions,
|
||||
UnorderedBulkOperation,
|
||||
OrderedBulkOperation,
|
||||
IndexInformationOptions,
|
||||
ObjectId,
|
||||
MongoError,
|
||||
} from "mongodb"
|
||||
import { DataSource } from "../data-source/DataSource"
|
||||
import { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions"
|
||||
import { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions"
|
||||
import { FindOptionsWhere } from "../find-options/FindOptionsWhere"
|
||||
import {
|
||||
FindOptionsSelect,
|
||||
FindOptionsSelectByString,
|
||||
} from "../find-options/FindOptionsSelect"
|
||||
import { ObjectUtils } from "../util/ObjectUtils"
|
||||
import { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions"
|
||||
import { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions"
|
||||
import { ColumnMetadata } from "../metadata/ColumnMetadata"
|
||||
import { ObjectUtils } from "../util/ObjectUtils"
|
||||
|
||||
/**
|
||||
* Entity manager supposed to work with any entity, automatically find its repository and call its methods,
|
||||
@ -103,51 +87,25 @@ export class MongoEntityManager extends EntityManager {
|
||||
/**
|
||||
* Finds entities that match given find options.
|
||||
*/
|
||||
/**
|
||||
* Finds entities that match given find options or conditions.
|
||||
*/
|
||||
async find<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>,
|
||||
options?: MongoFindManyOptions<Entity>,
|
||||
): Promise<Entity[]> {
|
||||
const query =
|
||||
this.convertFindManyOptionsOrConditionsToMongodbQuery(
|
||||
optionsOrConditions,
|
||||
)
|
||||
const cursor = this.createEntityCursor(
|
||||
entityClassOrName,
|
||||
query as Filter<Entity>,
|
||||
)
|
||||
const deleteDateColumn =
|
||||
this.connection.getMetadata(entityClassOrName).deleteDateColumn
|
||||
if (FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
|
||||
if (optionsOrConditions.select)
|
||||
cursor.project(
|
||||
this.convertFindOptionsSelectToProjectCriteria(
|
||||
optionsOrConditions.select,
|
||||
),
|
||||
)
|
||||
if (optionsOrConditions.skip) cursor.skip(optionsOrConditions.skip)
|
||||
if (optionsOrConditions.take) cursor.limit(optionsOrConditions.take)
|
||||
if (optionsOrConditions.order)
|
||||
cursor.sort(
|
||||
this.convertFindOptionsOrderToOrderCriteria(
|
||||
optionsOrConditions.order,
|
||||
),
|
||||
)
|
||||
if (deleteDateColumn && !optionsOrConditions.withDeleted) {
|
||||
this.filterSoftDeleted(cursor, deleteDateColumn, query)
|
||||
}
|
||||
} else if (deleteDateColumn) {
|
||||
this.filterSoftDeleted(cursor, deleteDateColumn, query)
|
||||
}
|
||||
return cursor.toArray()
|
||||
return this.executeFind(entityClassOrName, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds entities that match given find options or conditions.
|
||||
* Also counts all entities that match given conditions,
|
||||
* but ignores pagination settings (from and take options).
|
||||
* Finds entities that match given conditions.
|
||||
*/
|
||||
async findBy<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
where: any,
|
||||
): Promise<Entity[]> {
|
||||
return this.executeFind(entityClassOrName, where)
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds entities that match given find options.
|
||||
*/
|
||||
async findAndCount<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
@ -175,38 +133,37 @@ export class MongoEntityManager extends EntityManager {
|
||||
async findByIds<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
ids: any[],
|
||||
optionsOrConditions?: FindManyOptions<Entity> | Partial<Entity>,
|
||||
optionsOrConditions?: any,
|
||||
): Promise<Entity[]> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
const query =
|
||||
this.convertFindManyOptionsOrConditionsToMongodbQuery(
|
||||
optionsOrConditions,
|
||||
) || {}
|
||||
const objectIdInstance = ObjectId
|
||||
const objectIdInstance = PlatformTools.load("mongodb").ObjectID
|
||||
query["_id"] = {
|
||||
$in: ids.map((id) => {
|
||||
if (typeof id === "string") {
|
||||
return new objectIdInstance(id)
|
||||
}
|
||||
|
||||
if (typeof id === "object") {
|
||||
if (ObjectUtils.isObject(id)) {
|
||||
if (id instanceof objectIdInstance) {
|
||||
return id
|
||||
}
|
||||
|
||||
const propertyName = metadata.objectIdColumn!.propertyName
|
||||
|
||||
if (id[propertyName] instanceof objectIdInstance) {
|
||||
return id[propertyName]
|
||||
if ((id as any)[propertyName] instanceof objectIdInstance) {
|
||||
return (id as any)[propertyName]
|
||||
}
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
const cursor = this.createEntityCursor(
|
||||
entityClassOrName,
|
||||
query as Filter<Entity>,
|
||||
)
|
||||
const cursor = await this.createEntityCursor(entityClassOrName, query)
|
||||
const deleteDateColumn =
|
||||
this.connection.getMetadata(entityClassOrName).deleteDateColumn
|
||||
if (FindOptionsUtils.isFindManyOptions(optionsOrConditions)) {
|
||||
if (optionsOrConditions.select)
|
||||
cursor.project(
|
||||
@ -222,12 +179,17 @@ export class MongoEntityManager extends EntityManager {
|
||||
optionsOrConditions.order,
|
||||
),
|
||||
)
|
||||
if (deleteDateColumn && !optionsOrConditions.withDeleted) {
|
||||
this.filterSoftDeleted(cursor, deleteDateColumn, query)
|
||||
}
|
||||
} else if (deleteDateColumn) {
|
||||
this.filterSoftDeleted(cursor, deleteDateColumn, query)
|
||||
}
|
||||
return cursor.toArray()
|
||||
return await cursor.toArray()
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds first entity that matches given conditions and/or find options.
|
||||
* Finds first entity that matches given find options.
|
||||
*/
|
||||
async findOne<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
@ -257,7 +219,15 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
async findOneById<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
id: string | number | Date | ObjectID,
|
||||
id:
|
||||
| string
|
||||
| string[]
|
||||
| number
|
||||
| number[]
|
||||
| Date
|
||||
| Date[]
|
||||
| ObjectID
|
||||
| ObjectID[],
|
||||
): Promise<Entity | null> {
|
||||
return this.executeFindOne(entityClassOrName, id)
|
||||
}
|
||||
@ -328,9 +298,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
| number[]
|
||||
| Date
|
||||
| Date[]
|
||||
| ObjectId
|
||||
| ObjectId[]
|
||||
| ObjectLiteral,
|
||||
| ObjectID
|
||||
| ObjectID[]
|
||||
| FindOptionsWhere<Entity>,
|
||||
partialEntity: QueryDeepPartialEntity<Entity>,
|
||||
): Promise<UpdateResult> {
|
||||
const result = new UpdateResult()
|
||||
@ -380,9 +350,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
| number[]
|
||||
| Date
|
||||
| Date[]
|
||||
| ObjectId
|
||||
| ObjectId[]
|
||||
| ObjectLiteral[],
|
||||
| ObjectID
|
||||
| ObjectID[]
|
||||
| FindOptionsWhere<Entity>,
|
||||
): Promise<DeleteResult> {
|
||||
const result = new DeleteResult()
|
||||
|
||||
@ -422,8 +392,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
createCursor<Entity, T = any>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: ObjectLiteral = {},
|
||||
): FindCursor<T> {
|
||||
query?: ObjectLiteral,
|
||||
): Cursor<T> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.cursor(metadata.tableName, query)
|
||||
}
|
||||
@ -434,8 +404,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
createEntityCursor<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: ObjectLiteral = {},
|
||||
): FindCursor<Entity> {
|
||||
query?: ObjectLiteral,
|
||||
): Cursor<Entity> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
const cursor = this.createCursor(entityClassOrName, query)
|
||||
this.applyEntityTransformationToCursor(metadata, cursor)
|
||||
@ -447,8 +417,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
aggregate<Entity, R = any>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
pipeline: Document[],
|
||||
options?: AggregateOptions,
|
||||
pipeline: ObjectLiteral[],
|
||||
options?: CollectionAggregationOptions,
|
||||
): AggregationCursor<R> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.aggregate(
|
||||
@ -464,8 +434,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
aggregateEntity<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
pipeline: Document[],
|
||||
options?: AggregateOptions,
|
||||
pipeline: ObjectLiteral[],
|
||||
options?: CollectionAggregationOptions,
|
||||
): AggregationCursor<Entity> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
const cursor = this.mongoQueryRunner.aggregate(
|
||||
@ -482,9 +452,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
bulkWrite<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
operations: AnyBulkWriteOperation<Document>[],
|
||||
options?: BulkWriteOptions,
|
||||
): Promise<BulkWriteResult> {
|
||||
operations: ObjectLiteral[],
|
||||
options?: CollectionBulkWriteOptions,
|
||||
): Promise<BulkWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.bulkWrite(
|
||||
metadata.tableName,
|
||||
@ -498,8 +468,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
count<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document> = {},
|
||||
options: CountOptions = {},
|
||||
query?: ObjectLiteral,
|
||||
options?: MongoCountPreferences,
|
||||
): Promise<number> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.count(metadata.tableName, query, options)
|
||||
@ -511,7 +481,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
countBy<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query?: ObjectLiteral,
|
||||
options?: CountOptions,
|
||||
options?: MongoCountPreferences,
|
||||
): Promise<number> {
|
||||
return this.count(entityClassOrName, query, options)
|
||||
}
|
||||
@ -521,8 +491,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
createCollectionIndex<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
fieldOrSpec: IndexSpecification,
|
||||
options?: CreateIndexesOptions,
|
||||
fieldOrSpec: string | any,
|
||||
options?: MongodbIndexOptions,
|
||||
): Promise<string> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.createCollectionIndex(
|
||||
@ -539,8 +509,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
createCollectionIndexes<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
indexSpecs: IndexDescription[],
|
||||
): Promise<string[]> {
|
||||
indexSpecs: ObjectLiteral[],
|
||||
): Promise<void> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.createCollectionIndexes(
|
||||
metadata.tableName,
|
||||
@ -553,9 +523,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
deleteMany<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
options: DeleteOptions = {},
|
||||
): Promise<DeleteResultMongoDb> {
|
||||
query: ObjectLiteral,
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.deleteMany(
|
||||
metadata.tableName,
|
||||
@ -569,9 +539,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
deleteOne<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
options: DeleteOptions = {},
|
||||
): Promise<DeleteResultMongoDb> {
|
||||
query: ObjectLiteral,
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.deleteOne(
|
||||
metadata.tableName,
|
||||
@ -586,8 +556,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
distinct<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
key: string,
|
||||
query: Filter<Document>,
|
||||
options?: CommandOperationOptions,
|
||||
query: ObjectLiteral,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.distinct(
|
||||
@ -604,7 +574,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
dropCollectionIndex<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
indexName: string,
|
||||
options?: CommandOperationOptions,
|
||||
options?: CollectionOptions,
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.dropCollectionIndex(
|
||||
@ -630,8 +600,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
findOneAndDelete<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: ObjectLiteral,
|
||||
options?: FindOneAndDeleteOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
options?: { projection?: Object; sort?: Object; maxTimeMS?: number },
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.findOneAndDelete(
|
||||
metadata.tableName,
|
||||
@ -645,10 +615,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
findOneAndReplace<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
replacement: Document,
|
||||
options?: FindOneAndReplaceOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
query: ObjectLiteral,
|
||||
replacement: Object,
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.findOneAndReplace(
|
||||
metadata.tableName,
|
||||
@ -663,10 +633,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
findOneAndUpdate<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: FindOneAndUpdateOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
query: ObjectLiteral,
|
||||
update: Object,
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.findOneAndUpdate(
|
||||
metadata.tableName,
|
||||
@ -676,12 +646,69 @@ export class MongoEntityManager extends EntityManager {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a geo search using a geo haystack index on a collection.
|
||||
*/
|
||||
geoHaystackSearch<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: GeoHaystackSearchOptions,
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.geoHaystackSearch(
|
||||
metadata.tableName,
|
||||
x,
|
||||
y,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the geoNear command to search for items in the collection.
|
||||
*/
|
||||
geoNear<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
x: number,
|
||||
y: number,
|
||||
options?: GeoNearOptions,
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.geoNear(metadata.tableName, x, y, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a group command across a collection.
|
||||
*/
|
||||
group<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
keys: Object | Array<any> | Function | Code,
|
||||
condition: Object,
|
||||
initial: Object,
|
||||
reduce: Function | Code,
|
||||
finalize: Function | Code,
|
||||
command: boolean,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.group(
|
||||
metadata.tableName,
|
||||
keys,
|
||||
condition,
|
||||
initial,
|
||||
reduce,
|
||||
finalize,
|
||||
command,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all the indexes on the collection.
|
||||
*/
|
||||
collectionIndexes<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
): Promise<Document> {
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.collectionIndexes(metadata.tableName)
|
||||
}
|
||||
@ -705,7 +732,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
collectionIndexInformation<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: IndexInformationOptions,
|
||||
options?: { full: boolean },
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.collectionIndexInformation(
|
||||
@ -719,7 +746,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
initializeOrderedBulkOp<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: BulkWriteOptions,
|
||||
options?: CollectionOptions,
|
||||
): OrderedBulkOperation {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.initializeOrderedBulkOp(
|
||||
@ -733,7 +760,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
initializeUnorderedBulkOp<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: BulkWriteOptions,
|
||||
options?: CollectionOptions,
|
||||
): UnorderedBulkOperation {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.initializeUnorderedBulkOp(
|
||||
@ -747,9 +774,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
insertMany<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
docs: OptionalId<Document>[],
|
||||
options?: BulkWriteOptions,
|
||||
): Promise<InsertManyResult> {
|
||||
docs: ObjectLiteral[],
|
||||
options?: CollectionInsertManyOptions,
|
||||
): Promise<InsertWriteOpResult> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.insertMany(
|
||||
metadata.tableName,
|
||||
@ -763,9 +790,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
insertOne<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
doc: OptionalId<Document>,
|
||||
options?: InsertOneOptions,
|
||||
): Promise<InsertOneResult> {
|
||||
doc: ObjectLiteral,
|
||||
options?: CollectionInsertOneOptions,
|
||||
): Promise<InsertOneWriteOpResult> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.insertOne(metadata.tableName, doc, options)
|
||||
}
|
||||
@ -783,8 +810,11 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
listCollectionIndexes<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: ListIndexesOptions,
|
||||
): ListIndexesCursor {
|
||||
options?: {
|
||||
batchSize?: number
|
||||
readPreference?: ReadPreference | string
|
||||
},
|
||||
): CommandCursor {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.listCollectionIndexes(
|
||||
metadata.tableName,
|
||||
@ -797,10 +827,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
mapReduce<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
map: MapFunction,
|
||||
reduce: ReduceFunction | string,
|
||||
map: Function | string,
|
||||
reduce: Function | string,
|
||||
options?: MapReduceOptions,
|
||||
): Promise<Document | Document[]> {
|
||||
): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.mapReduce(
|
||||
metadata.tableName,
|
||||
@ -810,14 +840,37 @@ export class MongoEntityManager extends EntityManager {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
|
||||
* There are no ordering guarantees for returned results.
|
||||
*/
|
||||
parallelCollectionScan<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: ParallelCollectionScanOptions,
|
||||
): Promise<Cursor<Entity>[]> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.parallelCollectionScan(
|
||||
metadata.tableName,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
reIndex<Entity>(entityClassOrName: EntityTarget<Entity>): Promise<any> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.reIndex(metadata.tableName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
rename<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
newName: string,
|
||||
options?: RenameOptions,
|
||||
): Promise<Collection<Document>> {
|
||||
options?: { dropTarget?: boolean },
|
||||
): Promise<Collection<any>> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.rename(
|
||||
metadata.tableName,
|
||||
@ -831,10 +884,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
replaceOne<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
doc: Document,
|
||||
options?: ReplaceOptions,
|
||||
): Promise<Document | UpdateResultMongoDb> {
|
||||
query: ObjectLiteral,
|
||||
doc: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.replaceOne(
|
||||
metadata.tableName,
|
||||
@ -849,7 +902,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
stats<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
options?: CollStatsOptions,
|
||||
options?: { scale: number },
|
||||
): Promise<CollStats> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.stats(metadata.tableName, options)
|
||||
@ -857,7 +910,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
|
||||
watch<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
pipeline?: Document[],
|
||||
pipeline?: Object[],
|
||||
options?: ChangeStreamOptions,
|
||||
): ChangeStream {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
@ -873,10 +926,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
updateMany<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResultMongoDb> {
|
||||
query: ObjectLiteral,
|
||||
update: ObjectLiteral,
|
||||
options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean },
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.updateMany(
|
||||
metadata.tableName,
|
||||
@ -891,10 +944,10 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
updateOne<Entity>(
|
||||
entityClassOrName: EntityTarget<Entity>,
|
||||
query: Filter<Document>,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResultMongoDb> {
|
||||
query: ObjectLiteral,
|
||||
update: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
const metadata = this.connection.getMetadata(entityClassOrName)
|
||||
return this.mongoQueryRunner.updateOne(
|
||||
metadata.tableName,
|
||||
@ -994,7 +1047,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
metadata: EntityMetadata,
|
||||
idMap: any,
|
||||
): ObjectLiteral {
|
||||
const objectIdInstance = ObjectId
|
||||
const objectIdInstance = PlatformTools.load("mongodb").ObjectID
|
||||
|
||||
// check first if it's ObjectId compatible:
|
||||
// string, number, Buffer, ObjectId or ObjectId-like
|
||||
@ -1015,7 +1068,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
}, {} as any)
|
||||
}
|
||||
|
||||
// last resort: try to convert it to an ObjectId anyway
|
||||
// last resort: try to convert it to an ObjectID anyway
|
||||
// most likely it will fail, but we want to be backwards compatible and keep the same thrown Errors.
|
||||
// it can still pass with null/undefined
|
||||
return {
|
||||
@ -1028,38 +1081,38 @@ export class MongoEntityManager extends EntityManager {
|
||||
*/
|
||||
protected applyEntityTransformationToCursor<Entity extends ObjectLiteral>(
|
||||
metadata: EntityMetadata,
|
||||
cursor: FindCursor<Entity> | AggregationCursor<Entity>,
|
||||
cursor: Cursor<Entity> | AggregationCursor<Entity>,
|
||||
) {
|
||||
// mongdb-3.7 exports Cursor, mongodb-4.2 exports FindCursor, provide support for both.
|
||||
const ParentCursor =
|
||||
PlatformTools.load("mongodb").Cursor ||
|
||||
PlatformTools.load("mongodb").FindCursor
|
||||
const queryRunner = this.mongoQueryRunner
|
||||
cursor.toArray = function (callback?: MongoCallback<Entity[]>) {
|
||||
if (callback) {
|
||||
cursor
|
||||
.clone()
|
||||
.toArray.call(
|
||||
this,
|
||||
(error: MongoError, results: Entity[]): void => {
|
||||
if (error) {
|
||||
callback(error, results)
|
||||
return
|
||||
}
|
||||
ParentCursor.prototype.toArray.call(
|
||||
this,
|
||||
(error: MongoError, results: Entity[]): void => {
|
||||
if (error) {
|
||||
callback(error, results)
|
||||
return
|
||||
}
|
||||
|
||||
const transformer =
|
||||
new DocumentToEntityTransformer()
|
||||
const entities = transformer.transformAll(
|
||||
results,
|
||||
metadata,
|
||||
)
|
||||
const transformer = new DocumentToEntityTransformer()
|
||||
const entities = transformer.transformAll(
|
||||
results,
|
||||
metadata,
|
||||
)
|
||||
|
||||
// broadcast "load" events
|
||||
queryRunner.broadcaster
|
||||
.broadcast("Load", metadata, entities)
|
||||
.then(() => callback(error, entities))
|
||||
},
|
||||
)
|
||||
// broadcast "load" events
|
||||
queryRunner.broadcaster
|
||||
.broadcast("Load", metadata, entities)
|
||||
.then(() => callback(error, entities))
|
||||
},
|
||||
)
|
||||
} else {
|
||||
return cursor
|
||||
.clone()
|
||||
.toArray.call(this)
|
||||
return ParentCursor.prototype.toArray
|
||||
.call(this)
|
||||
.then((results: Entity[]) => {
|
||||
const transformer = new DocumentToEntityTransformer()
|
||||
const entities = transformer.transformAll(
|
||||
@ -1076,42 +1129,33 @@ export class MongoEntityManager extends EntityManager {
|
||||
}
|
||||
cursor.next = function (callback?: MongoCallback<CursorResult>) {
|
||||
if (callback) {
|
||||
cursor
|
||||
.clone()
|
||||
.next.call(
|
||||
this,
|
||||
(error: MongoError, result: CursorResult): void => {
|
||||
if (error || !result) {
|
||||
callback(error, result)
|
||||
return
|
||||
}
|
||||
|
||||
const transformer =
|
||||
new DocumentToEntityTransformer()
|
||||
const entity = transformer.transform(
|
||||
result,
|
||||
metadata,
|
||||
)
|
||||
|
||||
// broadcast "load" events
|
||||
|
||||
queryRunner.broadcaster
|
||||
.broadcast("Load", metadata, [entity])
|
||||
.then(() => callback(error, entity))
|
||||
},
|
||||
)
|
||||
} else {
|
||||
return cursor
|
||||
.clone()
|
||||
.next.call(this)
|
||||
.then((result: Entity) => {
|
||||
if (!result) {
|
||||
return result
|
||||
ParentCursor.prototype.next.call(
|
||||
this,
|
||||
(error: MongoError, result: CursorResult): void => {
|
||||
if (error || !result) {
|
||||
callback(error, result)
|
||||
return
|
||||
}
|
||||
|
||||
const transformer = new DocumentToEntityTransformer()
|
||||
const entity = transformer.transform(result, metadata)
|
||||
|
||||
// broadcast "load" events
|
||||
|
||||
queryRunner.broadcaster
|
||||
.broadcast("Load", metadata, [entity])
|
||||
.then(() => callback(error, entity))
|
||||
},
|
||||
)
|
||||
} else {
|
||||
return ParentCursor.prototype.next
|
||||
.call(this)
|
||||
.then((result: Entity) => {
|
||||
if (!result) return result
|
||||
|
||||
const transformer = new DocumentToEntityTransformer()
|
||||
const entity = transformer.transform(result, metadata)
|
||||
|
||||
// broadcast "load" events
|
||||
return queryRunner.broadcaster
|
||||
.broadcast("Load", metadata, [entity])
|
||||
@ -1122,7 +1166,7 @@ export class MongoEntityManager extends EntityManager {
|
||||
}
|
||||
|
||||
protected filterSoftDeleted<Entity>(
|
||||
cursor: FindCursor<Entity>,
|
||||
cursor: Cursor<Entity>,
|
||||
deleteDateColumn: ColumnMetadata,
|
||||
query?: ObjectLiteral,
|
||||
) {
|
||||
@ -1144,8 +1188,9 @@ export class MongoEntityManager extends EntityManager {
|
||||
optionsOrConditions?: any,
|
||||
maybeOptions?: MongoFindOneOptions<Entity>,
|
||||
): Promise<Entity | null> {
|
||||
const objectIdInstance = PlatformTools.load("mongodb").ObjectID
|
||||
const id =
|
||||
optionsOrConditions instanceof ObjectId ||
|
||||
optionsOrConditions instanceof objectIdInstance ||
|
||||
typeof optionsOrConditions === "string"
|
||||
? optionsOrConditions
|
||||
: undefined
|
||||
@ -1157,7 +1202,8 @@ export class MongoEntityManager extends EntityManager {
|
||||
findOneOptionsOrConditions,
|
||||
) || {}
|
||||
if (id) {
|
||||
query["_id"] = id instanceof ObjectId ? id : new ObjectId(id)
|
||||
query["_id"] =
|
||||
id instanceof objectIdInstance ? id : new objectIdInstance(id)
|
||||
}
|
||||
const cursor = await this.createEntityCursor(entityClassOrName, query)
|
||||
const deleteDateColumn =
|
||||
|
||||
@ -544,8 +544,10 @@ export class MigrationExecutor {
|
||||
): Promise<Migration[]> {
|
||||
if (this.connection.driver.options.type === "mongodb") {
|
||||
const mongoRunner = queryRunner as MongoQueryRunner
|
||||
return mongoRunner
|
||||
.cursor(this.migrationsTableName, {})
|
||||
return await mongoRunner.databaseConnection
|
||||
.db(this.connection.driver.database!)
|
||||
.collection(this.migrationsTableName)
|
||||
.find<Migration>()
|
||||
.sort({ _id: -1 })
|
||||
.toArray()
|
||||
} else {
|
||||
|
||||
@ -2,12 +2,35 @@ import { ObjectLiteral } from "../common/ObjectLiteral"
|
||||
import { Repository } from "./Repository"
|
||||
import { MongoFindManyOptions } from "../find-options/mongodb/MongoFindManyOptions"
|
||||
import {
|
||||
AggregationCursor,
|
||||
BulkWriteOpResultObject,
|
||||
Code,
|
||||
Collection,
|
||||
CollectionAggregationOptions,
|
||||
CollectionBulkWriteOptions,
|
||||
CollectionInsertManyOptions,
|
||||
CollectionInsertOneOptions,
|
||||
CollectionOptions,
|
||||
CollStats,
|
||||
CommandCursor,
|
||||
Cursor,
|
||||
DeleteWriteOpResultObject,
|
||||
FindAndModifyWriteOpResultObject,
|
||||
FindOneAndReplaceOption,
|
||||
GeoHaystackSearchOptions,
|
||||
GeoNearOptions,
|
||||
InsertOneWriteOpResult,
|
||||
InsertWriteOpResult,
|
||||
MapReduceOptions,
|
||||
MongoCountPreferences,
|
||||
MongodbIndexOptions,
|
||||
ObjectID,
|
||||
OrderedBulkOperation,
|
||||
ParallelCollectionScanOptions,
|
||||
ReadPreference,
|
||||
ReplaceOneOptions,
|
||||
UnorderedBulkOperation,
|
||||
UpdateWriteOpResult,
|
||||
} from "../driver/mongodb/typings"
|
||||
import { MongoEntityManager } from "../entity-manager/MongoEntityManager"
|
||||
import { QueryRunner } from "../query-runner/QueryRunner"
|
||||
@ -16,42 +39,6 @@ import { TypeORMError } from "../error/TypeORMError"
|
||||
import { MongoFindOneOptions } from "../find-options/mongodb/MongoFindOneOptions"
|
||||
import { FindOneOptions } from "../find-options/FindOneOptions"
|
||||
|
||||
import {
|
||||
AggregateOptions,
|
||||
AggregationCursor,
|
||||
AnyBulkWriteOperation,
|
||||
BulkWriteOptions,
|
||||
Collection,
|
||||
CollStats,
|
||||
CollStatsOptions,
|
||||
CommandOperationOptions,
|
||||
CountOptions,
|
||||
DeleteOptions,
|
||||
DeleteResult,
|
||||
Document,
|
||||
Filter,
|
||||
FindCursor,
|
||||
FindOneAndDeleteOptions,
|
||||
FindOneAndReplaceOptions,
|
||||
FindOneAndUpdateOptions,
|
||||
IndexDescription,
|
||||
InsertManyResult,
|
||||
InsertOneOptions,
|
||||
InsertOneResult,
|
||||
ListIndexesCursor,
|
||||
ListIndexesOptions,
|
||||
MapFunction,
|
||||
MapReduceOptions,
|
||||
ModifyResult,
|
||||
ObjectId,
|
||||
OrderedBulkOperation,
|
||||
ReduceFunction,
|
||||
UnorderedBulkOperation,
|
||||
UpdateFilter,
|
||||
UpdateOptions,
|
||||
UpdateResult,
|
||||
} from "mongodb"
|
||||
|
||||
/**
|
||||
* Repository used to manage mongodb documents of a single entity type.
|
||||
*/
|
||||
@ -164,7 +151,15 @@ export class MongoRepository<
|
||||
* })
|
||||
*/
|
||||
async findOneById(
|
||||
id: string | number | Date | ObjectID,
|
||||
id:
|
||||
| string
|
||||
| string[]
|
||||
| number
|
||||
| number[]
|
||||
| Date
|
||||
| Date[]
|
||||
| ObjectID
|
||||
| ObjectID[],
|
||||
): Promise<Entity | null> {
|
||||
return this.manager.findOneById(this.metadata.target, id)
|
||||
}
|
||||
@ -188,7 +183,7 @@ export class MongoRepository<
|
||||
/**
|
||||
* Creates a cursor for a query that can be used to iterate over results from MongoDB.
|
||||
*/
|
||||
createCursor<T = any>(query?: Filter<Entity>): FindCursor<T> {
|
||||
createCursor<T = any>(query?: ObjectLiteral): Cursor<T> {
|
||||
return this.manager.createCursor(this.metadata.target, query)
|
||||
}
|
||||
|
||||
@ -196,7 +191,7 @@ export class MongoRepository<
|
||||
* Creates a cursor for a query that can be used to iterate over results from MongoDB.
|
||||
* This returns modified version of cursor that transforms each result into Entity model.
|
||||
*/
|
||||
createEntityCursor(query?: Filter<Entity>): FindCursor<Entity> {
|
||||
createEntityCursor(query?: ObjectLiteral): Cursor<Entity> {
|
||||
return this.manager.createEntityCursor(this.metadata.target, query)
|
||||
}
|
||||
|
||||
@ -205,8 +200,8 @@ export class MongoRepository<
|
||||
*/
|
||||
aggregate<R = any>(
|
||||
pipeline: ObjectLiteral[],
|
||||
options?: AggregateOptions,
|
||||
): AggregationCursor<Entity> {
|
||||
options?: CollectionAggregationOptions,
|
||||
): AggregationCursor<R> {
|
||||
return this.manager.aggregate<R>(
|
||||
this.metadata.target,
|
||||
pipeline,
|
||||
@ -220,7 +215,7 @@ export class MongoRepository<
|
||||
*/
|
||||
aggregateEntity(
|
||||
pipeline: ObjectLiteral[],
|
||||
options?: AggregateOptions,
|
||||
options?: CollectionAggregationOptions,
|
||||
): AggregationCursor<Entity> {
|
||||
return this.manager.aggregateEntity(
|
||||
this.metadata.target,
|
||||
@ -232,8 +227,8 @@ export class MongoRepository<
|
||||
* Perform a bulkWrite operation without a fluent API.
|
||||
*/
|
||||
bulkWrite(
|
||||
operations: AnyBulkWriteOperation[],
|
||||
options?: BulkWriteOptions,
|
||||
operations: ObjectLiteral[],
|
||||
options?: CollectionBulkWriteOptions,
|
||||
): Promise<BulkWriteOpResultObject> {
|
||||
return this.manager.bulkWrite(this.metadata.target, operations, options)
|
||||
}
|
||||
@ -241,7 +236,10 @@ export class MongoRepository<
|
||||
/**
|
||||
* Count number of matching documents in the db to a query.
|
||||
*/
|
||||
count(query?: ObjectLiteral, options?: CountOptions): Promise<number> {
|
||||
count(
|
||||
query?: ObjectLiteral,
|
||||
options?: MongoCountPreferences,
|
||||
): Promise<number> {
|
||||
return this.manager.count(this.metadata.target, query || {}, options)
|
||||
}
|
||||
|
||||
@ -252,13 +250,7 @@ export class MongoRepository<
|
||||
query?: ObjectLiteral,
|
||||
options?: MongoCountPreferences,
|
||||
): Promise<number> {
|
||||
let where = {}
|
||||
if (query !== undefined) {
|
||||
where = query
|
||||
} else if (options !== undefined) {
|
||||
where = options
|
||||
}
|
||||
return this.manager.countBy(this.metadata.target, where)
|
||||
return this.manager.countBy(this.metadata.target, query || {}, options)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,7 +272,7 @@ export class MongoRepository<
|
||||
* Earlier version of MongoDB will throw a command not supported error.
|
||||
* Index specifications are defined at http://docs.mongodb.org/manual/reference/command/createIndexes/.
|
||||
*/
|
||||
createCollectionIndexes(indexSpecs: IndexDescription[]): Promise<string[]> {
|
||||
createCollectionIndexes(indexSpecs: ObjectLiteral[]): Promise<void> {
|
||||
return this.manager.createCollectionIndexes(
|
||||
this.metadata.target,
|
||||
indexSpecs,
|
||||
@ -292,8 +284,8 @@ export class MongoRepository<
|
||||
*/
|
||||
deleteMany(
|
||||
query: ObjectLiteral,
|
||||
options?: DeleteOptions,
|
||||
): Promise<DeleteResult> {
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
return this.manager.deleteMany(this.metadata.tableName, query, options)
|
||||
}
|
||||
|
||||
@ -302,8 +294,8 @@ export class MongoRepository<
|
||||
*/
|
||||
deleteOne(
|
||||
query: ObjectLiteral,
|
||||
options?: DeleteOptions,
|
||||
): Promise<DeleteResult> {
|
||||
options?: CollectionOptions,
|
||||
): Promise<DeleteWriteOpResultObject> {
|
||||
return this.manager.deleteOne(this.metadata.tableName, query, options)
|
||||
}
|
||||
|
||||
@ -313,7 +305,7 @@ export class MongoRepository<
|
||||
distinct(
|
||||
key: string,
|
||||
query: ObjectLiteral,
|
||||
options?: CommandOperationOptions,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
return this.manager.distinct(
|
||||
this.metadata.tableName,
|
||||
@ -328,7 +320,7 @@ export class MongoRepository<
|
||||
*/
|
||||
dropCollectionIndex(
|
||||
indexName: string,
|
||||
options?: CommandOperationOptions,
|
||||
options?: CollectionOptions,
|
||||
): Promise<any> {
|
||||
return this.manager.dropCollectionIndex(
|
||||
this.metadata.tableName,
|
||||
@ -349,7 +341,7 @@ export class MongoRepository<
|
||||
*/
|
||||
findOneAndDelete(
|
||||
query: ObjectLiteral,
|
||||
options?: FindOneAndDeleteOptions,
|
||||
options?: { projection?: Object; sort?: Object; maxTimeMS?: number },
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return this.manager.findOneAndDelete(
|
||||
this.metadata.tableName,
|
||||
@ -364,8 +356,8 @@ export class MongoRepository<
|
||||
findOneAndReplace(
|
||||
query: ObjectLiteral,
|
||||
replacement: Object,
|
||||
options?: FindOneAndReplaceOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return this.manager.findOneAndReplace(
|
||||
this.metadata.tableName,
|
||||
query,
|
||||
@ -380,8 +372,8 @@ export class MongoRepository<
|
||||
findOneAndUpdate(
|
||||
query: ObjectLiteral,
|
||||
update: Object,
|
||||
options?: FindOneAndUpdateOptions,
|
||||
): Promise<ModifyResult<Document>> {
|
||||
options?: FindOneAndReplaceOption,
|
||||
): Promise<FindAndModifyWriteOpResultObject> {
|
||||
return this.manager.findOneAndUpdate(
|
||||
this.metadata.tableName,
|
||||
query,
|
||||
@ -390,6 +382,53 @@ export class MongoRepository<
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a geo search using a geo haystack index on a collection.
|
||||
*/
|
||||
geoHaystackSearch(
|
||||
x: number,
|
||||
y: number,
|
||||
options?: GeoHaystackSearchOptions,
|
||||
): Promise<any> {
|
||||
return this.manager.geoHaystackSearch(
|
||||
this.metadata.tableName,
|
||||
x,
|
||||
y,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the geoNear command to search for items in the collection.
|
||||
*/
|
||||
geoNear(x: number, y: number, options?: GeoNearOptions): Promise<any> {
|
||||
return this.manager.geoNear(this.metadata.tableName, x, y, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a group command across a collection.
|
||||
*/
|
||||
group(
|
||||
keys: Object | Array<any> | Function | Code,
|
||||
condition: Object,
|
||||
initial: Object,
|
||||
reduce: Function | Code,
|
||||
finalize: Function | Code,
|
||||
command: boolean,
|
||||
options?: { readPreference?: ReadPreference | string },
|
||||
): Promise<any> {
|
||||
return this.manager.group(
|
||||
this.metadata.tableName,
|
||||
keys,
|
||||
condition,
|
||||
initial,
|
||||
reduce,
|
||||
finalize,
|
||||
command,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all the indexes on the collection.
|
||||
*/
|
||||
@ -420,7 +459,7 @@ export class MongoRepository<
|
||||
/**
|
||||
* Initiate an In order bulk write operation, operations will be serially executed in the order they are added, creating a new operation for each switch in types.
|
||||
*/
|
||||
initializeOrderedBulkOp(options?: BulkWriteOptions): OrderedBulkOperation {
|
||||
initializeOrderedBulkOp(options?: CollectionOptions): OrderedBulkOperation {
|
||||
return this.manager.initializeOrderedBulkOp(
|
||||
this.metadata.tableName,
|
||||
options,
|
||||
@ -431,7 +470,7 @@ export class MongoRepository<
|
||||
* Initiate a Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
|
||||
*/
|
||||
initializeUnorderedBulkOp(
|
||||
options?: BulkWriteOptions,
|
||||
options?: CollectionOptions,
|
||||
): UnorderedBulkOperation {
|
||||
return this.manager.initializeUnorderedBulkOp(
|
||||
this.metadata.tableName,
|
||||
@ -444,8 +483,8 @@ export class MongoRepository<
|
||||
*/
|
||||
insertMany(
|
||||
docs: ObjectLiteral[],
|
||||
options?: BulkWriteOptions,
|
||||
): Promise<InsertManyResult<Document>> {
|
||||
options?: CollectionInsertManyOptions,
|
||||
): Promise<InsertWriteOpResult> {
|
||||
return this.manager.insertMany(this.metadata.tableName, docs, options)
|
||||
}
|
||||
|
||||
@ -454,8 +493,8 @@ export class MongoRepository<
|
||||
*/
|
||||
insertOne(
|
||||
doc: ObjectLiteral,
|
||||
options?: InsertOneOptions,
|
||||
): Promise<InsertOneResult> {
|
||||
options?: CollectionInsertOneOptions,
|
||||
): Promise<InsertOneWriteOpResult> {
|
||||
return this.manager.insertOne(this.metadata.tableName, doc, options)
|
||||
}
|
||||
|
||||
@ -469,7 +508,10 @@ export class MongoRepository<
|
||||
/**
|
||||
* Get the list of all indexes information for the collection.
|
||||
*/
|
||||
listCollectionIndexes(options?: ListIndexesOptions): ListIndexesCursor {
|
||||
listCollectionIndexes(options?: {
|
||||
batchSize?: number
|
||||
readPreference?: ReadPreference | string
|
||||
}): CommandCursor {
|
||||
return this.manager.listCollectionIndexes(
|
||||
this.metadata.tableName,
|
||||
options,
|
||||
@ -480,8 +522,8 @@ export class MongoRepository<
|
||||
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
|
||||
*/
|
||||
mapReduce(
|
||||
map: MapFunction,
|
||||
reduce: string | ReduceFunction<ObjectId>,
|
||||
map: Function | string,
|
||||
reduce: Function | string,
|
||||
options?: MapReduceOptions,
|
||||
): Promise<any> {
|
||||
return this.manager.mapReduce(
|
||||
@ -492,13 +534,33 @@ export class MongoRepository<
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return N number of parallel cursors for a collection allowing parallel reading of entire collection.
|
||||
* There are no ordering guarantees for returned results.
|
||||
*/
|
||||
parallelCollectionScan(
|
||||
options?: ParallelCollectionScanOptions,
|
||||
): Promise<Cursor<Entity>[]> {
|
||||
return this.manager.parallelCollectionScan(
|
||||
this.metadata.tableName,
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
reIndex(): Promise<any> {
|
||||
return this.manager.reIndex(this.metadata.tableName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex all indexes on the collection Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
*/
|
||||
rename(
|
||||
newName: string,
|
||||
options?: { dropTarget?: boolean },
|
||||
): Promise<Collection<Document>> {
|
||||
): Promise<Collection<any>> {
|
||||
return this.manager.rename(this.metadata.tableName, newName, options)
|
||||
}
|
||||
|
||||
@ -509,7 +571,7 @@ export class MongoRepository<
|
||||
query: ObjectLiteral,
|
||||
doc: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return this.manager.replaceOne(
|
||||
this.metadata.tableName,
|
||||
query,
|
||||
@ -521,7 +583,7 @@ export class MongoRepository<
|
||||
/**
|
||||
* Get all the collection statistics.
|
||||
*/
|
||||
stats(options?: CollStatsOptions): Promise<CollStats> {
|
||||
stats(options?: { scale: number }): Promise<CollStats> {
|
||||
return this.manager.stats(this.metadata.tableName, options)
|
||||
}
|
||||
|
||||
@ -530,9 +592,9 @@ export class MongoRepository<
|
||||
*/
|
||||
updateMany(
|
||||
query: ObjectLiteral,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
update: ObjectLiteral,
|
||||
options?: { upsert?: boolean; w?: any; wtimeout?: number; j?: boolean },
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return this.manager.updateMany(
|
||||
this.metadata.tableName,
|
||||
query,
|
||||
@ -546,9 +608,9 @@ export class MongoRepository<
|
||||
*/
|
||||
updateOne(
|
||||
query: ObjectLiteral,
|
||||
update: UpdateFilter<Document>,
|
||||
options?: UpdateOptions,
|
||||
): Promise<Document | UpdateResult> {
|
||||
update: ObjectLiteral,
|
||||
options?: ReplaceOneOptions,
|
||||
): Promise<UpdateWriteOpResult> {
|
||||
return this.manager.updateOne(
|
||||
this.metadata.tableName,
|
||||
query,
|
||||
|
||||
@ -24,22 +24,22 @@ describe("benchmark > QueryBuilder > wide join", () => {
|
||||
|
||||
it("testing query builder with join to 10 relations with 10 columns each", () => {
|
||||
for (let i = 1; i <= 10_000; i++) {
|
||||
connections.forEach((connection) =>
|
||||
connections.map((connection) =>
|
||||
connection.manager
|
||||
.createQueryBuilder(One, "ones")
|
||||
.setFindOptions({
|
||||
where: { id: 1 },
|
||||
relations: {
|
||||
two: true,
|
||||
three: true,
|
||||
four: true,
|
||||
five: true,
|
||||
six: true,
|
||||
seven: true,
|
||||
eight: true,
|
||||
nine: true,
|
||||
ten: true,
|
||||
},
|
||||
relations: [
|
||||
"two",
|
||||
"three",
|
||||
"four",
|
||||
"five",
|
||||
"six",
|
||||
"seven",
|
||||
"eight",
|
||||
"nine",
|
||||
"ten",
|
||||
],
|
||||
})
|
||||
.getQuery(),
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ describe("deferrable fk constraints should be check at the end of transaction (#
|
||||
|
||||
// now check
|
||||
const user = await connection.manager.findOne(User, {
|
||||
relations: { company: true },
|
||||
relations: ["company"],
|
||||
where: { id: 1 },
|
||||
})
|
||||
|
||||
@ -86,7 +86,7 @@ describe("deferrable fk constraints should be check at the end of transaction (#
|
||||
|
||||
// now check
|
||||
const office = await connection.manager.findOne(Office, {
|
||||
relations: { company: true },
|
||||
relations: ["company"],
|
||||
where: { id: 2 },
|
||||
})
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ describe("find options > relations", () => {
|
||||
const posts2 = await connection
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
order: {
|
||||
id: "asc",
|
||||
},
|
||||
|
||||
@ -26,7 +26,7 @@ describe("find options > select", () => {
|
||||
const posts1 = await connection
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
select: { id: true },
|
||||
select: ["id"],
|
||||
order: {
|
||||
id: "asc",
|
||||
},
|
||||
@ -67,7 +67,7 @@ describe("find options > select", () => {
|
||||
const posts1 = await connection
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
select: { title: true },
|
||||
select: ["title"],
|
||||
order: {
|
||||
title: "asc",
|
||||
},
|
||||
@ -108,7 +108,7 @@ describe("find options > select", () => {
|
||||
const posts1 = await connection
|
||||
.createQueryBuilder(Post, "post")
|
||||
.setFindOptions({
|
||||
select: { title: true, text: true },
|
||||
select: ["title", "text"],
|
||||
order: {
|
||||
title: "asc",
|
||||
},
|
||||
|
||||
@ -2,6 +2,7 @@ import { Entity } from "../../../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../../../src/decorator/columns/Column"
|
||||
import { ObjectIdColumn } from "../../../../../../src/decorator/columns/ObjectIdColumn"
|
||||
import { ObjectID } from "../../../../../../src/driver/mongodb/typings"
|
||||
|
||||
@Entity()
|
||||
export class Post {
|
||||
@ObjectIdColumn()
|
||||
|
||||
@ -34,7 +34,7 @@ describe("mongodb > object id columns", () => {
|
||||
// little hack to get raw data from mongodb
|
||||
const aggArr = await postMongoRepository.aggregate([]).toArray()
|
||||
|
||||
expect((aggArr[0] as any)._id).to.be.not.undefined
|
||||
expect(aggArr[0]._id).to.be.not.undefined
|
||||
expect(aggArr[0].nonIdNameOfObjectId).to.be.undefined
|
||||
}),
|
||||
))
|
||||
@ -94,7 +94,7 @@ describe("mongodb > object id columns", () => {
|
||||
// little hack to get raw data from mongodb
|
||||
const aggArr = await postMongoRepository.aggregate([]).toArray()
|
||||
|
||||
expect((aggArr[0] as any)._id).to.be.not.undefined
|
||||
expect(aggArr[0]._id).to.be.not.undefined
|
||||
expect(aggArr[0].nonIdNameOfObjectId).to.be.undefined
|
||||
}),
|
||||
))
|
||||
|
||||
@ -45,7 +45,7 @@ describe("persistence > one-to-one", function () {
|
||||
|
||||
const loadedUser = await userRepository.findOne({
|
||||
where: { email: "mwelnick@test.com" },
|
||||
relations: { access_token: true },
|
||||
relations: ["access_token"],
|
||||
})
|
||||
|
||||
expect(loadedUser).not.to.be.null
|
||||
|
||||
@ -35,11 +35,7 @@ describe("persistence > orphanage > delete", () => {
|
||||
let postRepository: Repository<Post>
|
||||
let categoryId: number
|
||||
|
||||
beforeEach(async function () {
|
||||
if (connections.length === 0) {
|
||||
this.skip()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
categoryRepository = connection.getRepository(Category)
|
||||
|
||||
@ -35,11 +35,7 @@ describe("persistence > orphanage > disable", () => {
|
||||
let settingRepo: Repository<Setting>
|
||||
let userId: number
|
||||
|
||||
beforeEach(async function () {
|
||||
if (connections.length === 0) {
|
||||
this.skip()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
userRepo = connection.getRepository(User)
|
||||
|
||||
@ -300,7 +300,7 @@ describe("query builder > soft-delete", () => {
|
||||
await userRepository.save(user2)
|
||||
|
||||
const users = await userRepository.find({
|
||||
relations: { picture: true },
|
||||
relations: ["picture"],
|
||||
})
|
||||
|
||||
expect(users[0].picture.deletedAt).to.equal(null)
|
||||
@ -312,7 +312,7 @@ describe("query builder > soft-delete", () => {
|
||||
|
||||
const usersWithSoftDelete = await userRepository.find({
|
||||
withDeleted: true,
|
||||
relations: { picture: true },
|
||||
relations: ["picture"],
|
||||
})
|
||||
|
||||
expect(usersWithSoftDelete[0].picture.deletedAt).to.not.equal(
|
||||
|
||||
@ -58,7 +58,7 @@ describe("relations > multiple-primary-keys > one-to-many", () => {
|
||||
await insertSimpleTestData(connection)
|
||||
|
||||
const [user] = await connection.getRepository(User).find({
|
||||
relations: { settings: true },
|
||||
relations: ["settings"],
|
||||
// relationLoadStrategy: "join"
|
||||
})
|
||||
|
||||
@ -86,7 +86,7 @@ describe("relations > multiple-primary-keys > one-to-many", () => {
|
||||
|
||||
const [user] = await connection
|
||||
.getRepository(User)
|
||||
.find({ relations: { settings: true } })
|
||||
.find({ relations: ["settings"] })
|
||||
|
||||
// check the saved items have correctly updated value
|
||||
expect(user!).not.to.be.undefined
|
||||
@ -117,7 +117,7 @@ describe("relations > multiple-primary-keys > one-to-many", () => {
|
||||
})
|
||||
|
||||
const [user] = await connection.getRepository(User).find({
|
||||
relations: { settings: true },
|
||||
relations: ["settings"],
|
||||
})
|
||||
|
||||
// check that no relational items are found
|
||||
|
||||
@ -595,7 +595,7 @@ describe("repository > find options > locking", () => {
|
||||
.getRepository(Post)
|
||||
.findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_write",
|
||||
tables: ["img"],
|
||||
@ -617,7 +617,7 @@ describe("repository > find options > locking", () => {
|
||||
return Promise.all([
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_write",
|
||||
tables: ["post"],
|
||||
@ -625,7 +625,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: { mode: "pessimistic_write" },
|
||||
}),
|
||||
])
|
||||
@ -637,7 +637,7 @@ describe("repository > find options > locking", () => {
|
||||
return Promise.all([
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_write",
|
||||
tables: ["post"],
|
||||
@ -647,7 +647,7 @@ describe("repository > find options > locking", () => {
|
||||
.getRepository(Post)
|
||||
.findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: { mode: "pessimistic_write" },
|
||||
})
|
||||
.should.be.rejectedWith(
|
||||
@ -670,7 +670,7 @@ describe("repository > find options > locking", () => {
|
||||
return Promise.all([
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_read",
|
||||
tables: ["post"],
|
||||
@ -678,7 +678,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_write",
|
||||
tables: ["post"],
|
||||
@ -686,7 +686,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_partial_write",
|
||||
tables: ["post"],
|
||||
@ -694,7 +694,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "pessimistic_write_or_fail",
|
||||
tables: ["post"],
|
||||
@ -702,7 +702,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "for_no_key_update",
|
||||
tables: ["post"],
|
||||
@ -710,7 +710,7 @@ describe("repository > find options > locking", () => {
|
||||
}),
|
||||
entityManager.getRepository(Post).findOne({
|
||||
where: { id: 1 },
|
||||
relations: { author: true },
|
||||
relations: ["author"],
|
||||
lock: {
|
||||
mode: "for_key_share",
|
||||
tables: ["post"],
|
||||
|
||||
@ -45,7 +45,7 @@ describe("repository > find options", () => {
|
||||
await connection.manager.save(post)
|
||||
|
||||
const [loadedPost] = await connection.getRepository(Post).find({
|
||||
relations: { author: true, categories: true },
|
||||
relations: ["author", "categories"],
|
||||
})
|
||||
expect(loadedPost).to.be.eql({
|
||||
id: 1,
|
||||
@ -126,7 +126,7 @@ describe("repository > find options", () => {
|
||||
const loadedPhoto = await connection
|
||||
.getRepository(Photo)
|
||||
.findOne({
|
||||
select: { name: true },
|
||||
select: ["name"],
|
||||
where: {
|
||||
id: 5,
|
||||
},
|
||||
@ -135,14 +135,14 @@ describe("repository > find options", () => {
|
||||
const loadedPhotos1 = await connection
|
||||
.getRepository(Photo)
|
||||
.find({
|
||||
select: { filename: true, views: true },
|
||||
select: ["filename", "views"],
|
||||
})
|
||||
|
||||
const loadedPhotos2 = await connection
|
||||
.getRepository(Photo)
|
||||
.find({
|
||||
select: { id: true, name: true, description: true },
|
||||
relations: { categories: true },
|
||||
select: ["id", "name", "description"],
|
||||
relations: ["categories"],
|
||||
})
|
||||
|
||||
// const loadedPhotos3 = await connection.getRepository(Photo).createQueryBuilder("photo")
|
||||
|
||||
@ -55,7 +55,7 @@ describe("table-inheritance > single-table > no-type-column", () => {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const [postIt] = await postItRepo.find({
|
||||
relations: { owner: true },
|
||||
relations: ["owner"],
|
||||
})
|
||||
|
||||
postIt.owner.should.be.an.instanceOf(Employee)
|
||||
@ -63,7 +63,7 @@ describe("table-inheritance > single-table > no-type-column", () => {
|
||||
postIt.owner.employeeName.should.be.equal("Alice Foo")
|
||||
|
||||
const [sticky] = await stickyRepo.find({
|
||||
relations: { owner: true },
|
||||
relations: ["owner"],
|
||||
})
|
||||
|
||||
sticky.owner.should.be.an.instanceOf(Author)
|
||||
|
||||
@ -45,7 +45,7 @@ describe("github issues > #1178 subqueries must work in insert statements", () =
|
||||
where: {
|
||||
id: 1,
|
||||
},
|
||||
relations: { user: true },
|
||||
relations: ["user"],
|
||||
})
|
||||
.should.eventually.eql({
|
||||
id: 1,
|
||||
|
||||
@ -50,7 +50,7 @@ describe("github issue > #1416 Wrong behavior when fetching an entity that has a
|
||||
where: {
|
||||
name: photoAuthor.name,
|
||||
},
|
||||
relations: { photos: true },
|
||||
relations: ["photos"],
|
||||
})) as Author
|
||||
expect(author).not.to.be.null
|
||||
expect(author.photos[0]).not.to.be.undefined
|
||||
|
||||
@ -26,13 +26,11 @@ describe("github issues > #1504 Cannot eagerly query Entity with relation more t
|
||||
where: {
|
||||
id: 1,
|
||||
},
|
||||
relations: {
|
||||
Entity2: {
|
||||
Entity3: {
|
||||
Entity4: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"Entity2",
|
||||
"Entity2.Entity3",
|
||||
"Entity2.Entity3.Entity4",
|
||||
],
|
||||
})
|
||||
}),
|
||||
))
|
||||
|
||||
@ -37,7 +37,7 @@ describe("github issues > #1720 Listener not invoked when relation loaded throug
|
||||
await connection.manager.save(post1)
|
||||
|
||||
const [loadedPost] = await connection.manager.find(Post, {
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
loadedPost!.categories[0].loaded.should.be.equal(true)
|
||||
loadedPost!.categories[1].loaded.should.be.equal(true)
|
||||
|
||||
@ -41,7 +41,7 @@ describe("github issues > #1788 One to One does not load relationships.", () =>
|
||||
await providerRepository.save(provider)
|
||||
|
||||
const dbProvider = await providerRepository.find({
|
||||
relations: { personalization: true },
|
||||
relations: ["personalization"],
|
||||
})
|
||||
|
||||
expect(dbProvider[0].personalization).to.not.eql(undefined)
|
||||
|
||||
@ -30,7 +30,7 @@ describe("github issues > #1929 Select attributes in Find method - mongodb", ()
|
||||
product = new Product("test3", "label3", 30)
|
||||
await productRepository.save(product)
|
||||
await productRepository.find({
|
||||
select: { name: true, label: true },
|
||||
select: ["name", "label"],
|
||||
order: { name: 1 },
|
||||
})
|
||||
}),
|
||||
@ -47,7 +47,7 @@ describe("github issues > #1929 Select attributes in Find method - mongodb", ()
|
||||
product = new Product("test3", "label3", 30)
|
||||
await productRepository.save(product)
|
||||
await productRepository.findAndCount({
|
||||
select: { name: true, label: true },
|
||||
select: ["name", "label"],
|
||||
order: { name: 1 },
|
||||
})
|
||||
}),
|
||||
@ -65,7 +65,7 @@ describe("github issues > #1929 Select attributes in Find method - mongodb", ()
|
||||
const product3 = await productRepository.save(product)
|
||||
await productRepository.find({
|
||||
where: { _id: product3.id },
|
||||
select: { name: true, label: true },
|
||||
select: ["name", "label"],
|
||||
order: { name: 1 },
|
||||
})
|
||||
}),
|
||||
@ -82,7 +82,7 @@ describe("github issues > #1929 Select attributes in Find method - mongodb", ()
|
||||
product = new Product("test3", "label3", 30)
|
||||
await productRepository.findOne({
|
||||
where: { name: "test2" },
|
||||
select: { name: true, label: true },
|
||||
select: ["name", "label"],
|
||||
order: { name: 1 },
|
||||
})
|
||||
}),
|
||||
|
||||
@ -37,7 +37,7 @@ describe("github issues > #2044 Should not double get embedded column value", ()
|
||||
await connection.manager.save(photo)
|
||||
|
||||
const photos = await connection.manager.find(Photo, {
|
||||
relations: { user: true },
|
||||
relations: ["user"],
|
||||
})
|
||||
|
||||
const resultPhoto = photos[0]
|
||||
|
||||
@ -49,7 +49,7 @@ describe("github issues > #2632 createQueryBuilder relation remove works only if
|
||||
|
||||
let loadedPost1 = await connection.manager.findOne(Post, {
|
||||
where: { id: 1 },
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
expect(loadedPost1!.categories).to.deep.include({
|
||||
id: 1,
|
||||
@ -64,7 +64,7 @@ describe("github issues > #2632 createQueryBuilder relation remove works only if
|
||||
|
||||
loadedPost1 = await connection.manager.findOne(Post, {
|
||||
where: { id: 1 },
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
expect(loadedPost1!.categories).to.be.eql([])
|
||||
|
||||
@ -76,7 +76,7 @@ describe("github issues > #2632 createQueryBuilder relation remove works only if
|
||||
|
||||
let loadedPost2 = await connection.manager.findOne(Post, {
|
||||
where: { id: 2 },
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
expect(loadedPost2!.categories).to.deep.include({
|
||||
id: 2,
|
||||
@ -91,7 +91,7 @@ describe("github issues > #2632 createQueryBuilder relation remove works only if
|
||||
|
||||
loadedPost1 = await connection.manager.findOne(Post, {
|
||||
where: { id: 2 },
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
expect(loadedPost1!.categories).to.be.eql([])
|
||||
}),
|
||||
|
||||
@ -36,9 +36,7 @@ describe("github issues > #2965 Reuse preloaded lazy relations", () => {
|
||||
await repoNote.insert({ label: "note1", owner: personA })
|
||||
await repoNote.insert({ label: "note2", owner: personB })
|
||||
|
||||
const res1 = await repoPerson.find({
|
||||
relations: { notes: true },
|
||||
})
|
||||
const res1 = await repoPerson.find({ relations: ["notes"] })
|
||||
|
||||
const originalLoad: (...args: any[]) => Promise<any[]> =
|
||||
connection.relationLoader.load
|
||||
|
||||
@ -79,15 +79,11 @@ describe("github issues > #3118 shorten alias names (for RDBMS with a limit) whe
|
||||
const [loadedCategory] = await connection.manager.find(
|
||||
CategoryWithVeryLongName,
|
||||
{
|
||||
relations: {
|
||||
postsWithVeryLongName: {
|
||||
authorWithVeryLongName: {
|
||||
groupWithVeryLongName: true,
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"postsWithVeryLongName",
|
||||
// before: used to generate a SELECT "AS" alias like `CategoryWithVeryLongName__postsWithVeryLongName__authorWithVeryLongName_firstName`
|
||||
// now: `CaWiVeLoNa__poWiVeLoNa__auWiVeLoNa_firstName`, which is acceptable by Postgres (limit to 63 characters)
|
||||
// "postsWithVeryLongName.authorWithVeryLongName",
|
||||
"postsWithVeryLongName.authorWithVeryLongName",
|
||||
// before:
|
||||
// used to generate a JOIN "AS" alias like :
|
||||
// `CategoryWithVeryLongName__postsWithVeryLongName__authorWithVeryLongName_firstName`
|
||||
@ -99,8 +95,8 @@ describe("github issues > #3118 shorten alias names (for RDBMS with a limit) whe
|
||||
// now:
|
||||
// `CaWiVeLoNa__poWiVeLoNa__auWiVeLoNa_firstName`
|
||||
// `CaWiVeLoNa__poWiVeLoNa__auWiVeLoNa__grWiVeLoNa_name`
|
||||
// "postsWithVeryLongName.authorWithVeryLongName.groupWithVeryLongName",
|
||||
},
|
||||
"postsWithVeryLongName.authorWithVeryLongName.groupWithVeryLongName",
|
||||
],
|
||||
},
|
||||
)
|
||||
expect(loadedCategory).not.to.be.null
|
||||
@ -123,13 +119,11 @@ describe("github issues > #3118 shorten alias names (for RDBMS with a limit) whe
|
||||
const loadedCategories = await connection.manager.find(
|
||||
CategoryWithVeryLongName,
|
||||
{
|
||||
relations: {
|
||||
postsWithVeryLongName: {
|
||||
authorWithVeryLongName: {
|
||||
groupWithVeryLongName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: [
|
||||
"postsWithVeryLongName",
|
||||
"postsWithVeryLongName.authorWithVeryLongName",
|
||||
"postsWithVeryLongName.authorWithVeryLongName.groupWithVeryLongName",
|
||||
],
|
||||
},
|
||||
)
|
||||
expect(loadedCategories).to.be.an("array").that.is.not.empty
|
||||
|
||||
@ -123,11 +123,7 @@ describe('github issues > #3120 Add relation option "createForeignKeyConstraints
|
||||
ActionLog,
|
||||
{
|
||||
where: { action: "Test Log #1" },
|
||||
relations: {
|
||||
person: true,
|
||||
actionDetails: true,
|
||||
addresses: true,
|
||||
},
|
||||
relations: ["person", "actionDetails", "addresses"],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ describe("github issues > #4190 Relation decorators: allow to pass string instea
|
||||
await connection.manager.save(user)
|
||||
|
||||
const users = await connection.manager.find(User, {
|
||||
relations: { profile: true },
|
||||
relations: ["profile"],
|
||||
})
|
||||
|
||||
users.should.eql([
|
||||
@ -73,10 +73,10 @@ describe("github issues > #4190 Relation decorators: allow to pass string instea
|
||||
await connection.manager.save(user)
|
||||
|
||||
const users = await connection.manager.find(User, {
|
||||
relations: { photos: true },
|
||||
relations: ["photos"],
|
||||
})
|
||||
const photos = await connection.manager.find(Photo, {
|
||||
relations: { user: true },
|
||||
relations: ["user"],
|
||||
})
|
||||
|
||||
// Check one-to-many
|
||||
@ -130,7 +130,7 @@ describe("github issues > #4190 Relation decorators: allow to pass string instea
|
||||
await connection.manager.save(question)
|
||||
|
||||
const questions = await connection.manager.find(Question, {
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
|
||||
questions[0].categories.should.have.deep.members([
|
||||
|
||||
@ -75,38 +75,31 @@ describe("github issues > #5684 eager relation skips children relations", () =>
|
||||
}
|
||||
}
|
||||
|
||||
const relations = {
|
||||
company: {
|
||||
admin: true,
|
||||
staff: {
|
||||
company: {
|
||||
admin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
// "company.admin", // <-- can't be loaded without the fix.
|
||||
// "company.staff", // <-- can't be loaded without the fix.
|
||||
// "company.staff.company", // <-- can't be loaded without the fix.
|
||||
// "company.staff.company.admin", // <-- can't be loaded without the fix.
|
||||
}
|
||||
const relations = [
|
||||
"company",
|
||||
"company.admin", // <-- can't be loaded without the fix.
|
||||
"company.staff", // <-- can't be loaded without the fix.
|
||||
"company.staff.company", // <-- can't be loaded without the fix.
|
||||
"company.staff.company.admin", // <-- can't be loaded without the fix.
|
||||
]
|
||||
|
||||
const user1 = await connection.getRepository(User).findOne({
|
||||
where: { id: userAdmin.id },
|
||||
relations: relations,
|
||||
relations: [...relations],
|
||||
})
|
||||
assert(user1)
|
||||
const user2 = await connection
|
||||
.getRepository(User)
|
||||
.findOneOrFail({
|
||||
where: { id: userAdmin.id },
|
||||
relations: relations,
|
||||
relations: [...relations],
|
||||
})
|
||||
assert(user2)
|
||||
const users3 = await connection.getRepository(User).find({
|
||||
where: {
|
||||
id: userAdmin.id,
|
||||
},
|
||||
relations: relations,
|
||||
relations: [...relations],
|
||||
})
|
||||
assert(users3.pop())
|
||||
const [users4] = await connection
|
||||
@ -115,14 +108,14 @@ describe("github issues > #5684 eager relation skips children relations", () =>
|
||||
where: {
|
||||
id: userAdmin.id,
|
||||
},
|
||||
relations: relations,
|
||||
relations: [...relations],
|
||||
})
|
||||
assert(users4.pop())
|
||||
const users5 = await connection.getRepository(User).find({
|
||||
where: {
|
||||
id: In([userAdmin.id]),
|
||||
},
|
||||
relations: relations,
|
||||
relations: [...relations],
|
||||
})
|
||||
assert(users5.pop())
|
||||
}),
|
||||
|
||||
@ -103,29 +103,27 @@ describe("github issues > #5691 RelationId is too slow", () => {
|
||||
// const test1Start = new Date().getTime();
|
||||
// 54 rows for 1 root
|
||||
await connection.getRepository(Root).find({
|
||||
relations: {
|
||||
allChild1: {
|
||||
allShared: true,
|
||||
},
|
||||
allChild2: true,
|
||||
},
|
||||
relations: [
|
||||
"allChild1",
|
||||
"allChild1.allShared",
|
||||
"allChild2",
|
||||
],
|
||||
})
|
||||
// 21 rows 1 root
|
||||
await connection.getRepository(Root).find({
|
||||
relations: { allShared: true },
|
||||
relations: ["allShared"],
|
||||
})
|
||||
// const test1End = new Date().getTime();
|
||||
|
||||
// const test2Start = new Date().getTime();
|
||||
// 1134 rows 1 root
|
||||
await connection.getRepository(Root).find({
|
||||
relations: {
|
||||
allChild1: {
|
||||
allShared: true,
|
||||
},
|
||||
allChild2: true,
|
||||
allShared: true,
|
||||
},
|
||||
relations: [
|
||||
"allChild1",
|
||||
"allChild1.allShared",
|
||||
"allChild2",
|
||||
"allShared",
|
||||
],
|
||||
})
|
||||
// const test2End = new Date().getTime();
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ describe("github issues > #703.findOne does not return an empty array on OneToMa
|
||||
where: {
|
||||
id: 1,
|
||||
},
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
|
||||
loadedPost!.id.should.be.equal(1)
|
||||
|
||||
@ -32,7 +32,7 @@ describe("github issues > #7041 When requesting nested relations on foreign key
|
||||
where: {
|
||||
id: testUser.id,
|
||||
},
|
||||
relations: { admin: { organization: true } },
|
||||
relations: ["admin", "admin.organization"],
|
||||
})
|
||||
expect(foundUser?.randomField).eq("foo")
|
||||
expect(foundUser?.admin).eq(null)
|
||||
@ -50,7 +50,7 @@ describe("github issues > #7041 When requesting nested relations on foreign key
|
||||
where: {
|
||||
id: testUser.id,
|
||||
},
|
||||
relations: { membership: { organization: true } },
|
||||
relations: ["membership", "membership.organization"],
|
||||
})
|
||||
expect(foundUser?.randomField).eq("foo")
|
||||
expect(foundUser?.membership).eql([])
|
||||
|
||||
@ -50,7 +50,7 @@ describe("github issues > #7065 ChildEntity type relationship produces unexpecte
|
||||
where: {
|
||||
id: 1,
|
||||
},
|
||||
relations: { emails: true, phones: true },
|
||||
relations: ["emails", "phones"],
|
||||
})
|
||||
|
||||
expect(result!.emails.length).eq(1)
|
||||
|
||||
@ -25,13 +25,13 @@ describe("github issues > #7882 .findOne reduces relations to an empty array",
|
||||
it("should delete all documents related to search pattern", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const relations = { exampleText: true }
|
||||
const relations = ["exampleText"]
|
||||
|
||||
const repo = connection.getRepository(Example)
|
||||
|
||||
await repo.find({ relations })
|
||||
|
||||
expect(relations).to.be.eql({ exampleText: true })
|
||||
expect(relations).to.be.eql(["exampleText"])
|
||||
}),
|
||||
))
|
||||
})
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
import { Entity } from "../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../src/decorator/columns/Column"
|
||||
import { ObjectIdColumn } from "../../../../src/decorator/columns/ObjectIdColumn"
|
||||
// import { ObjectId } from "mongodb";
|
||||
import { ObjectID } from "../../../../src"
|
||||
|
||||
@Entity()
|
||||
export class Post {
|
||||
@ObjectIdColumn()
|
||||
id: ObjectID
|
||||
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
@Column()
|
||||
text: string
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
import "reflect-metadata"
|
||||
import { expect } from "chai"
|
||||
import { Connection } from "../../../src"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { Post } from "./entity/Post"
|
||||
|
||||
describe("github issues > #7907 add support for mongodb driver v4", () => {
|
||||
let connections: Connection[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [Post],
|
||||
enabledDrivers: ["mongodb"],
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(() => closeTestingConnections(connections))
|
||||
|
||||
it("should find the Post without throw error: Cannot read property 'prototype' of undefined", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const postMongoRepository = connection.getMongoRepository(Post)
|
||||
|
||||
// save a post
|
||||
const post = new Post()
|
||||
post.title = "Post"
|
||||
post.text = "This is a simple post"
|
||||
await postMongoRepository.save(post)
|
||||
|
||||
const findPosts = async () => {
|
||||
return postMongoRepository.find()
|
||||
}
|
||||
const posts = await findPosts()
|
||||
|
||||
expect(findPosts).to.not.throw()
|
||||
expect(posts).to.have.lengthOf(1)
|
||||
expect(posts[0]).to.be.instanceOf(Post)
|
||||
}),
|
||||
))
|
||||
})
|
||||
@ -40,7 +40,7 @@ describe("github issues > #8018 Non-unique relation property names causes entity
|
||||
await connection.manager.save([parent, child1, child2])
|
||||
|
||||
const result = await connection.manager.find(Parent, {
|
||||
relations: { children: true },
|
||||
relations: ["children"],
|
||||
})
|
||||
|
||||
expect(result).to.have.lengthOf(1)
|
||||
|
||||
@ -35,11 +35,7 @@ describe("persistence > delete orphans", () => {
|
||||
let postRepository: Repository<Post>
|
||||
let categoryId: number
|
||||
|
||||
beforeEach(async function () {
|
||||
if (connections.length === 0) {
|
||||
this.skip()
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
categoryRepository = connection.getRepository(Category)
|
||||
|
||||
@ -30,13 +30,13 @@ describe("other issues > preventing-injection", () => {
|
||||
const postWithOnlyIdSelected = await connection.manager.find(
|
||||
Post,
|
||||
{
|
||||
select: { id: true },
|
||||
select: ["id"],
|
||||
},
|
||||
)
|
||||
postWithOnlyIdSelected.should.be.eql([{ id: 1 }])
|
||||
|
||||
await connection.manager.find(Post, {
|
||||
select: "(WHERE LIMIT 1)" as any,
|
||||
select: ["(WHERE LIMIT 1)" as any],
|
||||
}).should.be.rejected
|
||||
}),
|
||||
))
|
||||
|
||||
@ -39,7 +39,7 @@ describe("other issues > Relation decorators: allow to pass given table name str
|
||||
await connection.manager.save(user)
|
||||
|
||||
const users = await connection.manager.find(User, {
|
||||
relations: { profile: true },
|
||||
relations: ["profile"],
|
||||
})
|
||||
|
||||
users.should.eql([
|
||||
@ -73,14 +73,10 @@ describe("other issues > Relation decorators: allow to pass given table name str
|
||||
await connection.manager.save(user)
|
||||
|
||||
const users = await connection.manager.find(User, {
|
||||
relations: {
|
||||
photos: true,
|
||||
},
|
||||
relations: ["photos"],
|
||||
})
|
||||
const photos = await connection.manager.find(Photo, {
|
||||
relations: {
|
||||
user: true,
|
||||
},
|
||||
relations: ["user"],
|
||||
})
|
||||
|
||||
// Check one-to-many
|
||||
@ -134,7 +130,7 @@ describe("other issues > Relation decorators: allow to pass given table name str
|
||||
await connection.manager.save(question)
|
||||
|
||||
const questions = await connection.manager.find(Question, {
|
||||
relations: { categories: true },
|
||||
relations: ["categories"],
|
||||
})
|
||||
|
||||
questions[0].categories.should.have.deep.members([
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user