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,23 @@
|
|
|
1
|
+
var newSingleCommand = require('./delete/newSingleCommand');
|
|
2
|
+
|
|
3
|
+
var nextCommand = function() {
|
|
4
|
+
nextCommand = require('./newDeleteCommand');
|
|
5
|
+
nextCommand.apply(null, arguments);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function newCommand(queries,table,filter,strategy,relations) {
|
|
9
|
+
var singleCommand = newSingleCommand(table,filter,relations);
|
|
10
|
+
for(var name in strategy) {
|
|
11
|
+
if (!(strategy[name] === null || strategy[name]))
|
|
12
|
+
continue;
|
|
13
|
+
var childStrategy = strategy[name];
|
|
14
|
+
var childRelation = table._relations[name];
|
|
15
|
+
var joinRelation = childRelation.joinRelation;
|
|
16
|
+
var childRelations = [joinRelation].concat(relations);
|
|
17
|
+
nextCommand(queries,childRelation.childTable,filter,childStrategy,childRelations);
|
|
18
|
+
}
|
|
19
|
+
queries.push(singleCommand);
|
|
20
|
+
return queries;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = newCommand;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var newGetLastInsertedCommandCore = require('./newGetLastInsertedCommandCore');
|
|
2
|
+
var newImmutable = require('../../newImmutable');
|
|
3
|
+
|
|
4
|
+
function newGetLastInsertedCommand(table, row, insertCommand) {
|
|
5
|
+
let cmd = new InsertCommand(table, row, insertCommand);
|
|
6
|
+
insertCommand.endEdit = () => {};
|
|
7
|
+
return cmd;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function InsertCommand(table, row, insertCommand) {
|
|
11
|
+
this._insertCommand = insertCommand;
|
|
12
|
+
this.__getCoreCommand = newImmutable(newGetLastInsertedCommandCore);
|
|
13
|
+
this._table = table;
|
|
14
|
+
this._row = row;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
InsertCommand.prototype._getCoreCommand = function() {
|
|
18
|
+
return this.__getCoreCommand(this._table, this._row);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
InsertCommand.prototype.sql = function() {
|
|
22
|
+
return this._getCoreCommand().sql();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
InsertCommand.prototype.matches = function(otherRow) {
|
|
26
|
+
return this._row === otherRow;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
InsertCommand.prototype.endEdit = function() {
|
|
31
|
+
this._insertCommand.endEdit();
|
|
32
|
+
this.sql();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Object.defineProperty(InsertCommand.prototype, 'parameters', {
|
|
36
|
+
get: function() {
|
|
37
|
+
return this._getCoreCommand().parameters;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
|
|
43
|
+
get: function() {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
module.exports = newGetLastInsertedCommand;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let newParameterized = require('../query/newParameterized');
|
|
2
|
+
let getSessionContext = require('../getSessionContext');
|
|
3
|
+
|
|
4
|
+
function newGetLastInsertedCommandCore(table, row) {
|
|
5
|
+
let parameters = [];
|
|
6
|
+
let keyValues = table._primaryColumns.map(column => row['__' + column.alias]);
|
|
7
|
+
let sql = `SELECT ${columnNames()} FROM ${table._dbName} WHERE ${whereSql()}`;
|
|
8
|
+
return newParameterized(sql, parameters);
|
|
9
|
+
|
|
10
|
+
function columnNames() {
|
|
11
|
+
return table._columns.map(col => col._dbName).join(',');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function whereSql() {
|
|
15
|
+
let parameterized;
|
|
16
|
+
let filter = getSessionContext().lastInsertedSql(table, keyValues);
|
|
17
|
+
if (Array.isArray(filter)) {
|
|
18
|
+
for (let i = 0; i < filter.length; i++) {
|
|
19
|
+
const sep = i === 0 ? '' : ' AND ';
|
|
20
|
+
if (!filter[i].sql) {
|
|
21
|
+
const sql = filter[i];
|
|
22
|
+
filter[i] = {sql : () => sql};
|
|
23
|
+
}
|
|
24
|
+
let next = newParameterized(sep + filter[i].sql(), filter[i].parameters);
|
|
25
|
+
if (parameterized)
|
|
26
|
+
parameterized = parameterized.append(next);
|
|
27
|
+
else
|
|
28
|
+
parameterized = next;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
parameterized = newParameterized(filter);
|
|
33
|
+
parameters = parameters.concat(parameterized.parameters);
|
|
34
|
+
return [discriminators(), parameterized.sql()].filter(x => x).join(' AND ');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function discriminators() {
|
|
38
|
+
return table._columnDiscriminators.join(',');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = newGetLastInsertedCommandCore;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var newInsertCommandCore = require('./newInsertCommandCore');
|
|
2
|
+
var newImmutable = require('../../newImmutable');
|
|
3
|
+
var createPatch = require('../../client/createPatch');
|
|
4
|
+
var createDto = require('../resultToRows/toDto/createDto');
|
|
5
|
+
|
|
6
|
+
function newInsertCommand(table, row, options) {
|
|
7
|
+
return new InsertCommand(table, row, options);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function InsertCommand(table, row) {
|
|
11
|
+
this.__getCoreCommand = newImmutable(newInsertCommandCore);
|
|
12
|
+
this._table = table;
|
|
13
|
+
this._row = row;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
InsertCommand.prototype._getCoreCommand = function() {
|
|
17
|
+
return this.__getCoreCommand(this._table, this._row);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
InsertCommand.prototype.sql = function() {
|
|
21
|
+
return this._getCoreCommand().sql();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
InsertCommand.prototype.matches = function(otherRow) {
|
|
25
|
+
return this._row === otherRow;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
InsertCommand.prototype.endEdit = function() {
|
|
30
|
+
this.sql();
|
|
31
|
+
var dto = createDto(this._table, this._row);
|
|
32
|
+
if (this._table._emitChanged.callbacks.length > 0)
|
|
33
|
+
this._patch = createPatch([], [dto]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
InsertCommand.prototype.emitChanged = function() {
|
|
37
|
+
return this._table._emitChanged({row: this._row, patch: this._patch});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Object.defineProperty(InsertCommand.prototype, 'parameters', {
|
|
41
|
+
get: function() {
|
|
42
|
+
return this._getCoreCommand().parameters;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
|
|
48
|
+
get: function() {
|
|
49
|
+
return this._table._emitChanged.callbacks.length > 0;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
module.exports = newInsertCommand;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// var newInsertCommandCore = require('./newInsertCommandCore');
|
|
2
|
+
var newImmutable = require('../../newImmutable');
|
|
3
|
+
var createPatch = require('../../client/createPatch');
|
|
4
|
+
var createDto = require('../resultToRows/toDto/createDto');
|
|
5
|
+
|
|
6
|
+
function newInsertCommand(newInsertCommandCore, table, row, options) {
|
|
7
|
+
return new InsertCommand(newInsertCommandCore, table, row, options);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function InsertCommand(newInsertCommandCore, table, row, options) {
|
|
11
|
+
this.__getCoreCommand = newImmutable(newInsertCommandCore);
|
|
12
|
+
this._table = table;
|
|
13
|
+
this._row = row;
|
|
14
|
+
this._options = options;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
InsertCommand.prototype._getCoreCommand = function() {
|
|
18
|
+
return this.__getCoreCommand(this._table, this._row, this._options);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
InsertCommand.prototype.sql = function() {
|
|
22
|
+
return this._getCoreCommand().sql();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
InsertCommand.prototype.matches = function(otherRow) {
|
|
26
|
+
return this._row === otherRow;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
InsertCommand.prototype.endEdit = function() {
|
|
31
|
+
this.sql();
|
|
32
|
+
var dto = createDto(this._table, this._row);
|
|
33
|
+
if (this._table._emitChanged.callbacks.length > 0)
|
|
34
|
+
this._patch = createPatch([], [dto]);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
InsertCommand.prototype.emitChanged = function() {
|
|
38
|
+
return this._table._emitChanged({row: this._row, patch: this._patch});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(InsertCommand.prototype, 'parameters', {
|
|
42
|
+
get: function() {
|
|
43
|
+
return this._getCoreCommand().parameters;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
Object.defineProperty(InsertCommand.prototype, 'disallowCompress', {
|
|
49
|
+
get: function() {
|
|
50
|
+
return this._table._emitChanged.callbacks.length > 0;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
module.exports = newInsertCommand;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var newParameterized = require('../query/newParameterized');
|
|
2
|
+
var getSqlTemplate = require('./insert/getSqlTemplate');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
function newInsertCommandCore(table, row, options = {}) {
|
|
6
|
+
var parameters = [];
|
|
7
|
+
var values = [getSqlTemplate(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,51 @@
|
|
|
1
|
+
var decodeDbRow = require('../resultToRows/decodeDbRow');
|
|
2
|
+
var flags = require('../../flags');
|
|
3
|
+
|
|
4
|
+
function newRow({table, _options}) {
|
|
5
|
+
var dto = {};
|
|
6
|
+
table._columns.forEach(addColumn);
|
|
7
|
+
|
|
8
|
+
function addColumn(column) {
|
|
9
|
+
var alias = column.alias;
|
|
10
|
+
if ('default' in column) {
|
|
11
|
+
if (typeof column.default === 'function')
|
|
12
|
+
dto[alias] = column.default();
|
|
13
|
+
else if (column.toDto)
|
|
14
|
+
dto[alias] = column.toDto(column.default);
|
|
15
|
+
else
|
|
16
|
+
dto[alias] = column.default;
|
|
17
|
+
}
|
|
18
|
+
else if (flags.useLazyDefaults && 'lazyDefault' in column && !column.isPrimary) {
|
|
19
|
+
if (typeof column.lazyDefault === 'function')
|
|
20
|
+
dto[alias] = column.lazyDefault();
|
|
21
|
+
else if (column.toDto)
|
|
22
|
+
dto[alias] = column.toDto(column.lazyDefault);
|
|
23
|
+
else
|
|
24
|
+
dto[alias] = column.lazyDefault;
|
|
25
|
+
}
|
|
26
|
+
else if (column.dbNull !== null)
|
|
27
|
+
dto[alias] = null;
|
|
28
|
+
else
|
|
29
|
+
dto[alias] = undefined;
|
|
30
|
+
}
|
|
31
|
+
const arg = arguments[1];
|
|
32
|
+
if (isObject(arg))
|
|
33
|
+
for (let name in arg) {
|
|
34
|
+
if (table[name] && table[name].equal)
|
|
35
|
+
dto[name] = arg[name];
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
39
|
+
var pkValue = arguments[i];
|
|
40
|
+
var column = table._primaryColumns[i - 1];
|
|
41
|
+
dto[column.alias] = pkValue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return decodeDbRow(table, table, dto, true, true);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isObject(object) {
|
|
48
|
+
return (object === Object(object) && !Array.isArray(object) && !(object instanceof Date));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = newRow;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
let newUpdateCommandCore = require('./newUpdateCommandCore');
|
|
2
|
+
let newImmutable = require('../../newImmutable');
|
|
3
|
+
let newColumnList = require('../../newObject');
|
|
4
|
+
var createPatch = require('../../client/createPatch');
|
|
5
|
+
let createDto = require('../resultToRows/toDto/createDto');
|
|
6
|
+
|
|
7
|
+
function newUpdateCommand(table, column, row) {
|
|
8
|
+
return new UpdateCommand(table, column, row);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function UpdateCommand(table, column, row) {
|
|
12
|
+
this._table = table;
|
|
13
|
+
this._row = row;
|
|
14
|
+
this.__getCoreCommand = newImmutable(newUpdateCommandCore);
|
|
15
|
+
this._columnList = newColumnList();
|
|
16
|
+
this._columnList[column.alias] = column;
|
|
17
|
+
this.onFieldChanged = this.onFieldChanged.bind(this);
|
|
18
|
+
row.subscribeChanged(this.onFieldChanged);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
UpdateCommand.prototype.onFieldChanged = function(_row, column) {
|
|
22
|
+
this._columnList[column.alias] = column;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
UpdateCommand.prototype.sql = function() {
|
|
26
|
+
return this._getCoreCommand().sql();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
Object.defineProperty(UpdateCommand.prototype, 'parameters', {
|
|
30
|
+
get: function() {
|
|
31
|
+
return this._getCoreCommand().parameters;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
UpdateCommand.prototype._getCoreCommand = function() {
|
|
36
|
+
return this.__getCoreCommand(this._table, this._columnList, this._row);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
UpdateCommand.prototype.endEdit = function() {
|
|
40
|
+
this._getCoreCommand();
|
|
41
|
+
this._row.unsubscribeChanged(this.onFieldChanged);
|
|
42
|
+
let dto = JSON.parse(JSON.stringify(createDto(this._table, this._row)));
|
|
43
|
+
this._patch = createPatch([JSON.parse(this._row._oldValues)],[dto]);
|
|
44
|
+
this._row._oldValues = JSON.stringify(dto);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
UpdateCommand.prototype.emitChanged = function() {
|
|
48
|
+
return this._table._emitChanged({row: this._row, patch: this._patch});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
UpdateCommand.prototype.matches = function(otherRow) {
|
|
52
|
+
return this._row === otherRow;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Object.defineProperty(UpdateCommand.prototype, 'disallowCompress', {
|
|
56
|
+
get: function() {
|
|
57
|
+
return this._table._emitChanged.callbacks.length > 0;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
module.exports = newUpdateCommand;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var newParameterized = require('../query/newParameterized');
|
|
2
|
+
|
|
3
|
+
function newUpdateCommandCore(table, columns, row) {
|
|
4
|
+
var command = newParameterized('UPDATE ' + table._dbName + ' SET');
|
|
5
|
+
var separator = ' ';
|
|
6
|
+
|
|
7
|
+
addColumns();
|
|
8
|
+
addWhereId();
|
|
9
|
+
addDiscriminators();
|
|
10
|
+
|
|
11
|
+
function addColumns() {
|
|
12
|
+
for (var alias in columns) {
|
|
13
|
+
var column = columns[alias];
|
|
14
|
+
var encoded = column.encode(row[alias]);
|
|
15
|
+
command = command.append(separator + column._dbName + '=').append(encoded);
|
|
16
|
+
separator = ',';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function addWhereId() {
|
|
21
|
+
separator = ' WHERE ';
|
|
22
|
+
var columns = table._primaryColumns;
|
|
23
|
+
for (var i = 0; i < columns.length; i++) {
|
|
24
|
+
var column = columns[i];
|
|
25
|
+
var value = row[column.alias];
|
|
26
|
+
var encoded = column.encode(value);
|
|
27
|
+
command = command.append(separator + column._dbName + '=').append(encoded);
|
|
28
|
+
separator = ' AND ';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function addDiscriminators() {
|
|
33
|
+
var discriminators = table._columnDiscriminators;
|
|
34
|
+
if (discriminators.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
discriminators = separator + discriminators.join(' AND ');
|
|
37
|
+
command = command.append(discriminators);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return command;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = newUpdateCommandCore;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var getChangeSet = require('./getChangeSet');
|
|
2
|
+
var negotiateEndEdit = require('./negotiateEndEdit');
|
|
3
|
+
|
|
4
|
+
function pushCommand(command) {
|
|
5
|
+
var changes = getChangeSet();
|
|
6
|
+
negotiateEndEdit(changes);
|
|
7
|
+
changes.push(command);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
module.exports = pushCommand;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var newParameterized = require('../query/newParameterized');
|
|
2
|
+
|
|
3
|
+
var command = newParameterized('ROLLBACK');
|
|
4
|
+
function empty() {}
|
|
5
|
+
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
command.endEdit = empty;
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
command.matches = empty;
|
|
10
|
+
|
|
11
|
+
module.exports = command;
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
let commitCommand = require('./commands/commitCommand');
|
|
2
|
+
let pushCommand = require('./commands/pushCommand');
|
|
3
|
+
let executeChanges = require('./executeQueries/executeChanges');
|
|
4
|
+
let releaseDbClient = require('./releaseDbClient');
|
|
5
|
+
let popChanges = require('./popChanges');
|
|
6
|
+
|
|
7
|
+
function commit(result) {
|
|
8
|
+
return popAndPushChanges()
|
|
9
|
+
.then(releaseDbClient)
|
|
10
|
+
.then(onReleased);
|
|
11
|
+
|
|
12
|
+
function onReleased() {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function popAndPushChanges() {
|
|
17
|
+
let changes = popChanges();
|
|
18
|
+
while (changes.length > 0) {
|
|
19
|
+
await executeChanges(changes);
|
|
20
|
+
changes = popChanges();
|
|
21
|
+
}
|
|
22
|
+
pushCommand(commitCommand);
|
|
23
|
+
return executeChanges(popChanges());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = function(result) {
|
|
28
|
+
return Promise.resolve()
|
|
29
|
+
.then(() => commit(result));
|
|
30
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const executeQueries = require('./executeQueries');
|
|
2
|
+
const negotiateRawSqlFilter = require('./column/negotiateRawSqlFilter');
|
|
3
|
+
const extractFilter = require('./query/extractFilter');
|
|
4
|
+
const newWhereSql = require('./query/singleQuery/newWhereSql');
|
|
5
|
+
|
|
6
|
+
async function count(table, filter) {
|
|
7
|
+
let alias = table._dbName;
|
|
8
|
+
filter = negotiateRawSqlFilter(filter, table);
|
|
9
|
+
let query = newQuery(table, filter, alias);
|
|
10
|
+
let allResults = await executeQueries([query]);
|
|
11
|
+
let count = await allResults[0].then((rows) => {
|
|
12
|
+
|
|
13
|
+
const count = Number.parseInt(rows[0]._count);
|
|
14
|
+
return count;
|
|
15
|
+
});
|
|
16
|
+
return count;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function newQuery(table, filter, alias) {
|
|
20
|
+
filter = extractFilter(filter);
|
|
21
|
+
var name = table._dbName;
|
|
22
|
+
var whereSql = newWhereSql(table, filter, alias);
|
|
23
|
+
|
|
24
|
+
return whereSql.prepend('select count(*) "_count" from ' + name + ' ' + alias);
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = count;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var createJSONReadStreamDefault = require('./createJSONReadStreamDefault');
|
|
2
|
+
|
|
3
|
+
function createJSONReadStream(table, db, filter, strategy, streamOptions) {
|
|
4
|
+
return createJSONReadStreamDefault(table, db, filter, strategy, streamOptions);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports = createJSONReadStream;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var createReadStreamCore = require('./createReadStreamDefault');
|
|
2
|
+
var Stream = require('stream');
|
|
3
|
+
|
|
4
|
+
function createJSONReadStream(table, db, filter, strategy, streamOptions) {
|
|
5
|
+
var transformer = Stream.Transform({ objectMode: true });
|
|
6
|
+
var started;
|
|
7
|
+
transformer._transform = function(obj, enc, cb) {
|
|
8
|
+
var data = JSON.stringify(obj);
|
|
9
|
+
if (started)
|
|
10
|
+
transformer.push(',' + data);
|
|
11
|
+
else {
|
|
12
|
+
transformer.push('[');
|
|
13
|
+
transformer.push(data);
|
|
14
|
+
started = true;
|
|
15
|
+
}
|
|
16
|
+
cb();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
transformer._flush = function(cb) {
|
|
20
|
+
transformer.push(']');
|
|
21
|
+
cb();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var objectStream = createReadStreamCore(table, db, filter, strategy, streamOptions);
|
|
25
|
+
objectStream.on('error', onError);
|
|
26
|
+
return objectStream.pipe(transformer);
|
|
27
|
+
|
|
28
|
+
function onError(e) {
|
|
29
|
+
transformer.emit('error', e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = createJSONReadStream;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var createReadStreamCore = require('./createReadStreamCoreNative');
|
|
2
|
+
var Stream = require('stream');
|
|
3
|
+
|
|
4
|
+
function createJSONReadStream(table, db, filter, strategy, streamOptions) {
|
|
5
|
+
var transformer = Stream.Transform({
|
|
6
|
+
objectMode: true
|
|
7
|
+
});
|
|
8
|
+
var started;
|
|
9
|
+
transformer._transform = function(chunk, enc, cb) {
|
|
10
|
+
if (started)
|
|
11
|
+
transformer.push(',' + chunk.result);
|
|
12
|
+
else {
|
|
13
|
+
transformer.push('[');
|
|
14
|
+
let result = chunk.result;
|
|
15
|
+
if (typeof result === 'object')
|
|
16
|
+
result = JSON.stringify(result);
|
|
17
|
+
transformer.push(result);
|
|
18
|
+
started = true;
|
|
19
|
+
}
|
|
20
|
+
cb();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
transformer._flush = function(cb) {
|
|
24
|
+
transformer.push(']');
|
|
25
|
+
cb();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return createReadStreamCore(table, db, filter, strategy, transformer, streamOptions);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = createJSONReadStream;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var createReadStreamNative = require('./createReadStreamNative');
|
|
2
|
+
var createReadStreamDefault = require('./createReadStreamDefault');
|
|
3
|
+
|
|
4
|
+
function createReadStream(table, db, filter, strategy, streamOptions) {
|
|
5
|
+
var create;
|
|
6
|
+
var c = {};
|
|
7
|
+
|
|
8
|
+
c.visitPg = function() {
|
|
9
|
+
create = createReadStreamNative;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
c.visitMySql = c.visitPg;
|
|
13
|
+
|
|
14
|
+
c.visitSqlite = function() {
|
|
15
|
+
create = createReadStreamDefault;
|
|
16
|
+
};
|
|
17
|
+
c.visitSap = c.visitSqlite;
|
|
18
|
+
|
|
19
|
+
db.accept(c);
|
|
20
|
+
|
|
21
|
+
return create(table, db, filter, strategy, streamOptions);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = createReadStream;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var newQuery = require('./readStream/newQuery');
|
|
2
|
+
var strategyToSpan = require('./strategyToSpan');
|
|
3
|
+
var negotiateRawSqlFilter = require('./column/negotiateRawSqlFilter');
|
|
4
|
+
var newQueryStream = require('./readStream/newQueryStream');
|
|
5
|
+
|
|
6
|
+
function createReadStreamCoreNative(table, db, filter, strategy, transformer, streamOptions) {
|
|
7
|
+
var alias = table._dbName;
|
|
8
|
+
filter = negotiateRawSqlFilter(filter, table);
|
|
9
|
+
var span = strategyToSpan(table, strategy);
|
|
10
|
+
|
|
11
|
+
if (process.domain)
|
|
12
|
+
process.domain.add(transformer);
|
|
13
|
+
|
|
14
|
+
db.transaction(async () => {
|
|
15
|
+
await start();
|
|
16
|
+
}).then(null, onError);
|
|
17
|
+
|
|
18
|
+
function start() {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var query = newQuery(db, table, filter, span, alias);
|
|
21
|
+
var queryStream = newQueryStream(query, streamOptions);
|
|
22
|
+
queryStream.on('end', resolve);
|
|
23
|
+
queryStream.on('error', onStreamError);
|
|
24
|
+
queryStream.pipe(transformer);
|
|
25
|
+
|
|
26
|
+
function onStreamError(e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function onError(e) {
|
|
34
|
+
transformer.emit('error', e);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return transformer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = createReadStreamCoreNative;
|