orange-orm 3.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +1 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +45 -0
- package/.gitattributes +3 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +43 -0
- package/LICENSE +7 -0
- package/README.md +1969 -0
- package/SECURITY.md +12 -0
- package/bin/build.js +127 -0
- package/bin/compile.js +26 -0
- package/bin/rdb.js +4 -0
- package/docs/CODE_OF_CONDUCT.md +18 -0
- package/docs/changelog.md +461 -0
- package/docs/docs.md +2373 -0
- package/docs/orange.svg +32 -0
- package/docs/relations.png +0 -0
- package/package.json +139 -0
- package/src/applyPatch.js +105 -0
- package/src/client/axiosInterceptor.js +46 -0
- package/src/client/clientMap.js +72 -0
- package/src/client/createPatch.js +122 -0
- package/src/client/createProviders.js +121 -0
- package/src/client/index.js +997 -0
- package/src/client/index.mjs +6295 -0
- package/src/client/map.js +110 -0
- package/src/client/merge.js +9 -0
- package/src/client/netAdapter.js +133 -0
- package/src/client/rollup.config.js +12 -0
- package/src/client/self.js +4 -0
- package/src/client/stringify.js +22 -0
- package/src/client/toKeyPositionMap.js +30 -0
- package/src/clsTest.js +79 -0
- package/src/createDomain/negotiateForwardProperty.js +23 -0
- package/src/createDomain.js +31 -0
- package/src/dateToISOString.js +25 -0
- package/src/emitEvent.js +46 -0
- package/src/emptyFilter.js +35 -0
- package/src/flags.js +6 -0
- package/src/fromCompareObject.js +24 -0
- package/src/generic-pool.js +641 -0
- package/src/getManyDto/newQuery.js +18 -0
- package/src/getManyDto/query/newColumnSql.js +8 -0
- package/src/getManyDto/query/newSingleQuery.js +19 -0
- package/src/getManyDto/query/singleQuery/newJoinedColumnSql.js +25 -0
- package/src/getManyDto/query/singleQuery/newShallowColumnSql.js +25 -0
- package/src/getManyDto.js +255 -0
- package/src/getTSDefinition.js +510 -0
- package/src/hostExpress/executePath.js +433 -0
- package/src/hostExpress/getMeta.js +49 -0
- package/src/hostExpress.js +125 -0
- package/src/hostLocal.js +110 -0
- package/src/index.d.ts +324 -0
- package/src/index.js +116 -0
- package/src/jsconfig.json +8 -0
- package/src/lock/toIntKey.js +35 -0
- package/src/lock.js +26 -0
- package/src/map.d.ts +1729 -0
- package/src/mssql/encodeBuffer.js +7 -0
- package/src/mssql/newDatabase.js +129 -0
- package/src/mssql/newPool.js +19 -0
- package/src/mssql/newTransaction.js +69 -0
- package/src/mssql/pool/defaults.js +45 -0
- package/src/mssql/pool/end.js +13 -0
- package/src/mssql/pool/newGenericPool.js +62 -0
- package/src/mssql/wrapQuery.js +34 -0
- package/src/mySql/deleteFromSql.js +8 -0
- package/src/mySql/encodeBoolean.js +7 -0
- package/src/mySql/insert.js +21 -0
- package/src/mySql/insertSql.js +62 -0
- package/src/mySql/lastInsertedSql.js +11 -0
- package/src/mySql/limitAndOffset.js +18 -0
- package/src/mySql/newDatabase.js +127 -0
- package/src/mySql/newPool.js +19 -0
- package/src/mySql/newTransaction.js +54 -0
- package/src/mySql/pool/defaults.js +16 -0
- package/src/mySql/pool/end.js +13 -0
- package/src/mySql/pool/negotiatePoolOptions.js +12 -0
- package/src/mySql/pool/newGenericPool.js +67 -0
- package/src/mySql/selectForUpdateSql.js +3 -0
- package/src/mySql/wrapQuery.js +16 -0
- package/src/mySql/wrapQueryStream.js +9 -0
- package/src/newArray.js +3 -0
- package/src/newCollection.js +55 -0
- package/src/newId.js +1 -0
- package/src/newImmutable.js +22 -0
- package/src/newObject.js +5 -0
- package/src/oracle/deleteFromSql.js +8 -0
- package/src/oracle/encodeBoolean.js +7 -0
- package/src/oracle/encodeBuffer.js +7 -0
- package/src/oracle/encodeDate.js +7 -0
- package/src/oracle/formatDateIn.js +5 -0
- package/src/oracle/formatDateOut.js +5 -0
- package/src/oracle/insert.js +23 -0
- package/src/oracle/insertSql.js +73 -0
- package/src/oracle/lastInsertedSql.js +14 -0
- package/src/oracle/limitAndOffset.js +18 -0
- package/src/oracle/mergeSql.js +79 -0
- package/src/oracle/newDatabase.js +128 -0
- package/src/oracle/newInsertCommandCore.js +27 -0
- package/src/oracle/newPool.js +19 -0
- package/src/oracle/newTransaction.js +63 -0
- package/src/oracle/outputInsertedSql.js +5 -0
- package/src/oracle/pool/defaults.js +45 -0
- package/src/oracle/pool/end.js +13 -0
- package/src/oracle/pool/newGenericPool.js +64 -0
- package/src/oracle/replaceParamChar.js +14 -0
- package/src/oracle/selectForUpdateSql.js +3 -0
- package/src/oracle/wrapQuery.js +38 -0
- package/src/patchRow.js +13 -0
- package/src/patchTable.js +317 -0
- package/src/pg/deleteFromSql.js +8 -0
- package/src/pg/encodeBoolean.js +5 -0
- package/src/pg/encodeDate.js +7 -0
- package/src/pg/encodeJSON.js +15 -0
- package/src/pg/formatDateOut.js +5 -0
- package/src/pg/insert.js +14 -0
- package/src/pg/insertSql.js +70 -0
- package/src/pg/lastInsertedSql.js +11 -0
- package/src/pg/limitAndOffset.js +18 -0
- package/src/pg/newDatabase.js +153 -0
- package/src/pg/newPool.js +19 -0
- package/src/pg/newStreamableQuery.js +7 -0
- package/src/pg/newTransaction.js +58 -0
- package/src/pg/pool/defaults.js +45 -0
- package/src/pg/pool/end.js +13 -0
- package/src/pg/pool/newPgPool.js +82 -0
- package/src/pg/replaceParamChar.js +14 -0
- package/src/pg/schema.js +11 -0
- package/src/pg/selectForUpdateSql.js +3 -0
- package/src/pg/wrapQuery.js +33 -0
- package/src/pg/wrapQueryStream.js +20 -0
- package/src/pools.js +17 -0
- package/src/query/negotiateParameters.js +10 -0
- package/src/query/negotiateSql.js +14 -0
- package/src/query/wrapQuery.js +17 -0
- package/src/query.js +13 -0
- package/src/sap/deleteFromSql.js +8 -0
- package/src/sap/encodeBoolean.js +7 -0
- package/src/sap/encodeBuffer.js +7 -0
- package/src/sap/formatDateOut.js +5 -0
- package/src/sap/insert.js +21 -0
- package/src/sap/insertSql.js +64 -0
- package/src/sap/lastInsertedSql.js +12 -0
- package/src/sap/limitAndOffset.js +16 -0
- package/src/sap/mergeSql.js +73 -0
- package/src/sap/newDatabase.js +129 -0
- package/src/sap/newPool.js +19 -0
- package/src/sap/newTransaction.js +69 -0
- package/src/sap/pool/end.js +13 -0
- package/src/sap/selectForUpdateSql.js +3 -0
- package/src/sqlite/deleteFromSql.js +8 -0
- package/src/sqlite/encodeBoolean.js +7 -0
- package/src/sqlite/encodeBuffer.js +7 -0
- package/src/sqlite/insert.js +21 -0
- package/src/sqlite/insertSql.js +64 -0
- package/src/sqlite/lastInsertedSql.js +12 -0
- package/src/sqlite/limitAndOffset.js +18 -0
- package/src/sqlite/newDatabase.js +128 -0
- package/src/sqlite/newPool.js +19 -0
- package/src/sqlite/newTransaction.js +58 -0
- package/src/sqlite/pool/defaults.js +45 -0
- package/src/sqlite/pool/end.js +13 -0
- package/src/sqlite/pool/newGenericPool.js +59 -0
- package/src/sqlite/selectForUpdateSql.js +3 -0
- package/src/sqlite/wrapQuery.js +24 -0
- package/src/table/aggregate.js +9 -0
- package/src/table/begin.js +10 -0
- package/src/table/cascadeDelete.js +11 -0
- package/src/table/cloneStrategy.js +18 -0
- package/src/table/column/binary/newDecode.js +15 -0
- package/src/table/column/binary/newEncode.js +23 -0
- package/src/table/column/binary/purify.js +12 -0
- package/src/table/column/binary.js +12 -0
- package/src/table/column/boolean/newDecode.js +12 -0
- package/src/table/column/boolean/newEncode.js +36 -0
- package/src/table/column/boolean/purify.js +7 -0
- package/src/table/column/boolean.js +14 -0
- package/src/table/column/date/formatOut.js +11 -0
- package/src/table/column/date/newDecode.js +17 -0
- package/src/table/column/date/newEncode.js +47 -0
- package/src/table/column/date/purify.js +17 -0
- package/src/table/column/date/toISOString.js +25 -0
- package/src/table/column/date/tryParseISO.js +14 -0
- package/src/table/column/date.js +14 -0
- package/src/table/column/dateWithTimeZone/newEncode.js +41 -0
- package/src/table/column/dateWithTimeZone.js +14 -0
- package/src/table/column/encodeFilterArg.js +8 -0
- package/src/table/column/equal.js +15 -0
- package/src/table/column/extractAlias.js +7 -0
- package/src/table/column/greaterThan.js +12 -0
- package/src/table/column/greaterThanOrEqual.js +12 -0
- package/src/table/column/guid/newDecode.js +10 -0
- package/src/table/column/guid/newEncode.js +30 -0
- package/src/table/column/guid/purify.js +10 -0
- package/src/table/column/guid.js +12 -0
- package/src/table/column/in.js +24 -0
- package/src/table/column/json/formatOut.js +11 -0
- package/src/table/column/json/newDecode.js +21 -0
- package/src/table/column/json/newEncode.js +41 -0
- package/src/table/column/json/purify.js +7 -0
- package/src/table/column/json.js +22 -0
- package/src/table/column/lessThan.js +12 -0
- package/src/table/column/lessThanOrEqual.js +12 -0
- package/src/table/column/negotiateNextAndFilter.js +7 -0
- package/src/table/column/negotiateNextOrFilter.js +7 -0
- package/src/table/column/negotiateRawSqlFilter.js +74 -0
- package/src/table/column/newBoolean.js +54 -0
- package/src/table/column/newColumn.js +89 -0
- package/src/table/column/newDecodeCore.js +10 -0
- package/src/table/column/notEqual.js +15 -0
- package/src/table/column/numeric/negotiateDefault.js +5 -0
- package/src/table/column/numeric/newDecode.js +16 -0
- package/src/table/column/numeric/newEncode.js +25 -0
- package/src/table/column/numeric/purify.js +12 -0
- package/src/table/column/numeric.js +15 -0
- package/src/table/column/string/contains.js +3 -0
- package/src/table/column/string/containsCore.js +16 -0
- package/src/table/column/string/endsWith.js +3 -0
- package/src/table/column/string/endsWithCore.js +16 -0
- package/src/table/column/string/iContains.js +3 -0
- package/src/table/column/string/iEndsWith.js +3 -0
- package/src/table/column/string/iEqual.js +15 -0
- package/src/table/column/string/iStartsWith.js +3 -0
- package/src/table/column/string/newEncode.js +31 -0
- package/src/table/column/string/purify.js +7 -0
- package/src/table/column/string/startsWith.js +3 -0
- package/src/table/column/string/startsWithCore.js +16 -0
- package/src/table/column/string.js +55 -0
- package/src/table/column.js +154 -0
- package/src/table/commands/beginCommand.js +13 -0
- package/src/table/commands/commitCommand.js +9 -0
- package/src/table/commands/compressChanges.js +25 -0
- package/src/table/commands/delete/createAlias.js +6 -0
- package/src/table/commands/delete/newSingleCommand.js +17 -0
- package/src/table/commands/delete/singleCommand/joinSql.js +26 -0
- package/src/table/commands/delete/singleCommand/newSingleCommandCore.js +19 -0
- package/src/table/commands/delete/singleCommand/selectSql.js +11 -0
- package/src/table/commands/delete/singleCommand/subFilter.js +19 -0
- package/src/table/commands/delete/singleCommand/whereSql.js +25 -0
- package/src/table/commands/getChangeSet.js +6 -0
- package/src/table/commands/insert/getSqlTemplate.js +68 -0
- package/src/table/commands/lastCommandMatches.js +11 -0
- package/src/table/commands/negotiateEndEdit.js +7 -0
- package/src/table/commands/newDeleteCommand.js +23 -0
- package/src/table/commands/newGetLastInsertedCommand.js +49 -0
- package/src/table/commands/newGetLastInsertedCommandCore.js +42 -0
- package/src/table/commands/newInsertAndForgetCommand.js +55 -0
- package/src/table/commands/newInsertCommand.js +56 -0
- package/src/table/commands/newInsertCommandCore.js +27 -0
- package/src/table/commands/newRow.js +51 -0
- package/src/table/commands/newUpdateCommand.js +62 -0
- package/src/table/commands/newUpdateCommandCore.js +45 -0
- package/src/table/commands/pushCommand.js +10 -0
- package/src/table/commands/rollbackCommand.js +13 -0
- package/src/table/commit.js +30 -0
- package/src/table/count.js +29 -0
- package/src/table/createJSONReadStream.js +7 -0
- package/src/table/createJSONReadStreamDefault.js +33 -0
- package/src/table/createJSONReadStreamNative.js +31 -0
- package/src/table/createReadStream.js +24 -0
- package/src/table/createReadStreamCoreNative.js +40 -0
- package/src/table/createReadStreamDefault.js +102 -0
- package/src/table/createReadStreamNative.js +17 -0
- package/src/table/delete.js +20 -0
- package/src/table/deleteSessionContext.js +17 -0
- package/src/table/encodeDbSpecific.js +10 -0
- package/src/table/executeQueries/executeChanges.js +35 -0
- package/src/table/executeQueries/executeQueriesCore.js +12 -0
- package/src/table/executeQueries/executeQuery.js +8 -0
- package/src/table/executeQueries/resolveExecuteQuery.js +57 -0
- package/src/table/executeQueries.js +15 -0
- package/src/table/extractDeleteStrategy.js +9 -0
- package/src/table/fuzzyPromise.js +18 -0
- package/src/table/getById.js +33 -0
- package/src/table/getFirstFromDb.js +10 -0
- package/src/table/getFromDbById.js +17 -0
- package/src/table/getIdArgs.js +14 -0
- package/src/table/getMany.js +26 -0
- package/src/table/getManyDto/newQuery.js +32 -0
- package/src/table/getManyDto/pg/newQuery.js +8 -0
- package/src/table/getManyDto.js +10 -0
- package/src/table/getManyDtoFast/getSubRows.js +172 -0
- package/src/table/getManyDtoFast/newQuery.js +8 -0
- package/src/table/getManyDtoFast/newQueryCore.js +18 -0
- package/src/table/getManyDtoFast/query/newSingleQuery.js +20 -0
- package/src/table/getManyDtoFast/query/newSubQueries/joinLegToQuery.js +18 -0
- package/src/table/getManyDtoFast/query/newSubQueries/manyLegToQuery.js +20 -0
- package/src/table/getManyDtoFast/query/newSubQueries/oneLegToQuery.js +21 -0
- package/src/table/getManyDtoFast/query/newSubQueries.js +47 -0
- package/src/table/getManyDtoFast/query/singleQuery/newShallowColumnSql.js +21 -0
- package/src/table/getSessionContext.js +10 -0
- package/src/table/getSessionSingleton.js +5 -0
- package/src/table/groupBy/newQuery.js +25 -0
- package/src/table/groupBy.js +65 -0
- package/src/table/hasMany.js +33 -0
- package/src/table/hasOne.js +33 -0
- package/src/table/insert.js +91 -0
- package/src/table/insertDefault.js +88 -0
- package/src/table/join.js +42 -0
- package/src/table/joinRelation/getRelatives.js +64 -0
- package/src/table/log.js +39 -0
- package/src/table/negotiateAddStrategy.js +20 -0
- package/src/table/negotiateExpandInverse.js +13 -0
- package/src/table/newCache.js +96 -0
- package/src/table/newCascadeDeleteStrategy.js +30 -0
- package/src/table/newGetRelated.js +21 -0
- package/src/table/newJoinRelation.js +117 -0
- package/src/table/newManyRelation.js +61 -0
- package/src/table/newOneRelation.js +61 -0
- package/src/table/newPrimaryKeyFilter.js +13 -0
- package/src/table/newQuery.js +18 -0
- package/src/table/newRelatedTable.js +100 -0
- package/src/table/newRowCache.js +106 -0
- package/src/table/newThrow.js +11 -0
- package/src/table/nullPromise.js +1 -0
- package/src/table/objectToCallback.js +7 -0
- package/src/table/oneRelation/getRelatives.js +45 -0
- package/src/table/popChanges.js +19 -0
- package/src/table/promise.js +14 -0
- package/src/table/purifyStrategy.js +49 -0
- package/src/table/query/extractFilter.js +9 -0
- package/src/table/query/extractLimit.js +11 -0
- package/src/table/query/extractLimitQuery.js +23 -0
- package/src/table/query/extractOffset.js +11 -0
- package/src/table/query/extractOrderBy.js +57 -0
- package/src/table/query/extractSql.js +10 -0
- package/src/table/query/newParameterized.js +38 -0
- package/src/table/query/newSingleQuery.js +23 -0
- package/src/table/query/parameterized/extractParameters.js +8 -0
- package/src/table/query/singleQuery/columnSql/joinLegToColumnSql.js +16 -0
- package/src/table/query/singleQuery/columnSql/newJoinedColumnSql.js +27 -0
- package/src/table/query/singleQuery/columnSql/newShallowColumnSql.js +37 -0
- package/src/table/query/singleQuery/joinSql/joinLegToJoinSql.js +13 -0
- package/src/table/query/singleQuery/joinSql/joinLegToShallowJoinSql.js +9 -0
- package/src/table/query/singleQuery/joinSql/newDiscriminatorSql.js +11 -0
- package/src/table/query/singleQuery/joinSql/newShallowJoinSql.js +9 -0
- package/src/table/query/singleQuery/joinSql/newShallowJoinSqlCore.js +25 -0
- package/src/table/query/singleQuery/joinSql/oneLegToJoinSql.js +13 -0
- package/src/table/query/singleQuery/joinSql/oneLegToShallowJoinSql.js +10 -0
- package/src/table/query/singleQuery/negotiateExclusive.js +11 -0
- package/src/table/query/singleQuery/negotiateLimit.js +10 -0
- package/src/table/query/singleQuery/newColumnSql.js +8 -0
- package/src/table/query/singleQuery/newDiscriminatorSql.js +33 -0
- package/src/table/query/singleQuery/newJoinSql.js +41 -0
- package/src/table/query/singleQuery/newQueryContext.js +20 -0
- package/src/table/query/singleQuery/newWhereSql.js +19 -0
- package/src/table/readStream/extractLimit.js +7 -0
- package/src/table/readStream/extractOrderBy.js +55 -0
- package/src/table/readStream/mySql/newQuery.js +16 -0
- package/src/table/readStream/mySql/query/newSingleQuery.js +21 -0
- package/src/table/readStream/mySql/query/newSubQueries/joinLegToQuery.js +19 -0
- package/src/table/readStream/mySql/query/newSubQueries/manyLegToQuery.js +22 -0
- package/src/table/readStream/mySql/query/newSubQueries/newQueryCore.js +9 -0
- package/src/table/readStream/mySql/query/newSubQueries/newSingleQueryCore.js +18 -0
- package/src/table/readStream/mySql/query/newSubQueries/oneLegToQuery.js +22 -0
- package/src/table/readStream/mySql/query/newSubQueries.js +47 -0
- package/src/table/readStream/mySql/query/singleQuery/newShallowColumnSql.js +17 -0
- package/src/table/readStream/newQuery.js +32 -0
- package/src/table/readStream/newQueryStream.js +8 -0
- package/src/table/readStream/pg/newQuery.js +8 -0
- package/src/table/readStream/pg/newQueryCore.js +17 -0
- package/src/table/readStream/pg/query/newSingleQuery.js +19 -0
- package/src/table/readStream/pg/query/newSubQueries/joinLegToQuery.js +19 -0
- package/src/table/readStream/pg/query/newSubQueries/manyLegToQuery.js +22 -0
- package/src/table/readStream/pg/query/newSubQueries/oneLegToQuery.js +19 -0
- package/src/table/readStream/pg/query/newSubQueries.js +47 -0
- package/src/table/readStream/pg/query/singleQuery/newShallowColumnSql.js +19 -0
- package/src/table/readStreamDefault/createBatchFilter.js +39 -0
- package/src/table/relatedTable/aggregate/aggregateJoinSql.js +37 -0
- package/src/table/relatedTable/aggregate/joinSql.js +38 -0
- package/src/table/relatedTable/aggregate.js +48 -0
- package/src/table/relatedTable/all.js +24 -0
- package/src/table/relatedTable/any.js +70 -0
- package/src/table/relatedTable/childColumn.js +61 -0
- package/src/table/relatedTable/columnAggregate.js +16 -0
- package/src/table/relatedTable/columnAggregateGroup.js +59 -0
- package/src/table/relatedTable/joinSql.js +40 -0
- package/src/table/relatedTable/joinSqlArray.js +32 -0
- package/src/table/relatedTable/none.js +22 -0
- package/src/table/relatedTable/relatedColumn.js +49 -0
- package/src/table/relatedTable/relationFilter.js +16 -0
- package/src/table/relatedTable/selectSql.js +11 -0
- package/src/table/relatedTable/subFilter.js +16 -0
- package/src/table/relatedTable/where.js +50 -0
- package/src/table/relatedTable/whereSql.js +41 -0
- package/src/table/relation/manyCache/extractParentKey.js +17 -0
- package/src/table/relation/manyCache/synchronizeAdded.js +13 -0
- package/src/table/relation/manyCache/synchronizeChanged.js +31 -0
- package/src/table/relation/manyCache/synchronizeRemoved.js +13 -0
- package/src/table/relation/newExpanderCache.js +7 -0
- package/src/table/relation/newForeignKeyFilter.js +20 -0
- package/src/table/relation/newJoinLeg.js +23 -0
- package/src/table/relation/newManyCache.js +57 -0
- package/src/table/relation/newManyCacheCore.js +53 -0
- package/src/table/relation/newManyLeg.js +15 -0
- package/src/table/relation/newOneCache.js +28 -0
- package/src/table/relation/newOneLeg.js +25 -0
- package/src/table/releaseDbClient.js +15 -0
- package/src/table/resultToPromise.js +8 -0
- package/src/table/resultToRows/dbRowToRow.js +51 -0
- package/src/table/resultToRows/dbRowsToRows.js +13 -0
- package/src/table/resultToRows/decodeDbRow.js +25 -0
- package/src/table/resultToRows/delete/removeFromCache.js +33 -0
- package/src/table/resultToRows/delete.js +31 -0
- package/src/table/resultToRows/negotiateQueryContext.js +6 -0
- package/src/table/resultToRows/newDecodeDbRow.js +262 -0
- package/src/table/resultToRows/toDto/createDto.js +20 -0
- package/src/table/resultToRows/toDto/extractStrategy.js +41 -0
- package/src/table/resultToRows/toDto.js +92 -0
- package/src/table/resultToRows.js +37 -0
- package/src/table/rollback.js +31 -0
- package/src/table/rowArray/negotiateNextTick.js +11 -0
- package/src/table/rowArray/orderBy.js +51 -0
- package/src/table/rowArray.js +62 -0
- package/src/table/setSessionSingleton.js +5 -0
- package/src/table/strategyToSpan.js +49 -0
- package/src/table/tryGetById.js +13 -0
- package/src/table/tryGetFirstFromDb.js +23 -0
- package/src/table/tryGetFromCacheById.js +12 -0
- package/src/table/tryGetFromDbById/extractStrategy.js +9 -0
- package/src/table/tryGetFromDbById.js +19 -0
- package/src/table/tryGetSessionContext.js +16 -0
- package/src/table/tryReleaseDbClient.js +14 -0
- package/src/table/updateField.js +12 -0
- package/src/table/where.js +12 -0
- package/src/table.js +174 -0
- package/src/tedious/deleteFromSql.js +8 -0
- package/src/tedious/encodeBoolean.js +7 -0
- package/src/tedious/encodeBuffer.js +7 -0
- package/src/tedious/formatDateOut.js +5 -0
- package/src/tedious/formatJSONOut.js +5 -0
- package/src/tedious/getManyDto/newQuery.js +8 -0
- package/src/tedious/getManyDto/newQueryCore.js +18 -0
- package/src/tedious/getManyDto/query/newSingleQuery.js +29 -0
- package/src/tedious/getManyDto/query/newSubQueries/joinLegToQuery.js +16 -0
- package/src/tedious/getManyDto/query/newSubQueries/manyLegToQuery.js +16 -0
- package/src/tedious/getManyDto/query/newSubQueries/oneLegToQuery.js +19 -0
- package/src/tedious/getManyDto/query/newSubQueries.js +48 -0
- package/src/tedious/getManyDto/query/singleQuery/newShallowColumnSql.js +34 -0
- package/src/tedious/getManyDto.js +27 -0
- package/src/tedious/insert.js +13 -0
- package/src/tedious/insertSql.js +70 -0
- package/src/tedious/limitAndOffset.js +16 -0
- package/src/tedious/mergeSql.js +76 -0
- package/src/tedious/newDatabase.js +129 -0
- package/src/tedious/newPool.js +19 -0
- package/src/tedious/newTransaction.js +72 -0
- package/src/tedious/outputInsertedSql.js +11 -0
- package/src/tedious/pool/defaults.js +45 -0
- package/src/tedious/pool/end.js +13 -0
- package/src/tedious/pool/newGenericPool.js +71 -0
- package/src/tedious/pool/parseConnectionString.js +40 -0
- package/src/tedious/selectForUpdateSql.js +3 -0
- package/src/tedious/wrapQuery.js +112 -0
- package/src/toCompareObject.js +41 -0
- package/src/useHook.js +9 -0
- package/src/validateDeleteAllowed.js +49 -0
- package/src/validateDeleteConflict.js +92 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var newParameterized = require('../table/query/newParameterized');
|
|
2
|
+
var insertSql = require('./insertSql');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
function newInsertCommandCore(table, row, options = {}) {
|
|
6
|
+
var parameters = [];
|
|
7
|
+
var values = [insertSql(table, row, options)];
|
|
8
|
+
|
|
9
|
+
var columns = table._columns;
|
|
10
|
+
for (var i = 0; i < columns.length; i++) {
|
|
11
|
+
var column = columns[i];
|
|
12
|
+
var alias = column.alias;
|
|
13
|
+
if (row['__' + column.alias] !== undefined) {
|
|
14
|
+
var encoded = column.encode(row[alias]);
|
|
15
|
+
if (encoded.parameters.length > 0) {
|
|
16
|
+
values.push('?');
|
|
17
|
+
parameters.push(encoded.parameters[0]);
|
|
18
|
+
} else
|
|
19
|
+
values.push(encoded.sql());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var sql = util.format.apply(null, values);
|
|
24
|
+
return newParameterized(sql, parameters);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = newInsertCommandCore;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var pools = require('../pools');
|
|
2
|
+
var promise = require('../table/promise');
|
|
3
|
+
var end = require('./pool/end');
|
|
4
|
+
var newGenericPool = require('./pool/newGenericPool');
|
|
5
|
+
var newId = require('../newId');
|
|
6
|
+
|
|
7
|
+
function newPool(connectionString, poolOptions) {
|
|
8
|
+
var pool = newGenericPool(connectionString, poolOptions);
|
|
9
|
+
var id = newId();
|
|
10
|
+
var boundEnd = end.bind(null, pool, id);
|
|
11
|
+
var c = {};
|
|
12
|
+
|
|
13
|
+
c.connect = pool.connect;
|
|
14
|
+
c.end = promise.denodeify(boundEnd);
|
|
15
|
+
pools[id] = c;
|
|
16
|
+
return c;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = newPool;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const wrapQuery = require('./wrapQuery');
|
|
2
|
+
const encodeBoolean = require('./encodeBoolean');
|
|
3
|
+
const deleteFromSql = require('./deleteFromSql');
|
|
4
|
+
const selectForUpdateSql = require('./selectForUpdateSql');
|
|
5
|
+
const lastInsertedSql = require('./lastInsertedSql');
|
|
6
|
+
const limitAndOffset = require('./limitAndOffset');
|
|
7
|
+
const insertSql = require('./insertSql');
|
|
8
|
+
const insert = require('./insert');
|
|
9
|
+
const formatDateOut = require('./formatDateOut');
|
|
10
|
+
const formatDateIn = require('./formatDateIn');
|
|
11
|
+
|
|
12
|
+
function newResolveTransaction(domain, pool) {
|
|
13
|
+
var rdb = {poolFactory: pool};
|
|
14
|
+
if (!pool.connect) {
|
|
15
|
+
pool = pool();
|
|
16
|
+
rdb.pool = pool;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return function(onSuccess, onError) {
|
|
20
|
+
pool.connect(onConnected);
|
|
21
|
+
|
|
22
|
+
function onConnected(err, client, done) {
|
|
23
|
+
try {
|
|
24
|
+
if (err) {
|
|
25
|
+
onError(err);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
client.executeQuery = wrapQuery(client);
|
|
29
|
+
rdb.begin = 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED';
|
|
30
|
+
rdb.engine = 'oracle';
|
|
31
|
+
rdb.dbClient = client;
|
|
32
|
+
rdb.dbClientDone = done;
|
|
33
|
+
rdb.encodeBoolean = encodeBoolean;
|
|
34
|
+
rdb.decodeJSON = decodeJSON;
|
|
35
|
+
rdb.encodeJSON = JSON.stringify;
|
|
36
|
+
rdb.formatDateOut = formatDateOut;
|
|
37
|
+
rdb.formatDateIn = formatDateIn;
|
|
38
|
+
rdb.deleteFromSql = deleteFromSql;
|
|
39
|
+
rdb.selectForUpdateSql = selectForUpdateSql;
|
|
40
|
+
rdb.lastInsertedSql = lastInsertedSql;
|
|
41
|
+
rdb.insertSql = insertSql;
|
|
42
|
+
rdb.insert = insert;
|
|
43
|
+
rdb.lastInsertedIsSeparate = true;
|
|
44
|
+
rdb.multipleStatements = false;
|
|
45
|
+
rdb.limitAndOffset = limitAndOffset;
|
|
46
|
+
rdb.accept = function(caller) {
|
|
47
|
+
caller.visitSqlite();
|
|
48
|
+
};
|
|
49
|
+
rdb.aggregateCount = 0;
|
|
50
|
+
domain.rdb = rdb;
|
|
51
|
+
onSuccess();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
onError(e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function decodeJSON(value) {
|
|
60
|
+
return JSON.parse(value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = newResolveTransaction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// database host defaults to localhost
|
|
3
|
+
host: 'localhost',
|
|
4
|
+
|
|
5
|
+
//database user's name
|
|
6
|
+
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
|
|
7
|
+
|
|
8
|
+
//name of database to connect
|
|
9
|
+
database: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
|
|
10
|
+
|
|
11
|
+
//database user's password
|
|
12
|
+
password: null,
|
|
13
|
+
|
|
14
|
+
//database port
|
|
15
|
+
port: 5432,
|
|
16
|
+
|
|
17
|
+
//number of rows to return at a time from a prepared statement's
|
|
18
|
+
//portal. 0 will return all rows at once
|
|
19
|
+
rows: 0,
|
|
20
|
+
|
|
21
|
+
// binary result mode
|
|
22
|
+
binary: false,
|
|
23
|
+
|
|
24
|
+
//Connection pool options - see https://github.com/coopernurse/node-pool
|
|
25
|
+
//number of connections to use in connection pool
|
|
26
|
+
//0 will disable connection pooling
|
|
27
|
+
poolSize: 0,
|
|
28
|
+
|
|
29
|
+
//max milliseconds a client can go unused before it is removed
|
|
30
|
+
//from the pool and destroyed
|
|
31
|
+
poolIdleTimeout: 30000,
|
|
32
|
+
|
|
33
|
+
//frequeny to check for idle clients within the client pool
|
|
34
|
+
reapIntervalMillis: 1000,
|
|
35
|
+
|
|
36
|
+
//pool log function / boolean
|
|
37
|
+
poolLog: false,
|
|
38
|
+
|
|
39
|
+
client_encoding: '',
|
|
40
|
+
|
|
41
|
+
ssl: false,
|
|
42
|
+
|
|
43
|
+
application_name : undefined,
|
|
44
|
+
fallback_application_name: undefined
|
|
45
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable no-prototype-builtins */
|
|
3
|
+
var EventEmitter = require('events').EventEmitter;
|
|
4
|
+
|
|
5
|
+
var defaults = require('./defaults');
|
|
6
|
+
var genericPool = require('../../generic-pool');
|
|
7
|
+
var oracle = require('oracledb');
|
|
8
|
+
|
|
9
|
+
oracle.outFormat = oracle.OUT_FORMAT_OBJECT;
|
|
10
|
+
oracle.fetchAsBuffer = [ oracle.BLOB ];
|
|
11
|
+
|
|
12
|
+
function newGenericPool(connectionString, poolOptions) {
|
|
13
|
+
poolOptions = poolOptions || {};
|
|
14
|
+
var pool = genericPool.Pool({
|
|
15
|
+
max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
|
|
16
|
+
idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
|
|
17
|
+
reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
|
|
18
|
+
log: poolOptions.log || defaults.poolLog,
|
|
19
|
+
create: function(cb) {
|
|
20
|
+
var client;
|
|
21
|
+
oracle.getConnection(connectionString, onConnected);
|
|
22
|
+
function onConnected(err, _client) {
|
|
23
|
+
client = _client;
|
|
24
|
+
if (err)
|
|
25
|
+
return cb(err, null);
|
|
26
|
+
client.poolCount = 0;
|
|
27
|
+
return cb(null, client);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
destroy: function(client) {
|
|
32
|
+
client.poolCount = undefined;
|
|
33
|
+
client.close();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//mixin EventEmitter to pool
|
|
37
|
+
EventEmitter.call(pool);
|
|
38
|
+
for (var key in EventEmitter.prototype) {
|
|
39
|
+
if (EventEmitter.prototype.hasOwnProperty(key)) {
|
|
40
|
+
pool[key] = EventEmitter.prototype[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//monkey-patch with connect method
|
|
44
|
+
pool.connect = function(cb) {
|
|
45
|
+
var domain = process.domain;
|
|
46
|
+
pool.acquire(function(err, client) {
|
|
47
|
+
if (domain) {
|
|
48
|
+
cb = domain.bind(cb);
|
|
49
|
+
}
|
|
50
|
+
if (err) return cb(err, null, function() {/*NOOP*/ });
|
|
51
|
+
client.poolCount++;
|
|
52
|
+
cb(null, client, function(err) {
|
|
53
|
+
if (err) {
|
|
54
|
+
pool.destroy(client);
|
|
55
|
+
} else {
|
|
56
|
+
pool.release(client);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return pool;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = newGenericPool;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function replaceParamChar(query, params) {
|
|
2
|
+
if (params.length === 0)
|
|
3
|
+
return query.sql();
|
|
4
|
+
var splitted = query.sql().split('?');
|
|
5
|
+
var sql = '';
|
|
6
|
+
var lastIndex = splitted.length - 1;
|
|
7
|
+
for (var i = 0; i < lastIndex; i++) {
|
|
8
|
+
sql += splitted[i] + ':p' + (i + 1);
|
|
9
|
+
}
|
|
10
|
+
sql += splitted[lastIndex];
|
|
11
|
+
return sql;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = replaceParamChar;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var log = require('../table/log');
|
|
2
|
+
var replaceParamChar = require('./replaceParamChar');
|
|
3
|
+
|
|
4
|
+
function wrapQuery(connection) {
|
|
5
|
+
var runOriginalQuery = connection.execute;
|
|
6
|
+
return runQuery;
|
|
7
|
+
|
|
8
|
+
function runQuery(query, onCompleted) {
|
|
9
|
+
var params = query.parameters;
|
|
10
|
+
var sql = replaceParamChar(query, params);
|
|
11
|
+
log.emitQuery({ sql, parameters: params });
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
runOriginalQuery.call(connection, sql, params, {
|
|
17
|
+
fetchTypeHandler: function(metaData) {
|
|
18
|
+
// Tells the database to return column names in lowercase
|
|
19
|
+
metaData.name = metaData.name.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
}, onInnerCompleted);
|
|
22
|
+
|
|
23
|
+
function onInnerCompleted(err, rows) {
|
|
24
|
+
if (err)
|
|
25
|
+
onCompleted(err);
|
|
26
|
+
else {
|
|
27
|
+
if (rows.rows)
|
|
28
|
+
rows = rows.rows;
|
|
29
|
+
else
|
|
30
|
+
rows = [rows];
|
|
31
|
+
onCompleted(null, rows);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = wrapQuery;
|
package/src/patchRow.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let patchTable = require('./patchTable');
|
|
2
|
+
|
|
3
|
+
function patchRow(table, row, patches, options) {
|
|
4
|
+
patches = JSON.parse(JSON.stringify(patches));
|
|
5
|
+
let pkName = table._primaryColumns[0].alias;
|
|
6
|
+
let id = row[pkName];
|
|
7
|
+
for (let i = 0; i < patches.length; i++) {
|
|
8
|
+
patches[i].path = '/' + id + patches[i].path;
|
|
9
|
+
}
|
|
10
|
+
return patchTable(table, patches, options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = patchRow;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/* eslint-disable require-atomic-updates */
|
|
2
|
+
let applyPatch = require('./applyPatch');
|
|
3
|
+
let fromCompareObject = require('./fromCompareObject');
|
|
4
|
+
let validateDeleteConflict = require('./validateDeleteConflict');
|
|
5
|
+
let validateDeleteAllowed = require('./validateDeleteAllowed');
|
|
6
|
+
|
|
7
|
+
async function patchTable() {
|
|
8
|
+
// const dryrun = true;
|
|
9
|
+
//traverse all rows you want to update before updatinng or inserting anything.
|
|
10
|
+
//this is to avoid page locks in ms sql
|
|
11
|
+
// await patchTableCore.apply(null, [...arguments, dryrun]);
|
|
12
|
+
return patchTableCore.apply(null, arguments);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function patchTableCore(table, patches, { strategy = undefined, deduceStrategy = false, ...options } = {}, dryrun) {
|
|
16
|
+
options = cleanOptions(options);
|
|
17
|
+
strategy = JSON.parse(JSON.stringify(strategy || {}));
|
|
18
|
+
let changed = new Set();
|
|
19
|
+
for (let i = 0; i < patches.length; i++) {
|
|
20
|
+
let patch = { path: undefined, value: undefined, op: undefined };
|
|
21
|
+
Object.assign(patch, patches[i]);
|
|
22
|
+
patch.path = patches[i].path.split('/').slice(1);
|
|
23
|
+
let result;
|
|
24
|
+
if (patch.op === 'add' || patch.op === 'replace') {
|
|
25
|
+
result = await add({ path: patch.path, value: patch.value, op: patch.op, oldValue: patch.oldValue, strategy: deduceStrategy ? strategy : {}, options }, table);
|
|
26
|
+
}
|
|
27
|
+
else if (patch.op === 'remove')
|
|
28
|
+
result = await remove({ path: patch.path, op: patch.op, oldValue: patch.oldValue, options }, table);
|
|
29
|
+
|
|
30
|
+
if (result.inserted)
|
|
31
|
+
changed.add(result.inserted);
|
|
32
|
+
else if (result.updated)
|
|
33
|
+
changed.add(result.updated);
|
|
34
|
+
}
|
|
35
|
+
if (strategy['insertAndForget'])
|
|
36
|
+
return {
|
|
37
|
+
changed: [], strategy
|
|
38
|
+
};
|
|
39
|
+
return { changed: await toDtos(changed), strategy };
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async function toDtos(set) {
|
|
43
|
+
set = [...set];
|
|
44
|
+
return table.getManyDto(set, strategy);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toKey(property) {
|
|
48
|
+
if (typeof property === 'string' && property.charAt(0) === '[')
|
|
49
|
+
return JSON.parse(property);
|
|
50
|
+
else
|
|
51
|
+
return [property];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function add({ path, value, op, oldValue, strategy, options }, table, row, parentRow, relation) {
|
|
55
|
+
let property = path[0];
|
|
56
|
+
path = path.slice(1);
|
|
57
|
+
if (!row && path.length > 0) {
|
|
58
|
+
const key = toKey(property);
|
|
59
|
+
row = await table.tryGetById.apply(null, toKey(property), strategy);
|
|
60
|
+
if (!row)
|
|
61
|
+
throw new Error(`Row ${table._dbName} with id ${key} was not found.`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (path.length === 0 && value === null) {
|
|
65
|
+
return remove({ path, op, oldValue, options }, table, row);
|
|
66
|
+
}
|
|
67
|
+
if (path.length === 0) {
|
|
68
|
+
if (dryrun) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
let childInserts = [];
|
|
72
|
+
for (let name in value) {
|
|
73
|
+
if (isColumn(name, table))
|
|
74
|
+
value[name] = fromCompareObject(value[name]);
|
|
75
|
+
else if (isJoinRelation(name, table)) {
|
|
76
|
+
strategy[name] = strategy[name] || {};
|
|
77
|
+
value[name] && updateJoinedColumns(name, value, table, value);
|
|
78
|
+
}
|
|
79
|
+
else if (isManyRelation(name, table))
|
|
80
|
+
value[name] && childInserts.push(insertManyRelation.bind(null, name, value, op, oldValue, table, strategy, options));
|
|
81
|
+
else if (isOneRelation(name, table) && value)
|
|
82
|
+
value[name] && childInserts.push(insertOneRelation.bind(null, name, value, op, oldValue, table, strategy, options));
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < table._primaryColumns.length; i++) {
|
|
85
|
+
let pkName = table._primaryColumns[i].alias;
|
|
86
|
+
let keyValue = value[pkName];
|
|
87
|
+
if (keyValue && typeof (keyValue) === 'string' && keyValue.indexOf('~') === 0)
|
|
88
|
+
value[pkName] = undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (relation && relation.joinRelation) {
|
|
92
|
+
for (let i = 0; i < relation.joinRelation.columns.length; i++) {
|
|
93
|
+
let column = relation.joinRelation.columns[i];
|
|
94
|
+
let fkName = column.alias;
|
|
95
|
+
let parentPk = relation.joinRelation.childTable._primaryColumns[i].alias;
|
|
96
|
+
if (!value[fkName]) {
|
|
97
|
+
value[fkName] = parentRow[parentPk];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let row = table.insertWithConcurrency.apply(null, [options, value]);
|
|
102
|
+
row = await row;
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < childInserts.length; i++) {
|
|
105
|
+
await childInserts[i](row);
|
|
106
|
+
}
|
|
107
|
+
return { inserted: row };
|
|
108
|
+
}
|
|
109
|
+
property = path[0];
|
|
110
|
+
if (isColumn(property, table)) {
|
|
111
|
+
if (dryrun)
|
|
112
|
+
return { updated: row };
|
|
113
|
+
let dto = {};
|
|
114
|
+
dto[property] = row[property];
|
|
115
|
+
let result = applyPatch({ options }, dto, [{ path: '/' + path.join('/'), op, value, oldValue }], table[property]);
|
|
116
|
+
row[property] = result[property];
|
|
117
|
+
return { updated: row };
|
|
118
|
+
}
|
|
119
|
+
else if (isOneRelation(property, table)) {
|
|
120
|
+
let relation = table[property]._relation;
|
|
121
|
+
let subRow = await row[property];
|
|
122
|
+
strategy[property] = strategy[property] || {};
|
|
123
|
+
options[property] = inferOptions(options, property);
|
|
124
|
+
|
|
125
|
+
await add({ path, value, op, oldValue, strategy: strategy[property], options: options[property] }, relation.childTable, subRow, row, relation);
|
|
126
|
+
return { updated: row };
|
|
127
|
+
}
|
|
128
|
+
else if (isManyRelation(property, table)) {
|
|
129
|
+
let relation = table[property]._relation;
|
|
130
|
+
strategy[property] = strategy[property] || {};
|
|
131
|
+
options[property] = inferOptions(options, property);
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if (path.length === 1) {
|
|
135
|
+
for (let id in value) {
|
|
136
|
+
if (id === '__patchType')
|
|
137
|
+
continue;
|
|
138
|
+
await add({ path: [id], value: value[id], op, oldValue, strategy: strategy[property], options: options[property] }, relation.childTable, undefined, row, relation);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
await add({ path: path.slice(1), value, oldValue, op, strategy: strategy[property], options: options[property] }, relation.childTable, undefined, row, relation);
|
|
143
|
+
}
|
|
144
|
+
return { updated: row };
|
|
145
|
+
}
|
|
146
|
+
else if (isJoinRelation(property, table) && path.length === 1) {
|
|
147
|
+
let dto = toJoinedColumns(property, { [property]: value }, table);
|
|
148
|
+
oldValue = toJoinedColumns(property, { [property]: oldValue }, table);
|
|
149
|
+
let result;
|
|
150
|
+
for (let p in dto) {
|
|
151
|
+
result = await add({ path: ['dummy', p], value: dto[p], oldValue: (oldValue || {})[p], op, strategy: strategy, options: options }, table, row, parentRow, relation) || result;
|
|
152
|
+
}
|
|
153
|
+
return result || {};
|
|
154
|
+
}
|
|
155
|
+
else if (isJoinRelation(property, table) && path.length === 2) {
|
|
156
|
+
let dto = toJoinedColumns(property, { [property]: { [path[1]]: value } }, table);
|
|
157
|
+
oldValue = toJoinedColumns(property, { [property]: { [path[1]]: oldValue } }, table);
|
|
158
|
+
let result;
|
|
159
|
+
for (let p in dto) {
|
|
160
|
+
result = await add({ path: ['dummy', p], value: dto[p], oldValue: (oldValue || {})[p], op, strategy: strategy, options: options }, table, row, parentRow, relation) || result;
|
|
161
|
+
}
|
|
162
|
+
return result || {};
|
|
163
|
+
}
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function insertManyRelation(name, value, op, oldValue, table, strategy, options, row) {
|
|
168
|
+
let relation = table[name]._relation;
|
|
169
|
+
for (let childKey in value[name]) {
|
|
170
|
+
if (childKey != '__patchType') {
|
|
171
|
+
let child = value[name][childKey];
|
|
172
|
+
strategy[name] = strategy[name] || {};
|
|
173
|
+
options[name] = inferOptions(options, name);
|
|
174
|
+
|
|
175
|
+
await add({ path: [childKey], value: child, op, oldValue, strategy: strategy[name], options: options[name] }, relation.childTable, {}, row, relation);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function insertOneRelation(name, value, op, oldValue, table, strategy, options, row) {
|
|
181
|
+
let relation = table[name]._relation;
|
|
182
|
+
let child = value[name];
|
|
183
|
+
strategy[name] = strategy[name] || {};
|
|
184
|
+
options[name] = inferOptions(options, name);
|
|
185
|
+
|
|
186
|
+
await add({ path: [name], value: child, op, oldValue, strategy: strategy[name], options: options[name] }, relation.childTable, {}, row, relation);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function updateJoinedColumns(name, value, table, row) {
|
|
190
|
+
let relation = table[name]._relation;
|
|
191
|
+
for (let i = 0; i < relation.columns.length; i++) {
|
|
192
|
+
let parentKey = relation.columns[i].alias;
|
|
193
|
+
let childKey = relation.childTable._primaryColumns[i].alias;
|
|
194
|
+
if (childKey in value[name])
|
|
195
|
+
row[parentKey] = fromCompareObject(value[name][childKey]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function toJoinedColumns(name, valueObject, table) {
|
|
199
|
+
let relation = table[name]._relation;
|
|
200
|
+
let dto = {};
|
|
201
|
+
for (let i = 0; i < relation.columns.length; i++) {
|
|
202
|
+
let parentKey = relation.columns[i].alias;
|
|
203
|
+
let childKey = relation.childTable._primaryColumns[i].alias;
|
|
204
|
+
if (valueObject && valueObject[name] && childKey in valueObject[name])
|
|
205
|
+
dto[parentKey] = fromCompareObject(valueObject[name][childKey]);
|
|
206
|
+
else
|
|
207
|
+
dto[parentKey] = null;
|
|
208
|
+
}
|
|
209
|
+
return dto;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function remove({ path, op, oldValue, options }, table, row) {
|
|
213
|
+
let property = path[0];
|
|
214
|
+
path = path.slice(1);
|
|
215
|
+
row = row || await table.getById.apply(null, toKey(property));
|
|
216
|
+
if (path.length === 0) {
|
|
217
|
+
await validateDeleteAllowed({ row, options, table });
|
|
218
|
+
if (await validateDeleteConflict({ row, oldValue, options, table }))
|
|
219
|
+
await row.deleteCascade();
|
|
220
|
+
}
|
|
221
|
+
property = path[0];
|
|
222
|
+
if (isColumn(property, table)) {
|
|
223
|
+
let dto = {};
|
|
224
|
+
dto[property] = row[property];
|
|
225
|
+
let result = applyPatch({ options }, dto, [{ path: '/' + path.join('/'), op, oldValue }], table[property]);
|
|
226
|
+
|
|
227
|
+
row[property] = result[property];
|
|
228
|
+
return { updated: row };
|
|
229
|
+
}
|
|
230
|
+
else if (isJoinRelation(property, table) && path.length === 1) {
|
|
231
|
+
oldValue = toJoinedColumns(property, { [property]: oldValue }, table);
|
|
232
|
+
let relation = table[property]._relation;
|
|
233
|
+
let result;
|
|
234
|
+
for (let i = 0; i < relation.columns.length; i++) {
|
|
235
|
+
let p = relation.columns[i].alias;
|
|
236
|
+
let dto = {};
|
|
237
|
+
dto[p] = row[p];
|
|
238
|
+
result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
|
|
239
|
+
}
|
|
240
|
+
return result || {};
|
|
241
|
+
}
|
|
242
|
+
else if (isJoinRelation(property, table) && path.length === 2) {
|
|
243
|
+
let relation = table[property]._relation;
|
|
244
|
+
oldValue = toJoinedColumns(property, { [property]: { [path[1]]: oldValue } }, table);
|
|
245
|
+
let result;
|
|
246
|
+
for (let i = 0; i < relation.columns.length; i++) {
|
|
247
|
+
let p = relation.columns[i].alias;
|
|
248
|
+
let childKey = relation.childTable._primaryColumns[i].alias;
|
|
249
|
+
if (path[1] === childKey) {
|
|
250
|
+
let dto = {};
|
|
251
|
+
dto[p] = row[p];
|
|
252
|
+
result = await remove({ path: ['dummy', p], oldValue: (oldValue || {})[p], op, options: options }, table, row) || result;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result || {};
|
|
257
|
+
}
|
|
258
|
+
else if (isOneRelation(property, table)) {
|
|
259
|
+
let child = await row[property];
|
|
260
|
+
if (!child)
|
|
261
|
+
throw new Error(property + ' does not exist');
|
|
262
|
+
options[property] = inferOptions(options, property);
|
|
263
|
+
|
|
264
|
+
await remove({ path, op, oldValue, options: options[property] }, table[property], child);
|
|
265
|
+
return { updated: row };
|
|
266
|
+
}
|
|
267
|
+
else if (isManyRelation(property, table)) {
|
|
268
|
+
let relation = table[property]._relation;
|
|
269
|
+
options[property] = inferOptions(options, property);
|
|
270
|
+
if (path.length === 1) {
|
|
271
|
+
let children = (await row[property]).slice(0);
|
|
272
|
+
for (let i = 0; i < children.length; i++) {
|
|
273
|
+
let child = children[i];
|
|
274
|
+
await remove({ path: path.slice(1), op, oldValue, options: options[property] }, table[property], child);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
await remove({ path: path.slice(1), op, oldValue, options: options[property] }, relation.childTable);
|
|
279
|
+
}
|
|
280
|
+
return { updated: row };
|
|
281
|
+
}
|
|
282
|
+
return {};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function isColumn(name, table) {
|
|
286
|
+
return table[name] && table[name].equal;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function isManyRelation(name, table) {
|
|
290
|
+
return table[name] && table[name]._relation.isMany;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function isOneRelation(name, table) {
|
|
294
|
+
return table[name] && table[name]._relation.isOne;
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function isJoinRelation(name, table) {
|
|
299
|
+
return table[name] && table[name]._relation.columns;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function inferOptions(defaults, property) {
|
|
303
|
+
const parent = {};
|
|
304
|
+
if ('readonly' in defaults)
|
|
305
|
+
parent.readonly = defaults.readonly;
|
|
306
|
+
if ('concurrency' in defaults)
|
|
307
|
+
parent.concurrency = defaults.concurrency;
|
|
308
|
+
return { ...parent, ...(defaults[property] || {}) };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function cleanOptions(options) {
|
|
312
|
+
const { table, transaction, db, ..._options } = options;
|
|
313
|
+
return _options;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
module.exports = patchTable;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function encode(arg) {
|
|
2
|
+
if (Array.isArray(arg))
|
|
3
|
+
return new JsonBArrayParam(arg);
|
|
4
|
+
else
|
|
5
|
+
return arg;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class JsonBArrayParam {
|
|
9
|
+
constructor(actualArray) { this.actualArray = actualArray; }
|
|
10
|
+
toPostgres() {
|
|
11
|
+
return JSON.stringify(this.actualArray);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = encode;
|