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,641 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
//Taken from https://raw.githubusercontent.com/coopernurse/node-pool/6c98fa9163bbe35b683ffc2b55ac741d02956096/lib/generic-pool.js
|
|
5
|
+
//Version 3 of generic-pool has lots og bugs and node program will never finish.
|
|
6
|
+
//So I copied version 2.5.4 below
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
function PriorityQueue(size) {
|
|
13
|
+
if (!(this instanceof PriorityQueue)) {
|
|
14
|
+
return new PriorityQueue();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this._size = size;
|
|
18
|
+
this._slots = null;
|
|
19
|
+
this._total = null;
|
|
20
|
+
|
|
21
|
+
// initialize arrays to hold queue elements
|
|
22
|
+
size = Math.max(+size | 0, 1);
|
|
23
|
+
this._slots = [];
|
|
24
|
+
for (var i = 0; i < size; i += 1) {
|
|
25
|
+
this._slots.push([]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
PriorityQueue.prototype.size = function size() {
|
|
30
|
+
if (this._total === null) {
|
|
31
|
+
this._total = 0;
|
|
32
|
+
for (var i = 0; i < this._size; i += 1) {
|
|
33
|
+
this._total += this._slots[i].length;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return this._total;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
PriorityQueue.prototype.enqueue = function enqueue(obj, priority) {
|
|
40
|
+
var priorityOrig;
|
|
41
|
+
|
|
42
|
+
// Convert to integer with a default value of 0.
|
|
43
|
+
priority = priority && +priority | 0 || 0;
|
|
44
|
+
|
|
45
|
+
// Clear cache for total.
|
|
46
|
+
this._total = null;
|
|
47
|
+
if (priority) {
|
|
48
|
+
priorityOrig = priority;
|
|
49
|
+
if (priority < 0 || priority >= this._size) {
|
|
50
|
+
priority = (this._size - 1);
|
|
51
|
+
// put obj at the end of the line
|
|
52
|
+
console.error('invalid priority: ' + priorityOrig + ' must be between 0 and ' + priority);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this._slots[priority].push(obj);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
PriorityQueue.prototype.dequeue = function dequeue(_callback) {
|
|
60
|
+
var obj = null;
|
|
61
|
+
// Clear cache for total.
|
|
62
|
+
this._total = null;
|
|
63
|
+
for (var i = 0, sl = this._slots.length; i < sl; i += 1) {
|
|
64
|
+
if (this._slots[i].length) {
|
|
65
|
+
obj = this._slots[i].shift();
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function doWhileAsync(conditionFn, iterateFn, callbackFn) {
|
|
73
|
+
var next = function() {
|
|
74
|
+
if (conditionFn()) {
|
|
75
|
+
iterateFn(next);
|
|
76
|
+
} else {
|
|
77
|
+
callbackFn();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
next();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generate an Object pool with a specified `factory`.
|
|
85
|
+
*
|
|
86
|
+
* @class
|
|
87
|
+
* @param {Object} factory
|
|
88
|
+
* Factory to be used for generating and destorying the items.
|
|
89
|
+
* @param {String} factory.name
|
|
90
|
+
* Name of the factory. Serves only logging purposes.
|
|
91
|
+
* @param {Function} factory.create
|
|
92
|
+
* Should create the item to be acquired,
|
|
93
|
+
* and call it's first callback argument with the generated item as it's argument.
|
|
94
|
+
* @param {Function} factory.destroy
|
|
95
|
+
* Should gently close any resources that the item is using.
|
|
96
|
+
* Called before the items is destroyed.
|
|
97
|
+
* @param {Function} factory.validate
|
|
98
|
+
* Should return true if connection is still valid and false
|
|
99
|
+
* If it should be removed from pool. Called before item is
|
|
100
|
+
* acquired from pool.
|
|
101
|
+
* @param {Function} factory.validateAsync
|
|
102
|
+
* Asynchronous validate function. Receives a callback function
|
|
103
|
+
* as its second argument, that should be called with a single
|
|
104
|
+
* boolean argument being true if the item is still valid and false
|
|
105
|
+
* if it should be removed from pool. Called before item is
|
|
106
|
+
* acquired from pool. Only one of validate/validateAsync may be specified
|
|
107
|
+
* @param {Number} factory.max
|
|
108
|
+
* Maximum number of items that can exist at the same time. Default: 1.
|
|
109
|
+
* Any further acquire requests will be pushed to the waiting list.
|
|
110
|
+
* @param {Number} factory.min
|
|
111
|
+
* Minimum number of items in pool (including in-use). Default: 0.
|
|
112
|
+
* When the pool is created, or a resource destroyed, this minimum will
|
|
113
|
+
* be checked. If the pool resource count is below the minimum, a new
|
|
114
|
+
* resource will be created and added to the pool.
|
|
115
|
+
* @param {Number} factory.idleTimeoutMillis
|
|
116
|
+
* Delay in milliseconds after the idle items in the pool will be destroyed.
|
|
117
|
+
* And idle item is that is not acquired yet. Waiting items doesn't count here.
|
|
118
|
+
* @param {Number} factory.reapIntervalMillis
|
|
119
|
+
* Cleanup is scheduled in every `factory.reapIntervalMillis` milliseconds.
|
|
120
|
+
* @param {Boolean|Function} factory.log
|
|
121
|
+
* Whether the pool should log activity. If function is specified,
|
|
122
|
+
* that will be used instead. The function expects the arguments msg, loglevel
|
|
123
|
+
* @param {Number} factory.priorityRange
|
|
124
|
+
* The range from 1 to be treated as a valid priority
|
|
125
|
+
* @param {RefreshIdle} factory.refreshIdle
|
|
126
|
+
* Should idle resources at or below the min threshold be destroyed and recreated every idleTimeoutMillis? Default: true.
|
|
127
|
+
* @param {Bool} [factory.returnToHead=false]
|
|
128
|
+
* Returns released object to head of available objects list
|
|
129
|
+
*/
|
|
130
|
+
function Pool(factory) {
|
|
131
|
+
if (!(this instanceof Pool)) {
|
|
132
|
+
return new Pool(factory);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (factory.validate && factory.validateAsync) {
|
|
136
|
+
throw new Error('Only one of validate or validateAsync may be specified');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// defaults
|
|
140
|
+
factory.idleTimeoutMillis = factory.idleTimeoutMillis || 30000;
|
|
141
|
+
factory.returnToHead = factory.returnToHead || false;
|
|
142
|
+
factory.refreshIdle = ('refreshIdle' in factory) ? factory.refreshIdle : true;
|
|
143
|
+
factory.reapInterval = factory.reapIntervalMillis || 1000;
|
|
144
|
+
factory.priorityRange = factory.priorityRange || 1;
|
|
145
|
+
factory.validate = factory.validate || function() {
|
|
146
|
+
return true;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
factory.max = parseInt(factory.max, 10);
|
|
150
|
+
factory.min = parseInt(factory.min, 10);
|
|
151
|
+
|
|
152
|
+
factory.max = Math.max(isNaN(factory.max) ? 1 : factory.max, 1);
|
|
153
|
+
factory.min = Math.min(isNaN(factory.min) ? 0 : factory.min, factory.max - 1);
|
|
154
|
+
|
|
155
|
+
this._factory = factory;
|
|
156
|
+
this._inUseObjects = [];
|
|
157
|
+
this._draining = false;
|
|
158
|
+
this._waitingClients = new PriorityQueue(factory.priorityRange);
|
|
159
|
+
this._availableObjects = [];
|
|
160
|
+
this._asyncTestObjects = [];
|
|
161
|
+
this._count = 0;
|
|
162
|
+
this._removeIdleTimer = null;
|
|
163
|
+
this._removeIdleScheduled = false;
|
|
164
|
+
|
|
165
|
+
// create initial resources (if factory.min > 0)
|
|
166
|
+
this._ensureMinimum();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* logs to console or user defined log function
|
|
171
|
+
* @private
|
|
172
|
+
* @param {string} str
|
|
173
|
+
* @param {string} level
|
|
174
|
+
*/
|
|
175
|
+
Pool.prototype._log = function log(str, level) {
|
|
176
|
+
if (typeof this._factory.log === 'function') {
|
|
177
|
+
this._factory.log(str, level);
|
|
178
|
+
} else if (this._factory.log) {
|
|
179
|
+
console.log(level.toUpperCase() + ' pool ' + this._factory.name + ' - ' + str);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Request the client to be destroyed. The factory's destroy handler
|
|
185
|
+
* will also be called.
|
|
186
|
+
*
|
|
187
|
+
* This should be called within an acquire() block as an alternative to release().
|
|
188
|
+
*
|
|
189
|
+
* @param {Object} obj
|
|
190
|
+
* The acquired item to be destoyed.
|
|
191
|
+
* @param {Function} callback
|
|
192
|
+
* Optional. Callback invoked after client is destroyed
|
|
193
|
+
*/
|
|
194
|
+
Pool.prototype.destroy = function destroy(obj, cb) {
|
|
195
|
+
this._count -= 1;
|
|
196
|
+
if (this._count < 0) this._count = 0;
|
|
197
|
+
this._availableObjects = this._availableObjects.filter(function(objWithTimeout) {
|
|
198
|
+
return (objWithTimeout.obj !== obj);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
this._inUseObjects = this._inUseObjects.filter(function(objInUse) {
|
|
202
|
+
return (objInUse !== obj);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
this._factory.destroy(obj, cb);
|
|
206
|
+
|
|
207
|
+
// keep compatibily with old interface
|
|
208
|
+
if (this._factory.destroy.length === 1 && cb && typeof cb === 'function') {
|
|
209
|
+
cb();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
this._ensureMinimum();
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Checks and removes the available (idle) clients that have timed out.
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
Pool.prototype._removeIdle = function removeIdle() {
|
|
220
|
+
var toRemove = [];
|
|
221
|
+
var now = new Date().getTime();
|
|
222
|
+
var i;
|
|
223
|
+
var al = this._availableObjects.length;
|
|
224
|
+
var refreshIdle = this._factory.refreshIdle;
|
|
225
|
+
var maxRemovable = this._count - this._factory.min;
|
|
226
|
+
var timeout;
|
|
227
|
+
|
|
228
|
+
this._removeIdleScheduled = false;
|
|
229
|
+
|
|
230
|
+
// Go through the available (idle) items,
|
|
231
|
+
// check if they have timed out
|
|
232
|
+
for (i = 0; i < al && (refreshIdle || (maxRemovable > toRemove.length)); i++) {
|
|
233
|
+
timeout = this._availableObjects[i].timeout;
|
|
234
|
+
if (now >= timeout) {
|
|
235
|
+
// Client timed out, so destroy it.
|
|
236
|
+
this._log('removeIdle() destroying obj - now:' + now + ' timeout:' + timeout, 'verbose');
|
|
237
|
+
toRemove.push(this._availableObjects[i].obj);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
toRemove.forEach(this.destroy, this);
|
|
242
|
+
|
|
243
|
+
// NOTE: we are re-calcing this value because it may have changed
|
|
244
|
+
// after destroying items above
|
|
245
|
+
// Replace the available items with the ones to keep.
|
|
246
|
+
al = this._availableObjects.length;
|
|
247
|
+
|
|
248
|
+
if (al > 0) {
|
|
249
|
+
this._log('this._availableObjects.length=' + al, 'verbose');
|
|
250
|
+
this._scheduleRemoveIdle();
|
|
251
|
+
} else {
|
|
252
|
+
this._log('removeIdle() all objects removed', 'verbose');
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Schedule removal of idle items in the pool.
|
|
258
|
+
*
|
|
259
|
+
* More schedules cannot run concurrently.
|
|
260
|
+
*/
|
|
261
|
+
Pool.prototype._scheduleRemoveIdle = function scheduleRemoveIdle() {
|
|
262
|
+
var self = this;
|
|
263
|
+
if (!this._removeIdleScheduled) {
|
|
264
|
+
this._removeIdleScheduled = true;
|
|
265
|
+
this._removeIdleTimer = setTimeout(function() {
|
|
266
|
+
self._removeIdle();
|
|
267
|
+
}, this._factory.reapInterval);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Try to get a new client to work, and clean up pool unused (idle) items.
|
|
273
|
+
*
|
|
274
|
+
* - If there are available clients waiting, shift the first one out (LIFO),
|
|
275
|
+
* and call its callback.
|
|
276
|
+
* - If there are no waiting clients, try to create one if it won't exceed
|
|
277
|
+
* the maximum number of clients.
|
|
278
|
+
* - If creating a new client would exceed the maximum, add the client to
|
|
279
|
+
* the wait list.
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
Pool.prototype._dispense = function dispense() {
|
|
283
|
+
var self = this;
|
|
284
|
+
var objWithTimeout = null;
|
|
285
|
+
var clientCb = null;
|
|
286
|
+
var waitingCount = this._waitingClients.size();
|
|
287
|
+
|
|
288
|
+
this._log('dispense() clients=' + waitingCount + ' available=' + this._availableObjects.length, 'info');
|
|
289
|
+
|
|
290
|
+
if (waitingCount < 1) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (this._factory.validateAsync) {
|
|
295
|
+
doWhileAsync(function() {
|
|
296
|
+
return self._availableObjects.length > 0;
|
|
297
|
+
},
|
|
298
|
+
this._createAsyncValidator(),
|
|
299
|
+
function() {
|
|
300
|
+
if (self._count < self._factory.max) {
|
|
301
|
+
self._createResource();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
while (this._availableObjects.length > 0) {
|
|
309
|
+
this._log('dispense() - reusing obj', 'verbose');
|
|
310
|
+
objWithTimeout = this._availableObjects[0];
|
|
311
|
+
if (!this._factory.validate(objWithTimeout.obj)) {
|
|
312
|
+
this.destroy(objWithTimeout.obj);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
this._availableObjects.shift();
|
|
317
|
+
this._inUseObjects.push(objWithTimeout.obj);
|
|
318
|
+
clientCb = this._waitingClients.dequeue();
|
|
319
|
+
return clientCb(null, objWithTimeout.obj);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (this._count < this._factory.max) {
|
|
323
|
+
this._createResource();
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
Pool.prototype._createAsyncValidator = function _createAsyncValidator() {
|
|
328
|
+
var self = this;
|
|
329
|
+
return function asyncValidate(next) {
|
|
330
|
+
self._log('dispense() - reusing obj', 'verbose');
|
|
331
|
+
|
|
332
|
+
var objWithTimeout = self._availableObjects.shift();
|
|
333
|
+
self._asyncTestObjects.push(objWithTimeout);
|
|
334
|
+
|
|
335
|
+
self._factory.validateAsync(objWithTimeout.obj, function(valid) {
|
|
336
|
+
var pos = self._asyncTestObjects.indexOf(objWithTimeout);
|
|
337
|
+
self._asyncTestObjects.splice(pos, 1);
|
|
338
|
+
|
|
339
|
+
if (!valid) {
|
|
340
|
+
self.destroy(objWithTimeout.obj);
|
|
341
|
+
return next();
|
|
342
|
+
}
|
|
343
|
+
if (self._waitingClients.size() < 1) {
|
|
344
|
+
// there is no longer anyone waiting for a resource
|
|
345
|
+
self._addResourceToAvailableObjects(objWithTimeout.obj);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
self._inUseObjects.push(objWithTimeout.obj);
|
|
350
|
+
var clientCb = self._waitingClients.dequeue();
|
|
351
|
+
clientCb(null, objWithTimeout.obj);
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* @private
|
|
358
|
+
*/
|
|
359
|
+
Pool.prototype._createResource = function _createResource() {
|
|
360
|
+
this._count += 1;
|
|
361
|
+
this._log('createResource() - creating obj - count=' + this._count + ' min=' + this._factory.min + ' max=' + this._factory.max, 'verbose');
|
|
362
|
+
var self = this;
|
|
363
|
+
this._factory.create(function() {
|
|
364
|
+
var err, obj;
|
|
365
|
+
var clientCb = self._waitingClients.dequeue();
|
|
366
|
+
if (arguments.length > 1) {
|
|
367
|
+
err = arguments[0];
|
|
368
|
+
obj = arguments[1];
|
|
369
|
+
} else {
|
|
370
|
+
err = (arguments[0] instanceof Error) ? arguments[0] : null;
|
|
371
|
+
obj = (arguments[0] instanceof Error) ? null : arguments[0];
|
|
372
|
+
}
|
|
373
|
+
if (err) {
|
|
374
|
+
self._count -= 1;
|
|
375
|
+
if (self._count < 0) self._count = 0;
|
|
376
|
+
if (clientCb) {
|
|
377
|
+
clientCb(err, obj);
|
|
378
|
+
}
|
|
379
|
+
process.nextTick(function() {
|
|
380
|
+
self._dispense();
|
|
381
|
+
});
|
|
382
|
+
} else {
|
|
383
|
+
self._inUseObjects.push(obj);
|
|
384
|
+
if (clientCb) {
|
|
385
|
+
clientCb(err, obj);
|
|
386
|
+
} else {
|
|
387
|
+
self._addResourceToAvailableObjects(obj);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
Pool.prototype._addResourceToAvailableObjects = function(obj) {
|
|
394
|
+
var objWithTimeout = {
|
|
395
|
+
obj: obj,
|
|
396
|
+
timeout: (new Date().getTime() + this._factory.idleTimeoutMillis)
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
if (this._factory.returnToHead) {
|
|
400
|
+
this._availableObjects.splice(0, 0, objWithTimeout);
|
|
401
|
+
} else {
|
|
402
|
+
this._availableObjects.push(objWithTimeout);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this._dispense();
|
|
406
|
+
this._scheduleRemoveIdle();
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* @private
|
|
411
|
+
*/
|
|
412
|
+
Pool.prototype._ensureMinimum = function _ensureMinimum() {
|
|
413
|
+
var i, diff;
|
|
414
|
+
if (!this._draining && (this._count < this._factory.min)) {
|
|
415
|
+
diff = this._factory.min - this._count;
|
|
416
|
+
for (i = 0; i < diff; i++) {
|
|
417
|
+
this._createResource();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Request a new client. The callback will be called,
|
|
424
|
+
* when a new client will be availabe, passing the client to it.
|
|
425
|
+
*
|
|
426
|
+
* @param {Function} callback
|
|
427
|
+
* Callback function to be called after the acquire is successful.
|
|
428
|
+
* The function will receive the acquired item as the first parameter.
|
|
429
|
+
*
|
|
430
|
+
* @param {Number} priority
|
|
431
|
+
* Optional. Integer between 0 and (priorityRange - 1). Specifies the priority
|
|
432
|
+
* of the caller if there are no available resources. Lower numbers mean higher
|
|
433
|
+
* priority.
|
|
434
|
+
*
|
|
435
|
+
* @returns {boolean} `true` if the pool is not fully utilized, `false` otherwise.
|
|
436
|
+
*/
|
|
437
|
+
Pool.prototype.acquire = function acquire(callback, priority) {
|
|
438
|
+
if (this._draining) {
|
|
439
|
+
throw new Error('pool is draining and cannot accept work');
|
|
440
|
+
}
|
|
441
|
+
if (process.domain) {
|
|
442
|
+
callback = process.domain.bind(callback);
|
|
443
|
+
}
|
|
444
|
+
this._waitingClients.enqueue(callback, priority);
|
|
445
|
+
this._dispense();
|
|
446
|
+
return (this._count < this._factory.max);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* @deprecated
|
|
451
|
+
*/
|
|
452
|
+
Pool.prototype.borrow = function borrow(callback, priority) {
|
|
453
|
+
this._log('borrow() is deprecated. use acquire() instead', 'warn');
|
|
454
|
+
this.acquire(callback, priority);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Return the client to the pool, in case it is no longer required.
|
|
459
|
+
*
|
|
460
|
+
* @param {Object} obj
|
|
461
|
+
* The acquired object to be put back to the pool.
|
|
462
|
+
*/
|
|
463
|
+
Pool.prototype.release = function release(obj) {
|
|
464
|
+
// check to see if this object has already been released (i.e., is back in the pool of this._availableObjects)
|
|
465
|
+
if (this._availableObjects.some(function(objWithTimeout) {
|
|
466
|
+
return (objWithTimeout.obj === obj);
|
|
467
|
+
})) {
|
|
468
|
+
this._log('release called twice for the same resource: ' + (new Error().stack), 'error');
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// check to see if this object exists in the `in use` list and remove it
|
|
473
|
+
var index = this._inUseObjects.indexOf(obj);
|
|
474
|
+
if (index < 0) {
|
|
475
|
+
this._log('attempt to release an invalid resource: ' + (new Error().stack), 'error');
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// this._log("return to pool")
|
|
480
|
+
this._inUseObjects.splice(index, 1);
|
|
481
|
+
this._addResourceToAvailableObjects(obj);
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @deprecated
|
|
486
|
+
*/
|
|
487
|
+
Pool.prototype.returnToPool = function returnToPool(obj) {
|
|
488
|
+
this._log('returnToPool() is deprecated. use release() instead', 'warn');
|
|
489
|
+
this.release(obj);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
function invoke(cb) {
|
|
493
|
+
if (typeof setImmediate === 'function') {
|
|
494
|
+
setImmediate(cb);
|
|
495
|
+
} else {
|
|
496
|
+
setTimeout(cb, 0);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Disallow any new requests and let the request backlog dissapate.
|
|
502
|
+
*
|
|
503
|
+
* @param {Function} callback
|
|
504
|
+
* Optional. Callback invoked when all work is done and all clients have been
|
|
505
|
+
* released.
|
|
506
|
+
*/
|
|
507
|
+
Pool.prototype.drain = function drain(callback) {
|
|
508
|
+
this._log('draining', 'info');
|
|
509
|
+
|
|
510
|
+
// disable the ability to put more work on the queue.
|
|
511
|
+
this._draining = true;
|
|
512
|
+
|
|
513
|
+
var self = this;
|
|
514
|
+
var check = function() {
|
|
515
|
+
if (self._waitingClients.size() > 0) {
|
|
516
|
+
// wait until all client requests have been satisfied.
|
|
517
|
+
return setTimeout(check, 100);
|
|
518
|
+
}
|
|
519
|
+
if (self._asyncTestObjects.length > 0) {
|
|
520
|
+
// wait until any async tests have finished
|
|
521
|
+
return setTimeout(check, 100);
|
|
522
|
+
}
|
|
523
|
+
if (self._availableObjects.length !== self._count) {
|
|
524
|
+
// wait until in use object have been released.
|
|
525
|
+
return setTimeout(check, 100);
|
|
526
|
+
}
|
|
527
|
+
if (callback) {
|
|
528
|
+
invoke(callback);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
check();
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Forcibly destroys all clients regardless of timeout. Intended to be
|
|
536
|
+
* invoked as part of a drain. Does not prevent the creation of new
|
|
537
|
+
* clients as a result of subsequent calls to acquire.
|
|
538
|
+
*
|
|
539
|
+
* Note that if factory.min > 0, the pool will destroy all idle resources
|
|
540
|
+
* in the pool, but replace them with newly created resources up to the
|
|
541
|
+
* specified factory.min value. If this is not desired, set factory.min
|
|
542
|
+
* to zero before calling destroyAllNow()
|
|
543
|
+
*
|
|
544
|
+
* @param {Function} callback
|
|
545
|
+
* Optional. Callback invoked after all existing clients are destroyed.
|
|
546
|
+
*/
|
|
547
|
+
Pool.prototype.destroyAllNow = function destroyAllNow(callback) {
|
|
548
|
+
this._log('force destroying all objects', 'info');
|
|
549
|
+
var willDie = this._availableObjects;
|
|
550
|
+
this._availableObjects = [];
|
|
551
|
+
var todo = willDie.length;
|
|
552
|
+
var done = 0;
|
|
553
|
+
var obj = willDie.shift();
|
|
554
|
+
|
|
555
|
+
this._removeIdleScheduled = false;
|
|
556
|
+
clearTimeout(this._removeIdleTimer);
|
|
557
|
+
|
|
558
|
+
if (todo === 0 && callback) {
|
|
559
|
+
invoke(callback);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
while (obj !== null && obj !== undefined) {
|
|
563
|
+
this.destroy(obj.obj, function() {
|
|
564
|
+
++done;
|
|
565
|
+
if (done === todo && callback) {
|
|
566
|
+
invoke(callback);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
obj = willDie.shift();
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Decorates a function to use a acquired client from the object pool when called.
|
|
576
|
+
*
|
|
577
|
+
* @param {Function} decorated
|
|
578
|
+
* The decorated function, accepting a client as the first argument and
|
|
579
|
+
* (optionally) a callback as the final argument.
|
|
580
|
+
*
|
|
581
|
+
* @param {Number} priority
|
|
582
|
+
* Optional. Integer between 0 and (priorityRange - 1). Specifies the priority
|
|
583
|
+
* of the caller if there are no available resources. Lower numbers mean higher
|
|
584
|
+
* priority.
|
|
585
|
+
*/
|
|
586
|
+
Pool.prototype.pooled = function pooled(decorated, priority) {
|
|
587
|
+
var self = this;
|
|
588
|
+
return function() {
|
|
589
|
+
var callerArgs = arguments;
|
|
590
|
+
var callerCallback = callerArgs[callerArgs.length - 1];
|
|
591
|
+
var callerHasCallback = typeof callerCallback === 'function';
|
|
592
|
+
self.acquire(function(err, client) {
|
|
593
|
+
if (err) {
|
|
594
|
+
if (callerHasCallback) {
|
|
595
|
+
callerCallback(err);
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
var args = [client].concat(Array.prototype.slice.call(callerArgs, 0, callerHasCallback ? -1 : undefined));
|
|
601
|
+
args.push(function() {
|
|
602
|
+
self.release(client);
|
|
603
|
+
if (callerHasCallback) {
|
|
604
|
+
callerCallback.apply(null, arguments);
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
decorated.apply(null, args);
|
|
609
|
+
}, priority);
|
|
610
|
+
};
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
Pool.prototype.getPoolSize = function getPoolSize() {
|
|
614
|
+
return this._count;
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
Pool.prototype.getName = function getName() {
|
|
618
|
+
return this._factory.name;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
Pool.prototype.availableObjectsCount = function availableObjectsCount() {
|
|
622
|
+
return this._availableObjects.length;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
Pool.prototype.inUseObjectsCount = function inUseObjectsCount() {
|
|
626
|
+
return this._inUseObjects.length;
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
Pool.prototype.waitingClientsCount = function waitingClientsCount() {
|
|
630
|
+
return this._waitingClients.size();
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
Pool.prototype.getMaxPoolSize = function getMaxPoolSize() {
|
|
634
|
+
return this._factory.max;
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
Pool.prototype.getMinPoolSize = function getMinPoolSize() {
|
|
638
|
+
return this._factory.min;
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
exports.Pool = Pool;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var newSingleQuery = require('./query/newSingleQuery');
|
|
2
|
+
var extractFilter = require('../table/query/extractFilter');
|
|
3
|
+
var extractOrderBy = require('../table/query/extractOrderBy');
|
|
4
|
+
var extractLimit = require('../table/query/extractLimit');
|
|
5
|
+
var newParameterized = require('../table/query/newParameterized');
|
|
6
|
+
var extractOffset = require('../table/query/extractOffset');
|
|
7
|
+
|
|
8
|
+
function newQuery(table,filter,span,alias) {
|
|
9
|
+
filter = extractFilter(filter);
|
|
10
|
+
var orderBy = extractOrderBy(table,alias,span.orderBy);
|
|
11
|
+
var limit = extractLimit(span);
|
|
12
|
+
var offset = extractOffset(span);
|
|
13
|
+
|
|
14
|
+
var query = newSingleQuery(table,filter,span,alias,orderBy,limit,offset);
|
|
15
|
+
return newParameterized(query.sql(), query.parameters);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = newQuery;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var newShallowColumnSql = require('./singleQuery/newShallowColumnSql');
|
|
2
|
+
var newJoinedColumnSql = require('./singleQuery/newJoinedColumnSql');
|
|
3
|
+
|
|
4
|
+
module.exports = function(table,span,alias) {
|
|
5
|
+
var shallowColumnSql = newShallowColumnSql(table,alias, span);
|
|
6
|
+
var joinedColumnSql = newJoinedColumnSql(span,alias);
|
|
7
|
+
return shallowColumnSql + joinedColumnSql;
|
|
8
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var newColumnSql = require('../../table/query/singleQuery/newColumnSql');
|
|
2
|
+
var newWhereSql = require('../../table/query/singleQuery/newWhereSql');
|
|
3
|
+
var newJoinSql = require('../../table/query/singleQuery/newJoinSql');
|
|
4
|
+
var newParameterized = require('../../table/query/newParameterized');
|
|
5
|
+
|
|
6
|
+
function _new(table,filter,span, alias,orderBy,limit,offset) {
|
|
7
|
+
//todo
|
|
8
|
+
var name = table._dbName;
|
|
9
|
+
var columnSql = newColumnSql(table,span,alias,true);
|
|
10
|
+
var joinSql = newJoinSql(span, alias);
|
|
11
|
+
var whereSql = newWhereSql(table,filter,alias);
|
|
12
|
+
if (limit)
|
|
13
|
+
limit = limit + ' ';
|
|
14
|
+
|
|
15
|
+
return newParameterized('select ' + limit + columnSql + ' from ' + name + ' ' + alias).append(joinSql).append(whereSql).append(orderBy + offset);
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = _new;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var util = require('util');
|
|
2
|
+
//todo delete
|
|
3
|
+
function _new(table,alias,span) {
|
|
4
|
+
let columnsMap = span.columns;
|
|
5
|
+
var columnFormat = '%s as "%s"';
|
|
6
|
+
var columns = table._columns;
|
|
7
|
+
var sql = '';
|
|
8
|
+
var separator = '';
|
|
9
|
+
for (var i = 0; i < columns.length; i++) {
|
|
10
|
+
var column = columns[i];
|
|
11
|
+
if (!columnsMap || (columnsMap.get(column))) {
|
|
12
|
+
if (column.dbNull === null)
|
|
13
|
+
sql = sql + separator + alias + '.' + util.format(columnFormat, column._dbName, column.alias);
|
|
14
|
+
else {
|
|
15
|
+
const encoded = column.encode.unsafe(column.dbNull);
|
|
16
|
+
sql = sql + separator + `CASE WHEN ${alias}.${column._dbName}=${encoded} THEN null ELSE ${alias}.${column._dbName} END as ${column.alias}`;
|
|
17
|
+
}
|
|
18
|
+
separator = ',';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return sql;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = _new;
|