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,129 @@
|
|
|
1
|
+
let createDomain = require('../createDomain');
|
|
2
|
+
let newTransaction = require('./newTransaction');
|
|
3
|
+
let begin = require('../table/begin');
|
|
4
|
+
let commit = require('../table/commit');
|
|
5
|
+
let rollback = require('../table/rollback');
|
|
6
|
+
let newPool = require('./newPool');
|
|
7
|
+
let useHook = require('../useHook');
|
|
8
|
+
let promise = require('promise/domains');
|
|
9
|
+
let versionArray = process.version.replace('v', '').split('.');
|
|
10
|
+
let major = parseInt(versionArray[0]);
|
|
11
|
+
let express = require('../hostExpress');
|
|
12
|
+
let hostLocal = require('../hostLocal');
|
|
13
|
+
let doQuery = require('../query');
|
|
14
|
+
let releaseDbClient = require('../table/releaseDbClient');
|
|
15
|
+
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
16
|
+
|
|
17
|
+
function newDatabase(connectionString, poolOptions) {
|
|
18
|
+
if (!connectionString)
|
|
19
|
+
throw new Error('Connection string cannot be empty');
|
|
20
|
+
var pool;
|
|
21
|
+
if (!poolOptions)
|
|
22
|
+
pool = newPool.bind(null,connectionString, poolOptions);
|
|
23
|
+
else
|
|
24
|
+
pool = newPool(connectionString, poolOptions);
|
|
25
|
+
|
|
26
|
+
let c = {poolFactory: pool, hostLocal, express};
|
|
27
|
+
|
|
28
|
+
c.transaction = function(options, fn) {
|
|
29
|
+
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
30
|
+
fn = options;
|
|
31
|
+
options = undefined;
|
|
32
|
+
}
|
|
33
|
+
let domain = createDomain();
|
|
34
|
+
|
|
35
|
+
if (fn)
|
|
36
|
+
return domain.run(runInTransaction);
|
|
37
|
+
else if ((major >= 12) && useHook()) {
|
|
38
|
+
domain.exitContext = true;
|
|
39
|
+
return domain.start().then(run);
|
|
40
|
+
}
|
|
41
|
+
else
|
|
42
|
+
return domain.run(run);
|
|
43
|
+
|
|
44
|
+
async function runInTransaction() {
|
|
45
|
+
let result;
|
|
46
|
+
let transaction = newTransaction(domain, pool);
|
|
47
|
+
await new Promise(transaction)
|
|
48
|
+
.then(begin)
|
|
49
|
+
.then(fn)
|
|
50
|
+
.then((res) => result = res)
|
|
51
|
+
.then(c.commit)
|
|
52
|
+
.then(null, c.rollback);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function run() {
|
|
57
|
+
let p;
|
|
58
|
+
let transaction = newTransaction(domain, pool);
|
|
59
|
+
if (useHook())
|
|
60
|
+
p = new Promise(transaction);
|
|
61
|
+
else
|
|
62
|
+
p = new promise(transaction);
|
|
63
|
+
|
|
64
|
+
return p.then(begin);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
c.createTransaction = function() {
|
|
70
|
+
let domain = createDomain();
|
|
71
|
+
let transaction = newTransaction(domain, pool);
|
|
72
|
+
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
73
|
+
|
|
74
|
+
function run(fn) {
|
|
75
|
+
return p.then(domain.run.bind(domain, fn));
|
|
76
|
+
}
|
|
77
|
+
return run;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
c.bindTransaction = function() {
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
var domain = process.domain;
|
|
83
|
+
let p = domain.run(() => true);
|
|
84
|
+
|
|
85
|
+
function run(fn) {
|
|
86
|
+
return p.then(domain.run.bind(domain, fn));
|
|
87
|
+
}
|
|
88
|
+
return run;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
c.query = function(query) {
|
|
92
|
+
let domain = createDomain();
|
|
93
|
+
let transaction = newTransaction(domain, pool);
|
|
94
|
+
let p = domain.run(() => new Promise(transaction)
|
|
95
|
+
.then(() => setSessionSingleton('changes', []))
|
|
96
|
+
.then(() => doQuery(query).then(onResult, onError)));
|
|
97
|
+
return p;
|
|
98
|
+
|
|
99
|
+
function onResult(result) {
|
|
100
|
+
releaseDbClient();
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function onError(e) {
|
|
105
|
+
releaseDbClient();
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
c.rollback = rollback;
|
|
112
|
+
c.commit = commit;
|
|
113
|
+
|
|
114
|
+
c.end = function() {
|
|
115
|
+
if (poolOptions)
|
|
116
|
+
return pool.end();
|
|
117
|
+
else
|
|
118
|
+
return Promise.resolve();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
c.accept = function(caller) {
|
|
122
|
+
caller.visitSqlite();
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
return c;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = newDatabase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var pools = require('../pools');
|
|
2
|
+
var promise = require('../table/promise');
|
|
3
|
+
var end = require('./pool/end');
|
|
4
|
+
var newGenericPool = require('./pool/newGenericPool');
|
|
5
|
+
var newId = require('../newId');
|
|
6
|
+
|
|
7
|
+
function newPool(connectionString, poolOptions) {
|
|
8
|
+
var pool = newGenericPool(connectionString, poolOptions);
|
|
9
|
+
var id = newId();
|
|
10
|
+
var boundEnd = end.bind(null, pool, id);
|
|
11
|
+
var c = {};
|
|
12
|
+
|
|
13
|
+
c.connect = pool.connect;
|
|
14
|
+
c.end = promise.denodeify(boundEnd);
|
|
15
|
+
pools[id] = c;
|
|
16
|
+
return c;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = newPool;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var wrapQuery = require('./wrapQuery');
|
|
2
|
+
var encodeBoolean = require('../tedious/encodeBoolean');
|
|
3
|
+
var deleteFromSql = require('../tedious/deleteFromSql');
|
|
4
|
+
var selectForUpdateSql = require('../tedious/selectForUpdateSql');
|
|
5
|
+
var outputInsertedSql = require('../tedious/outputInsertedSql');
|
|
6
|
+
const limitAndOffset = require('../tedious/limitAndOffset');
|
|
7
|
+
const formatDateOut = require('../tedious/formatDateOut');
|
|
8
|
+
const insertSql = require('../tedious/insertSql');
|
|
9
|
+
const insert = require('../tedious/insert');
|
|
10
|
+
|
|
11
|
+
function newResolveTransaction(domain, pool) {
|
|
12
|
+
var rdb = {poolFactory: pool};
|
|
13
|
+
if (!pool.connect) {
|
|
14
|
+
pool = pool();
|
|
15
|
+
rdb.pool = pool;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return function(onSuccess, onError) {
|
|
19
|
+
pool.connect(onConnected);
|
|
20
|
+
|
|
21
|
+
function onConnected(err, client, done) {
|
|
22
|
+
try {
|
|
23
|
+
if (err) {
|
|
24
|
+
onError(err);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
client.setUseUTC(false);
|
|
28
|
+
client.executeQuery = wrapQuery(client);
|
|
29
|
+
rdb.engine = 'mssqlNative';
|
|
30
|
+
rdb.dbClient = client;
|
|
31
|
+
rdb.dbClientDone = done;
|
|
32
|
+
rdb.encodeBoolean = encodeBoolean;
|
|
33
|
+
rdb.decodeJSON = decodeJSON;
|
|
34
|
+
rdb.encodeJSON = JSON.stringify;
|
|
35
|
+
rdb.formatDateOut = formatDateOut;
|
|
36
|
+
rdb.deleteFromSql = deleteFromSql;
|
|
37
|
+
rdb.selectForUpdateSql = selectForUpdateSql;
|
|
38
|
+
rdb.outputInsertedSql = outputInsertedSql;
|
|
39
|
+
rdb.insertSql = insertSql;
|
|
40
|
+
rdb.insert = insert;
|
|
41
|
+
rdb.lastInsertedIsSeparate = false;
|
|
42
|
+
rdb.multipleStatements = true;
|
|
43
|
+
rdb.begin = 'BEGIN TRANSACTION';
|
|
44
|
+
rdb.limit = (span) => {
|
|
45
|
+
if (span.offset)
|
|
46
|
+
return '';
|
|
47
|
+
else if (span.limit || span.limit === 0)
|
|
48
|
+
return 'TOP ' + span.limit;
|
|
49
|
+
else
|
|
50
|
+
return '';
|
|
51
|
+
};
|
|
52
|
+
rdb.limitAndOffset = limitAndOffset;
|
|
53
|
+
rdb.accept = function(caller) {
|
|
54
|
+
caller.visitSqlite();
|
|
55
|
+
};
|
|
56
|
+
rdb.aggregateCount = 0;
|
|
57
|
+
domain.rdb = rdb;
|
|
58
|
+
onSuccess();
|
|
59
|
+
} catch (e) {
|
|
60
|
+
onError(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function decodeJSON(value){
|
|
66
|
+
return JSON.parse(value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = newResolveTransaction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// database host defaults to localhost
|
|
3
|
+
host: 'localhost',
|
|
4
|
+
|
|
5
|
+
//database user's name
|
|
6
|
+
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
|
|
7
|
+
|
|
8
|
+
//name of database to connect
|
|
9
|
+
database: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
|
|
10
|
+
|
|
11
|
+
//database user's password
|
|
12
|
+
password: null,
|
|
13
|
+
|
|
14
|
+
//database port
|
|
15
|
+
port: 5432,
|
|
16
|
+
|
|
17
|
+
//number of rows to return at a time from a prepared statement's
|
|
18
|
+
//portal. 0 will return all rows at once
|
|
19
|
+
rows: 0,
|
|
20
|
+
|
|
21
|
+
// binary result mode
|
|
22
|
+
binary: false,
|
|
23
|
+
|
|
24
|
+
//Connection pool options - see https://github.com/coopernurse/node-pool
|
|
25
|
+
//number of connections to use in connection pool
|
|
26
|
+
//0 will disable connection pooling
|
|
27
|
+
poolSize: 0,
|
|
28
|
+
|
|
29
|
+
//max milliseconds a client can go unused before it is removed
|
|
30
|
+
//from the pool and destroyed
|
|
31
|
+
poolIdleTimeout: 30000,
|
|
32
|
+
|
|
33
|
+
//frequeny to check for idle clients within the client pool
|
|
34
|
+
reapIntervalMillis: 1000,
|
|
35
|
+
|
|
36
|
+
//pool log function / boolean
|
|
37
|
+
poolLog: false,
|
|
38
|
+
|
|
39
|
+
client_encoding: '',
|
|
40
|
+
|
|
41
|
+
ssl: false,
|
|
42
|
+
|
|
43
|
+
application_name : undefined,
|
|
44
|
+
fallback_application_name: undefined
|
|
45
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable no-prototype-builtins */
|
|
3
|
+
var EventEmitter = require('events').EventEmitter;
|
|
4
|
+
|
|
5
|
+
var defaults = require('./defaults');
|
|
6
|
+
var genericPool = require('../../generic-pool');
|
|
7
|
+
var mssql = require('msnodesqlv8');
|
|
8
|
+
|
|
9
|
+
function newGenericPool(connectionString, poolOptions) {
|
|
10
|
+
poolOptions = poolOptions || {};
|
|
11
|
+
var pool = genericPool.Pool({
|
|
12
|
+
max: poolOptions.size || poolOptions.poolSize || defaults.poolSize,
|
|
13
|
+
idleTimeoutMillis: poolOptions.idleTimeout || defaults.poolIdleTimeout,
|
|
14
|
+
reapIntervalMillis: poolOptions.reapIntervalMillis || defaults.reapIntervalMillis,
|
|
15
|
+
log: poolOptions.log || defaults.poolLog,
|
|
16
|
+
create: function(cb) {
|
|
17
|
+
var client;
|
|
18
|
+
mssql.open(connectionString, onConnected);
|
|
19
|
+
|
|
20
|
+
function onConnected(err, _client) {
|
|
21
|
+
if(err)
|
|
22
|
+
return cb(err, null);
|
|
23
|
+
client = _client;
|
|
24
|
+
client.poolCount = 0;
|
|
25
|
+
return cb(null, client);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
destroy: function(client) {
|
|
30
|
+
client.poolCount = undefined;
|
|
31
|
+
client.close();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
//mixin EventEmitter to pool
|
|
35
|
+
EventEmitter.call(pool);
|
|
36
|
+
for(var key in EventEmitter.prototype) {
|
|
37
|
+
if(EventEmitter.prototype.hasOwnProperty(key)) {
|
|
38
|
+
pool[key] = EventEmitter.prototype[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//monkey-patch with connect method
|
|
42
|
+
pool.connect = function(cb) {
|
|
43
|
+
var domain = process.domain;
|
|
44
|
+
pool.acquire(function(err, client) {
|
|
45
|
+
if(domain) {
|
|
46
|
+
cb = domain.bind(cb);
|
|
47
|
+
}
|
|
48
|
+
if(err) return cb(err, null, function() {/*NOOP*/});
|
|
49
|
+
client.poolCount++;
|
|
50
|
+
cb(null, client, function(err) {
|
|
51
|
+
if(err) {
|
|
52
|
+
pool.destroy(client);
|
|
53
|
+
} else {
|
|
54
|
+
pool.release(client);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return pool;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = newGenericPool;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var log = require('../table/log');
|
|
2
|
+
|
|
3
|
+
function wrapQuery(connection) {
|
|
4
|
+
var runOriginalQuery = connection.query;
|
|
5
|
+
return runQuery;
|
|
6
|
+
|
|
7
|
+
function runQuery(query, onCompleted) {
|
|
8
|
+
var params = query.parameters;
|
|
9
|
+
var sql = query.sql();
|
|
10
|
+
log.emitQuery({ sql, parameters: params });
|
|
11
|
+
|
|
12
|
+
runOriginalQuery.call(connection, sql, params, onInnerCompleted);
|
|
13
|
+
let result = [];
|
|
14
|
+
|
|
15
|
+
function onInnerCompleted(err, rows, hasMore) {
|
|
16
|
+
if (err) {
|
|
17
|
+
if (err.code)
|
|
18
|
+
onCompleted(err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
result.push(rows);
|
|
22
|
+
if (!hasMore) {
|
|
23
|
+
|
|
24
|
+
if (result.length === 1)
|
|
25
|
+
onCompleted(null, result[0]);
|
|
26
|
+
else
|
|
27
|
+
onCompleted(null, result);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = wrapQuery;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
let newInsertCommand = require('../table/commands/newInsertCommand');
|
|
2
|
+
let newInsertCommandCore = require('../table/commands/newInsertCommandCore');
|
|
3
|
+
let newGetLastInsertedCommand = require('../table/commands/newGetLastInsertedCommand');
|
|
4
|
+
let executeQueries = require('../table/executeQueries');
|
|
5
|
+
let pushCommand = require('../table/commands/pushCommand');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function insertDefault(table, row, options) {
|
|
9
|
+
let commands = [];
|
|
10
|
+
let insertCmd = newInsertCommand(newInsertCommandCore, table, row, options);
|
|
11
|
+
insertCmd.disallowCompress = true;
|
|
12
|
+
pushCommand(insertCmd);
|
|
13
|
+
|
|
14
|
+
let selectCmd = newGetLastInsertedCommand(table, row, insertCmd);
|
|
15
|
+
commands.push(selectCmd);
|
|
16
|
+
|
|
17
|
+
return executeQueries(commands).then((result) => result[result.length - 1]);
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = insertDefault;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function insertSql(table, row, options) {
|
|
2
|
+
let columnNames = [];
|
|
3
|
+
let regularColumnNames = [];
|
|
4
|
+
let conflictColumnUpdateSql = '';
|
|
5
|
+
let values = [];
|
|
6
|
+
let sql = 'INSERT INTO ' + table._dbName + ' ';
|
|
7
|
+
addDiscriminators();
|
|
8
|
+
addColumns();
|
|
9
|
+
if (columnNames.length === 0) {
|
|
10
|
+
sql += 'VALUES ()';
|
|
11
|
+
} else {
|
|
12
|
+
sql = sql + '(' + columnNames.join(',') + ') ' + 'VALUES (' + values.join(',') + ')' + onDuplicateKeyUpdate();
|
|
13
|
+
}
|
|
14
|
+
return sql;
|
|
15
|
+
|
|
16
|
+
function onDuplicateKeyUpdate() {
|
|
17
|
+
if (options.concurrency === 'skipOnConflict' || options.concurrency === 'overwrite') {
|
|
18
|
+
return ` ON DUPLICATE KEY UPDATE ${conflictColumnUpdateSql} `;
|
|
19
|
+
} else {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function addDiscriminators() {
|
|
25
|
+
let discriminators = table._columnDiscriminators;
|
|
26
|
+
for (let i = 0; i < discriminators.length; i++) {
|
|
27
|
+
let parts = discriminators[i].split('=');
|
|
28
|
+
columnNames.push(parts[0]);
|
|
29
|
+
values.push(parts[1]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function addColumns() {
|
|
34
|
+
let conflictColumnUpdates = [];
|
|
35
|
+
let columns = table._columns;
|
|
36
|
+
for (let i = 0; i < columns.length; i++) {
|
|
37
|
+
let column = columns[i];
|
|
38
|
+
regularColumnNames.push(column._dbName);
|
|
39
|
+
if (row['__' + column.alias] !== undefined) {
|
|
40
|
+
columnNames.push(column._dbName);
|
|
41
|
+
values.push('%s');
|
|
42
|
+
addConflictUpdate(column);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (conflictColumnUpdates.length === 0) {
|
|
46
|
+
const column = table._primaryColumns[0];
|
|
47
|
+
conflictColumnUpdates.push(`${column._dbName}=VALUES(${column._dbName})`);
|
|
48
|
+
}
|
|
49
|
+
conflictColumnUpdateSql = conflictColumnUpdates.join(',');
|
|
50
|
+
|
|
51
|
+
function addConflictUpdate(column) {
|
|
52
|
+
let concurrency = options[column.alias]?.concurrency || options.concurrency;
|
|
53
|
+
if (concurrency === 'overwrite') {
|
|
54
|
+
conflictColumnUpdates.push(`${column._dbName}=VALUES(${column._dbName})`);
|
|
55
|
+
} else if (concurrency === 'optimistic') {
|
|
56
|
+
conflictColumnUpdates.push(`${column._dbName} = CASE WHEN ${table._dbName}.${column._dbName} <> VALUES(${column._dbName}) THEN CAST('12345678-1234-1234-1234-123456789012Conflict when updating ${column._dbName}12345678-1234-1234-1234-123456789012' AS SIGNED) ELSE ${table._dbName}.${column._dbName} END`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = insertSql;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function lastInsertedSql(table, keyValues) {
|
|
2
|
+
return keyValues.map((value,i) => {
|
|
3
|
+
let column = table._primaryColumns[i];
|
|
4
|
+
if (value === undefined && column.tsType === 'NumberColumn')
|
|
5
|
+
return `${column._dbName}=LAST_INSERT_ID()`;
|
|
6
|
+
else
|
|
7
|
+
return column.eq(value);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = lastInsertedSql;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function limitAndOffset(span) {
|
|
2
|
+
if (span.offset)
|
|
3
|
+
return ` limit ${span.offset}${limit()}`;
|
|
4
|
+
else if (span.limit || span.limit === 0)
|
|
5
|
+
return ` limit ${span.limit}`;
|
|
6
|
+
else
|
|
7
|
+
return '';
|
|
8
|
+
|
|
9
|
+
function limit() {
|
|
10
|
+
if (span.limit || span.limit === 0)
|
|
11
|
+
return `, ${span.limit}`;
|
|
12
|
+
else
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = limitAndOffset;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
let createDomain = require('../createDomain');
|
|
2
|
+
let newTransaction = require('./newTransaction');
|
|
3
|
+
let begin = require('../table/begin');
|
|
4
|
+
let commit = require('../table/commit');
|
|
5
|
+
let rollback = require('../table/rollback');
|
|
6
|
+
let newPool = require('./newPool');
|
|
7
|
+
let useHook = require('../useHook');
|
|
8
|
+
let promise = require('promise/domains');
|
|
9
|
+
let versionArray = process.version.replace('v', '').split('.');
|
|
10
|
+
let major = parseInt(versionArray[0]);
|
|
11
|
+
let express = require('../hostExpress');
|
|
12
|
+
let hostLocal = require('../hostLocal');
|
|
13
|
+
let doQuery = require('../query');
|
|
14
|
+
let releaseDbClient = require('../table/releaseDbClient');
|
|
15
|
+
let setSessionSingleton = require('../table/setSessionSingleton');
|
|
16
|
+
|
|
17
|
+
function newDatabase(connectionString, poolOptions) {
|
|
18
|
+
if (!connectionString)
|
|
19
|
+
throw new Error('Connection string cannot be empty');
|
|
20
|
+
var pool;
|
|
21
|
+
if (!poolOptions)
|
|
22
|
+
pool = newPool.bind(null,connectionString, poolOptions);
|
|
23
|
+
else
|
|
24
|
+
pool = newPool(connectionString, poolOptions);
|
|
25
|
+
|
|
26
|
+
let c = {poolFactory: pool, hostLocal, express};
|
|
27
|
+
|
|
28
|
+
c.transaction = function(options, fn) {
|
|
29
|
+
if ((arguments.length === 1) && (typeof options === 'function')) {
|
|
30
|
+
fn = options;
|
|
31
|
+
options = undefined;
|
|
32
|
+
}
|
|
33
|
+
let domain = createDomain();
|
|
34
|
+
|
|
35
|
+
if (fn)
|
|
36
|
+
return domain.run(runInTransaction);
|
|
37
|
+
else if ((major >= 12) && useHook()) {
|
|
38
|
+
domain.exitContext = true;
|
|
39
|
+
return domain.start().then(run);
|
|
40
|
+
} else
|
|
41
|
+
return domain.run(run);
|
|
42
|
+
|
|
43
|
+
async function runInTransaction() {
|
|
44
|
+
let result;
|
|
45
|
+
let transaction = newTransaction(domain, pool);
|
|
46
|
+
await new Promise(transaction)
|
|
47
|
+
.then(begin)
|
|
48
|
+
.then(fn)
|
|
49
|
+
.then((res) => result = res)
|
|
50
|
+
.then(c.commit)
|
|
51
|
+
.then(null, c.rollback);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function run() {
|
|
56
|
+
let p;
|
|
57
|
+
let transaction = newTransaction(domain, pool);
|
|
58
|
+
if (useHook())
|
|
59
|
+
p = new Promise(transaction);
|
|
60
|
+
else
|
|
61
|
+
p = new promise(transaction);
|
|
62
|
+
|
|
63
|
+
return p.then(begin);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
c.createTransaction = function() {
|
|
69
|
+
let domain = createDomain();
|
|
70
|
+
let transaction = newTransaction(domain, pool);
|
|
71
|
+
let p = domain.run(() => new Promise(transaction).then(begin));
|
|
72
|
+
|
|
73
|
+
function run(fn) {
|
|
74
|
+
return p.then(domain.run.bind(domain, fn));
|
|
75
|
+
}
|
|
76
|
+
return run;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
c.bindTransaction = function() {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
var domain = process.domain;
|
|
82
|
+
let p = domain.run(() => true);
|
|
83
|
+
|
|
84
|
+
function run(fn) {
|
|
85
|
+
return p.then(domain.run.bind(domain, fn));
|
|
86
|
+
}
|
|
87
|
+
return run;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
c.query = function(query) {
|
|
91
|
+
let domain = createDomain();
|
|
92
|
+
let transaction = newTransaction(domain, pool);
|
|
93
|
+
let p = domain.run(() => new Promise(transaction)
|
|
94
|
+
.then(() => setSessionSingleton('changes', []))
|
|
95
|
+
.then(() => doQuery(query).then(onResult, onError)));
|
|
96
|
+
return p;
|
|
97
|
+
|
|
98
|
+
function onResult(result) {
|
|
99
|
+
releaseDbClient();
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function onError(e) {
|
|
104
|
+
releaseDbClient();
|
|
105
|
+
throw e;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
c.rollback = rollback;
|
|
111
|
+
c.commit = commit;
|
|
112
|
+
|
|
113
|
+
c.end = function() {
|
|
114
|
+
if (poolOptions)
|
|
115
|
+
return pool.end();
|
|
116
|
+
else
|
|
117
|
+
return Promise.resolve();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
c.accept = function(caller) {
|
|
121
|
+
caller.visitMySql();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return c;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = newDatabase;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var pools = require('../pools');
|
|
2
|
+
var promise = require('../table/promise');
|
|
3
|
+
var end = require('./pool/end');
|
|
4
|
+
var newGenericPool = require('./pool/newGenericPool');
|
|
5
|
+
var newId = require('../newId');
|
|
6
|
+
|
|
7
|
+
function newPool(connectionString, poolOptions) {
|
|
8
|
+
var pool = newGenericPool(connectionString, poolOptions);
|
|
9
|
+
var id = newId();
|
|
10
|
+
var boundEnd = end.bind(null, pool, id);
|
|
11
|
+
var c = {};
|
|
12
|
+
|
|
13
|
+
c.connect = pool.connect;
|
|
14
|
+
c.end = promise.denodeify(boundEnd);
|
|
15
|
+
pools[id] = c;
|
|
16
|
+
return c;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = newPool;
|