@contember/database 2.1.0-rc.3 → 2.2.0-alpha.10
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/CLAUDE.md +22 -0
- package/dist/development/index.cjs +9 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +10 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/builders/CaseStatement.cjs.map +1 -1
- package/dist/development/src/builders/CaseStatement.js.map +1 -1
- package/dist/development/src/builders/ColumnExpressionFactory.cjs.map +1 -1
- package/dist/development/src/builders/ColumnExpressionFactory.js.map +1 -1
- package/dist/development/src/builders/Compiler.cjs.map +1 -1
- package/dist/development/src/builders/Compiler.js.map +1 -1
- package/dist/development/src/builders/ConditionBuilder.cjs +6 -0
- package/dist/development/src/builders/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/builders/ConditionBuilder.js +6 -0
- package/dist/development/src/builders/ConditionBuilder.js.map +1 -1
- package/dist/development/src/builders/DeleteBuilder.cjs.map +1 -1
- package/dist/development/src/builders/DeleteBuilder.js.map +1 -1
- package/dist/development/src/builders/InsertBuilder.cjs.map +1 -1
- package/dist/development/src/builders/InsertBuilder.js.map +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.cjs +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.cjs.map +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.js +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.js.map +1 -1
- package/dist/development/src/builders/SelectBuilder.cjs.map +1 -1
- package/dist/development/src/builders/SelectBuilder.js.map +1 -1
- package/dist/development/src/builders/UpdateBuilder.cjs.map +1 -1
- package/dist/development/src/builders/UpdateBuilder.js.map +1 -1
- package/dist/development/src/builders/WindowFunction.cjs +1 -1
- package/dist/development/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/development/src/builders/WindowFunction.js +1 -1
- package/dist/development/src/builders/WindowFunction.js.map +1 -1
- package/dist/development/src/builders/internal/Returning.cjs.map +1 -1
- package/dist/development/src/builders/internal/Returning.js.map +1 -1
- package/dist/development/src/builders/internal/Subqueries.cjs.map +1 -1
- package/dist/development/src/builders/internal/Subqueries.js.map +1 -1
- package/dist/development/src/builders/internal/Where.cjs.map +1 -1
- package/dist/development/src/builders/internal/Where.js.map +1 -1
- package/dist/development/src/builders/internal/With.cjs.map +1 -1
- package/dist/development/src/builders/internal/With.js.map +1 -1
- package/dist/development/src/builders/utils.cjs.map +1 -1
- package/dist/development/src/builders/utils.js.map +1 -1
- package/dist/development/src/client/AcquiredConnection.cjs +105 -32
- package/dist/development/src/client/AcquiredConnection.cjs.map +1 -1
- package/dist/development/src/client/AcquiredConnection.js +107 -34
- package/dist/development/src/client/AcquiredConnection.js.map +1 -1
- package/dist/development/src/client/Client.cjs +9 -1
- package/dist/development/src/client/Client.cjs.map +1 -1
- package/dist/development/src/client/Client.js +9 -1
- package/dist/development/src/client/Client.js.map +1 -1
- package/dist/development/src/client/Connection.cjs +19 -1
- package/dist/development/src/client/Connection.cjs.map +1 -1
- package/dist/development/src/client/Connection.js +19 -1
- package/dist/development/src/client/Connection.js.map +1 -1
- package/dist/development/src/client/EventManager.cjs +6 -2
- package/dist/development/src/client/EventManager.cjs.map +1 -1
- package/dist/development/src/client/EventManager.js +6 -2
- package/dist/development/src/client/EventManager.js.map +1 -1
- package/dist/development/src/client/Pool.cjs.map +1 -1
- package/dist/development/src/client/Pool.js.map +1 -1
- package/dist/development/src/client/RequestMemoryBudget.cjs +237 -0
- package/dist/development/src/client/RequestMemoryBudget.cjs.map +1 -0
- package/dist/development/src/client/RequestMemoryBudget.js +237 -0
- package/dist/development/src/client/RequestMemoryBudget.js.map +1 -0
- package/dist/development/src/client/ScopeLimitedConnection.cjs +37 -0
- package/dist/development/src/client/ScopeLimitedConnection.cjs.map +1 -0
- package/dist/development/src/client/ScopeLimitedConnection.js +37 -0
- package/dist/development/src/client/ScopeLimitedConnection.js.map +1 -0
- package/dist/development/src/client/Transaction.cjs +20 -8
- package/dist/development/src/client/Transaction.cjs.map +1 -1
- package/dist/development/src/client/Transaction.js +21 -9
- package/dist/development/src/client/Transaction.js.map +1 -1
- package/dist/development/src/client/cancelRunningStatement.cjs +32 -0
- package/dist/development/src/client/cancelRunningStatement.cjs.map +1 -0
- package/dist/development/src/client/cancelRunningStatement.js +32 -0
- package/dist/development/src/client/cancelRunningStatement.js.map +1 -0
- package/dist/development/src/client/errors.cjs +6 -0
- package/dist/development/src/client/errors.cjs.map +1 -1
- package/dist/development/src/client/errors.js +6 -0
- package/dist/development/src/client/errors.js.map +1 -1
- package/dist/development/src/metadata/DatabaseMetadata.cjs.map +1 -1
- package/dist/development/src/metadata/DatabaseMetadata.js.map +1 -1
- package/dist/development/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
- package/dist/development/src/metadata/DatabaseMetadataResolver.js.map +1 -1
- package/dist/development/src/metadata/IndexMetadata.cjs.map +1 -1
- package/dist/development/src/metadata/IndexMetadata.js.map +1 -1
- package/dist/development/src/metadata/UniqueConstraintMetadata.cjs.map +1 -1
- package/dist/development/src/metadata/UniqueConstraintMetadata.js.map +1 -1
- package/dist/development/src/queryable/DatabaseQuery.cjs.map +1 -1
- package/dist/development/src/queryable/DatabaseQuery.js.map +1 -1
- package/dist/development/src/queryable/DatabaseQueryable.cjs.map +1 -1
- package/dist/development/src/queryable/DatabaseQueryable.js.map +1 -1
- package/dist/development/src/utils/ConstraintHelper.cjs.map +1 -1
- package/dist/development/src/utils/ConstraintHelper.js.map +1 -1
- package/dist/development/src/utils/Semaphore.cjs +43 -0
- package/dist/development/src/utils/Semaphore.cjs.map +1 -0
- package/dist/development/src/utils/Semaphore.js +43 -0
- package/dist/development/src/utils/Semaphore.js.map +1 -0
- package/dist/development/src/utils/createDatabaseIfNotExists.cjs.map +1 -1
- package/dist/development/src/utils/createDatabaseIfNotExists.js.map +1 -1
- package/dist/development/src/utils/listen.cjs.map +1 -1
- package/dist/development/src/utils/listen.js.map +1 -1
- package/dist/development/src/utils/pgClientFactory.cjs +9 -4
- package/dist/development/src/utils/pgClientFactory.cjs.map +1 -1
- package/dist/development/src/utils/pgClientFactory.js +9 -4
- package/dist/development/src/utils/pgClientFactory.js.map +1 -1
- package/dist/development/src/utils/retryTransaction.cjs.map +1 -1
- package/dist/development/src/utils/retryTransaction.js.map +1 -1
- package/dist/development/src/utils/sql.cjs.map +1 -1
- package/dist/development/src/utils/sql.js.map +1 -1
- package/dist/development/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -1
- package/dist/development/src/utils/withDatabaseAdvisoryLock.js.map +1 -1
- package/dist/production/index.cjs +9 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +10 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/builders/CaseStatement.cjs.map +1 -1
- package/dist/production/src/builders/CaseStatement.js.map +1 -1
- package/dist/production/src/builders/ColumnExpressionFactory.cjs.map +1 -1
- package/dist/production/src/builders/ColumnExpressionFactory.js.map +1 -1
- package/dist/production/src/builders/Compiler.cjs.map +1 -1
- package/dist/production/src/builders/Compiler.js.map +1 -1
- package/dist/production/src/builders/ConditionBuilder.cjs +6 -0
- package/dist/production/src/builders/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/builders/ConditionBuilder.js +6 -0
- package/dist/production/src/builders/ConditionBuilder.js.map +1 -1
- package/dist/production/src/builders/DeleteBuilder.cjs.map +1 -1
- package/dist/production/src/builders/DeleteBuilder.js.map +1 -1
- package/dist/production/src/builders/InsertBuilder.cjs.map +1 -1
- package/dist/production/src/builders/InsertBuilder.js.map +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.cjs +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.cjs.map +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.js +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.js.map +1 -1
- package/dist/production/src/builders/SelectBuilder.cjs.map +1 -1
- package/dist/production/src/builders/SelectBuilder.js.map +1 -1
- package/dist/production/src/builders/UpdateBuilder.cjs.map +1 -1
- package/dist/production/src/builders/UpdateBuilder.js.map +1 -1
- package/dist/production/src/builders/WindowFunction.cjs +1 -1
- package/dist/production/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/production/src/builders/WindowFunction.js +1 -1
- package/dist/production/src/builders/WindowFunction.js.map +1 -1
- package/dist/production/src/builders/internal/Returning.cjs.map +1 -1
- package/dist/production/src/builders/internal/Returning.js.map +1 -1
- package/dist/production/src/builders/internal/Subqueries.cjs.map +1 -1
- package/dist/production/src/builders/internal/Subqueries.js.map +1 -1
- package/dist/production/src/builders/internal/Where.cjs.map +1 -1
- package/dist/production/src/builders/internal/Where.js.map +1 -1
- package/dist/production/src/builders/internal/With.cjs.map +1 -1
- package/dist/production/src/builders/internal/With.js.map +1 -1
- package/dist/production/src/builders/utils.cjs.map +1 -1
- package/dist/production/src/builders/utils.js.map +1 -1
- package/dist/production/src/client/AcquiredConnection.cjs +105 -32
- package/dist/production/src/client/AcquiredConnection.cjs.map +1 -1
- package/dist/production/src/client/AcquiredConnection.js +107 -34
- package/dist/production/src/client/AcquiredConnection.js.map +1 -1
- package/dist/production/src/client/Client.cjs +9 -1
- package/dist/production/src/client/Client.cjs.map +1 -1
- package/dist/production/src/client/Client.js +9 -1
- package/dist/production/src/client/Client.js.map +1 -1
- package/dist/production/src/client/Connection.cjs +19 -1
- package/dist/production/src/client/Connection.cjs.map +1 -1
- package/dist/production/src/client/Connection.js +19 -1
- package/dist/production/src/client/Connection.js.map +1 -1
- package/dist/production/src/client/EventManager.cjs +6 -2
- package/dist/production/src/client/EventManager.cjs.map +1 -1
- package/dist/production/src/client/EventManager.js +6 -2
- package/dist/production/src/client/EventManager.js.map +1 -1
- package/dist/production/src/client/Pool.cjs.map +1 -1
- package/dist/production/src/client/Pool.js.map +1 -1
- package/dist/production/src/client/RequestMemoryBudget.cjs +237 -0
- package/dist/production/src/client/RequestMemoryBudget.cjs.map +1 -0
- package/dist/production/src/client/RequestMemoryBudget.js +237 -0
- package/dist/production/src/client/RequestMemoryBudget.js.map +1 -0
- package/dist/production/src/client/ScopeLimitedConnection.cjs +37 -0
- package/dist/production/src/client/ScopeLimitedConnection.cjs.map +1 -0
- package/dist/production/src/client/ScopeLimitedConnection.js +37 -0
- package/dist/production/src/client/ScopeLimitedConnection.js.map +1 -0
- package/dist/production/src/client/Transaction.cjs +20 -8
- package/dist/production/src/client/Transaction.cjs.map +1 -1
- package/dist/production/src/client/Transaction.js +21 -9
- package/dist/production/src/client/Transaction.js.map +1 -1
- package/dist/production/src/client/cancelRunningStatement.cjs +32 -0
- package/dist/production/src/client/cancelRunningStatement.cjs.map +1 -0
- package/dist/production/src/client/cancelRunningStatement.js +32 -0
- package/dist/production/src/client/cancelRunningStatement.js.map +1 -0
- package/dist/production/src/client/errors.cjs +6 -0
- package/dist/production/src/client/errors.cjs.map +1 -1
- package/dist/production/src/client/errors.js +6 -0
- package/dist/production/src/client/errors.js.map +1 -1
- package/dist/production/src/metadata/DatabaseMetadata.cjs.map +1 -1
- package/dist/production/src/metadata/DatabaseMetadata.js.map +1 -1
- package/dist/production/src/metadata/DatabaseMetadataResolver.cjs.map +1 -1
- package/dist/production/src/metadata/DatabaseMetadataResolver.js.map +1 -1
- package/dist/production/src/metadata/IndexMetadata.cjs.map +1 -1
- package/dist/production/src/metadata/IndexMetadata.js.map +1 -1
- package/dist/production/src/metadata/UniqueConstraintMetadata.cjs.map +1 -1
- package/dist/production/src/metadata/UniqueConstraintMetadata.js.map +1 -1
- package/dist/production/src/queryable/DatabaseQuery.cjs.map +1 -1
- package/dist/production/src/queryable/DatabaseQuery.js.map +1 -1
- package/dist/production/src/queryable/DatabaseQueryable.cjs.map +1 -1
- package/dist/production/src/queryable/DatabaseQueryable.js.map +1 -1
- package/dist/production/src/utils/ConstraintHelper.cjs.map +1 -1
- package/dist/production/src/utils/ConstraintHelper.js.map +1 -1
- package/dist/production/src/utils/Semaphore.cjs +43 -0
- package/dist/production/src/utils/Semaphore.cjs.map +1 -0
- package/dist/production/src/utils/Semaphore.js +43 -0
- package/dist/production/src/utils/Semaphore.js.map +1 -0
- package/dist/production/src/utils/createDatabaseIfNotExists.cjs.map +1 -1
- package/dist/production/src/utils/createDatabaseIfNotExists.js.map +1 -1
- package/dist/production/src/utils/listen.cjs.map +1 -1
- package/dist/production/src/utils/listen.js.map +1 -1
- package/dist/production/src/utils/pgClientFactory.cjs +9 -4
- package/dist/production/src/utils/pgClientFactory.cjs.map +1 -1
- package/dist/production/src/utils/pgClientFactory.js +9 -4
- package/dist/production/src/utils/pgClientFactory.js.map +1 -1
- package/dist/production/src/utils/retryTransaction.cjs.map +1 -1
- package/dist/production/src/utils/retryTransaction.js.map +1 -1
- package/dist/production/src/utils/sql.cjs.map +1 -1
- package/dist/production/src/utils/sql.js.map +1 -1
- package/dist/production/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -1
- package/dist/production/src/utils/withDatabaseAdvisoryLock.js.map +1 -1
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/acquiredConnection.test.d.ts +2 -0
- package/dist/tests/cases/unit/acquiredConnection.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts +6 -3
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts.map +1 -1
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/scopeLimitedConnection.test.d.ts +2 -0
- package/dist/tests/cases/unit/scopeLimitedConnection.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/semaphore.test.d.ts +2 -0
- package/dist/tests/cases/unit/semaphore.test.d.ts.map +1 -0
- package/dist/tests/src/tags.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Literal.d.ts.map +1 -1
- package/dist/types/builders/CaseStatement.d.ts +2 -2
- package/dist/types/builders/CaseStatement.d.ts.map +1 -1
- package/dist/types/builders/ColumnExpressionFactory.d.ts +6 -6
- package/dist/types/builders/ColumnExpressionFactory.d.ts.map +1 -1
- package/dist/types/builders/Compiler.d.ts +5 -5
- package/dist/types/builders/Compiler.d.ts.map +1 -1
- package/dist/types/builders/ConditionBuilder.d.ts +8 -6
- package/dist/types/builders/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/builders/DeleteBuilder.d.ts +8 -8
- package/dist/types/builders/DeleteBuilder.d.ts.map +1 -1
- package/dist/types/builders/InsertBuilder.d.ts +10 -10
- package/dist/types/builders/InsertBuilder.d.ts.map +1 -1
- package/dist/types/builders/LimitByGroupWrapper.d.ts +3 -3
- package/dist/types/builders/LimitByGroupWrapper.d.ts.map +1 -1
- package/dist/types/builders/QueryBuilder.d.ts +5 -5
- package/dist/types/builders/QueryBuilder.d.ts.map +1 -1
- package/dist/types/builders/SelectBuilder.d.ts +9 -9
- package/dist/types/builders/SelectBuilder.d.ts.map +1 -1
- package/dist/types/builders/UpdateBuilder.d.ts +9 -9
- package/dist/types/builders/UpdateBuilder.d.ts.map +1 -1
- package/dist/types/builders/WindowFunction.d.ts +4 -3
- package/dist/types/builders/WindowFunction.d.ts.map +1 -1
- package/dist/types/builders/index.d.ts +12 -12
- package/dist/types/builders/index.d.ts.map +1 -1
- package/dist/types/builders/internal/Returning.d.ts +3 -3
- package/dist/types/builders/internal/Returning.d.ts.map +1 -1
- package/dist/types/builders/internal/Subqueries.d.ts +4 -4
- package/dist/types/builders/internal/Subqueries.d.ts.map +1 -1
- package/dist/types/builders/internal/Where.d.ts +3 -3
- package/dist/types/builders/internal/Where.d.ts.map +1 -1
- package/dist/types/builders/internal/With.d.ts +3 -3
- package/dist/types/builders/internal/With.d.ts.map +1 -1
- package/dist/types/builders/utils.d.ts +2 -2
- package/dist/types/builders/utils.d.ts.map +1 -1
- package/dist/types/client/AcquiredConnection.d.ts +9 -4
- package/dist/types/client/AcquiredConnection.d.ts.map +1 -1
- package/dist/types/client/Client.d.ts +12 -4
- package/dist/types/client/Client.d.ts.map +1 -1
- package/dist/types/client/Connection.d.ts +12 -4
- package/dist/types/client/Connection.d.ts.map +1 -1
- package/dist/types/client/EventManager.d.ts +6 -2
- package/dist/types/client/EventManager.d.ts.map +1 -1
- package/dist/types/client/PgClient.d.ts +12 -1
- package/dist/types/client/PgClient.d.ts.map +1 -1
- package/dist/types/client/Pool.d.ts +3 -3
- package/dist/types/client/Pool.d.ts.map +1 -1
- package/dist/types/client/RequestMemoryBudget.d.ts +41 -0
- package/dist/types/client/RequestMemoryBudget.d.ts.map +1 -0
- package/dist/types/client/ScopeLimitedConnection.d.ts +34 -0
- package/dist/types/client/ScopeLimitedConnection.d.ts.map +1 -0
- package/dist/types/client/Transaction.d.ts +5 -5
- package/dist/types/client/Transaction.d.ts.map +1 -1
- package/dist/types/client/cancelRunningStatement.d.ts +7 -0
- package/dist/types/client/cancelRunningStatement.d.ts.map +1 -0
- package/dist/types/client/errors.d.ts +3 -0
- package/dist/types/client/errors.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +8 -7
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadata.d.ts +3 -3
- package/dist/types/metadata/DatabaseMetadata.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts +2 -2
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/types/metadata/ForeignKeyConstraintMetadata.d.ts.map +1 -1
- package/dist/types/metadata/IndexMetadata.d.ts.map +1 -1
- package/dist/types/metadata/UniqueConstraintMetadata.d.ts.map +1 -1
- package/dist/types/metadata/index.d.ts +5 -5
- package/dist/types/metadata/index.d.ts.map +1 -1
- package/dist/types/metadata/stringArrayEquals.d.ts.map +1 -1
- package/dist/types/queryable/DatabaseQuery.d.ts +1 -1
- package/dist/types/queryable/DatabaseQuery.d.ts.map +1 -1
- package/dist/types/queryable/DatabaseQueryable.d.ts +1 -1
- package/dist/types/queryable/DatabaseQueryable.d.ts.map +1 -1
- package/dist/types/queryable/index.d.ts +2 -2
- package/dist/types/queryable/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +16 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/ConstraintHelper.d.ts +2 -2
- package/dist/types/utils/ConstraintHelper.d.ts.map +1 -1
- package/dist/types/utils/Mutex.d.ts.map +1 -1
- package/dist/types/utils/Semaphore.d.ts +17 -0
- package/dist/types/utils/Semaphore.d.ts.map +1 -0
- package/dist/types/utils/createDatabaseIfNotExists.d.ts +1 -1
- package/dist/types/utils/createDatabaseIfNotExists.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +11 -10
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/listen.d.ts +1 -1
- package/dist/types/utils/listen.d.ts.map +1 -1
- package/dist/types/utils/pgClientFactory.d.ts +3 -3
- package/dist/types/utils/pgClientFactory.d.ts.map +1 -1
- package/dist/types/utils/retryTransaction.d.ts.map +1 -1
- package/dist/types/utils/sql.d.ts +1 -1
- package/dist/types/utils/sql.d.ts.map +1 -1
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts +1 -1
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/builders/CaseStatement.ts +3 -3
- package/src/builders/ColumnExpressionFactory.ts +7 -7
- package/src/builders/Compiler.ts +9 -9
- package/src/builders/ConditionBuilder.ts +13 -7
- package/src/builders/DeleteBuilder.ts +8 -8
- package/src/builders/InsertBuilder.ts +11 -11
- package/src/builders/LimitByGroupWrapper.ts +6 -6
- package/src/builders/QueryBuilder.ts +5 -5
- package/src/builders/SelectBuilder.ts +11 -11
- package/src/builders/UpdateBuilder.ts +10 -10
- package/src/builders/WindowFunction.ts +7 -6
- package/src/builders/index.ts +12 -12
- package/src/builders/internal/Returning.ts +4 -4
- package/src/builders/internal/Subqueries.ts +4 -4
- package/src/builders/internal/Where.ts +4 -4
- package/src/builders/internal/With.ts +4 -4
- package/src/builders/utils.ts +4 -4
- package/src/client/AcquiredConnection.ts +131 -39
- package/src/client/Client.ts +16 -6
- package/src/client/Connection.ts +27 -7
- package/src/client/EventManager.ts +12 -2
- package/src/client/PgClient.ts +16 -1
- package/src/client/Pool.ts +5 -5
- package/src/client/RequestMemoryBudget.ts +260 -0
- package/src/client/ScopeLimitedConnection.ts +65 -0
- package/src/client/Transaction.ts +24 -11
- package/src/client/cancelRunningStatement.ts +36 -0
- package/src/client/errors.ts +6 -0
- package/src/client/index.ts +8 -7
- package/src/index.ts +12 -10
- package/src/metadata/DatabaseMetadata.ts +3 -3
- package/src/metadata/DatabaseMetadataResolver.ts +5 -5
- package/src/metadata/IndexMetadata.ts +1 -1
- package/src/metadata/UniqueConstraintMetadata.ts +1 -1
- package/src/metadata/index.ts +5 -5
- package/src/queryable/DatabaseQuery.ts +2 -2
- package/src/queryable/DatabaseQueryable.ts +1 -1
- package/src/queryable/index.ts +2 -2
- package/src/types.ts +16 -0
- package/src/utils/ConstraintHelper.ts +3 -3
- package/src/utils/Semaphore.ts +49 -0
- package/src/utils/createDatabaseIfNotExists.ts +3 -3
- package/src/utils/index.ts +11 -10
- package/src/utils/listen.ts +2 -2
- package/src/utils/pgClientFactory.ts +18 -10
- package/src/utils/retryTransaction.ts +1 -1
- package/src/utils/sql.ts +1 -1
- package/src/utils/withDatabaseAdvisoryLock.ts +1 -1
- package/tests/cases/integration/requestMemoryBudget.test.ts +296 -0
- package/tests/cases/unit/acquiredConnection.test.ts +154 -0
- package/tests/cases/unit/connection.test.ts +34 -2
- package/tests/cases/unit/createConnectionMockAlt.ts +18 -4
- package/tests/cases/unit/eventManager.test.ts +2 -2
- package/tests/cases/unit/pool.test.ts +1 -1
- package/tests/cases/unit/queryBuilder.test.ts +29 -4
- package/tests/cases/unit/requestMemoryBudget.test.ts +287 -0
- package/tests/cases/unit/scopeLimitedConnection.test.ts +204 -0
- package/tests/cases/unit/semaphore.test.ts +53 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgClientFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/pgClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"pgClientFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/pgClientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAA;AAC5C,eAAO,MAAM,qBAAqB,0FACuD,cAAc,oBAcrG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryTransaction.d.ts","sourceRoot":"","sources":["../../../src/utils/retryTransaction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAQD,eAAO,MAAM,gBAAgB,GAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"retryTransaction.d.ts","sourceRoot":"","sources":["../../../src/utils/retryTransaction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;CAClB;AAQD,eAAO,MAAM,gBAAgB,GAAU,CAAC,MACnC,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,UAChB,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,YACxB,OAAO,CAAC,YAAY,CAAC,KAC5B,OAAO,CAAC,CAAC,CA4BX,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Literal } from '../Literal';
|
|
1
|
+
import { Literal } from '../Literal.js';
|
|
2
2
|
export declare const wrapIdentifier: (value: string) => string;
|
|
3
3
|
export declare const aliasLiteral: (raw: Literal, alias?: string) => Literal;
|
|
4
4
|
export declare const prependSchema: (tableExpression: string | Literal, schema: string, cteAliases: Set<string>) => Literal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../src/utils/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../../src/utils/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,eAAO,MAAM,cAAc,UAAW,MAAM,WAA0C,CAAA;AAEtF,eAAO,MAAM,YAAY,QAAS,OAAO,UAAU,MAAM,KAAG,OAK3D,CAAA;AAED,eAAO,MAAM,aAAa,oBAAqB,MAAM,GAAG,OAAO,UAAU,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,YASvG,CAAA;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAMpF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Connection } from '../client';
|
|
1
|
+
import { Connection } from '../client/index.js';
|
|
2
2
|
export declare const withDatabaseAdvisoryLock: <Result>(connection: Connection.ConnectionLike, lock: number, callback: () => Result | Promise<Result>) => Promise<Result>;
|
|
3
3
|
//# sourceMappingURL=withDatabaseAdvisoryLock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDatabaseAdvisoryLock.d.ts","sourceRoot":"","sources":["../../../src/utils/withDatabaseAdvisoryLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"withDatabaseAdvisoryLock.d.ts","sourceRoot":"","sources":["../../../src/utils/withDatabaseAdvisoryLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,eAAO,MAAM,wBAAwB,GAAU,MAAM,cACxC,UAAU,CAAC,cAAc,QAC/B,MAAM,YACF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KACtC,OAAO,CAAC,MAAM,CAWhB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/database",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.10",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@contember/queryable": "2.
|
|
26
|
+
"@contember/queryable": "2.2.0-alpha.10"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@contember/database-tester": "2.
|
|
29
|
+
"@contember/database-tester": "2.2.0-alpha.10",
|
|
30
30
|
"@types/node": "^24.12.0",
|
|
31
31
|
"pg": "^8.20.0"
|
|
32
32
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
2
|
-
import { Literal } from '../Literal'
|
|
3
|
-
import { columnExpressionToLiteral } from './utils'
|
|
1
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
2
|
+
import { Literal } from '../Literal.js'
|
|
3
|
+
import { columnExpressionToLiteral } from './utils.js'
|
|
4
4
|
|
|
5
5
|
class CaseStatement {
|
|
6
6
|
constructor(private readonly options: CaseStatement.Options) {}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
2
|
-
import { Literal } from '../Literal'
|
|
3
|
-
import { Value } from '../types'
|
|
4
|
-
import { ConditionBuilder, ConditionExpression } from './ConditionBuilder'
|
|
5
|
-
import { WindowFunction } from './WindowFunction'
|
|
6
|
-
import { CaseStatement } from './CaseStatement'
|
|
7
|
-
import { formatColumnIdentifier } from '../utils'
|
|
1
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
2
|
+
import { Literal } from '../Literal.js'
|
|
3
|
+
import { Value } from '../types.js'
|
|
4
|
+
import { ConditionBuilder, ConditionExpression } from './ConditionBuilder.js'
|
|
5
|
+
import { WindowFunction } from './WindowFunction.js'
|
|
6
|
+
import { CaseStatement } from './CaseStatement.js'
|
|
7
|
+
import { formatColumnIdentifier } from '../utils/index.js'
|
|
8
8
|
|
|
9
9
|
export class ColumnExpressionFactory {
|
|
10
10
|
public select(columnName: QueryBuilder.ColumnIdentifier): Literal {
|
package/src/builders/Compiler.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { aliasLiteral, assertNever, prependSchema, wrapIdentifier } from '../utils'
|
|
2
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
3
|
-
import { Literal } from '../Literal'
|
|
4
|
-
import { DeleteBuilder } from './DeleteBuilder'
|
|
5
|
-
import { InsertBuilder } from './InsertBuilder'
|
|
6
|
-
import { UpdateBuilder } from './UpdateBuilder'
|
|
7
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
8
|
-
import { LockType } from './LockType'
|
|
9
|
-
import { ConflictActionType } from './ConflictActionType'
|
|
1
|
+
import { aliasLiteral, assertNever, prependSchema, wrapIdentifier } from '../utils/index.js'
|
|
2
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
3
|
+
import { Literal } from '../Literal.js'
|
|
4
|
+
import { DeleteBuilder } from './DeleteBuilder.js'
|
|
5
|
+
import { InsertBuilder } from './InsertBuilder.js'
|
|
6
|
+
import { UpdateBuilder } from './UpdateBuilder.js'
|
|
7
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
8
|
+
import { LockType } from './LockType.js'
|
|
9
|
+
import { ConflictActionType } from './ConflictActionType.js'
|
|
10
10
|
|
|
11
11
|
class Compiler {
|
|
12
12
|
compileSelect(options: SelectBuilder.Options, namespaceContext: Compiler.Context): Literal {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Value } from '../types'
|
|
2
|
-
import { Literal } from '../Literal'
|
|
3
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
4
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
5
|
-
import { Compiler } from './Compiler'
|
|
6
|
-
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
|
|
7
|
-
import { formatColumnIdentifier } from '../utils'
|
|
1
|
+
import { Value } from '../types.js'
|
|
2
|
+
import { Literal } from '../Literal.js'
|
|
3
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
4
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
5
|
+
import { Compiler } from './Compiler.js'
|
|
6
|
+
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
|
|
7
|
+
import { formatColumnIdentifier } from '../utils/index.js'
|
|
8
8
|
|
|
9
9
|
export type ConditionCallback = (builder: ConditionBuilder) => ConditionBuilder
|
|
10
10
|
export type ConditionExpression = ConditionBuilder | ConditionCallback
|
|
@@ -22,6 +22,8 @@ export enum Operator {
|
|
|
22
22
|
'containsCI' = 'containsCI',
|
|
23
23
|
'startsWithCI' = 'startsWithCI',
|
|
24
24
|
'endsWithCI' = 'endsWithCI',
|
|
25
|
+
'similar' = 'similar',
|
|
26
|
+
'wordSimilar' = 'wordSimilar',
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const likeOperators: string[] = [
|
|
@@ -170,6 +172,10 @@ export class ConditionBuilder {
|
|
|
170
172
|
return `${left} LIKE '%' || ${right}`
|
|
171
173
|
case Operator.endsWithCI:
|
|
172
174
|
return `${left} ILIKE '%' || ${right}`
|
|
175
|
+
case Operator.similar:
|
|
176
|
+
return `${left} % ${right}`
|
|
177
|
+
case Operator.wordSimilar:
|
|
178
|
+
return `${right} <% ${left}`
|
|
173
179
|
}
|
|
174
180
|
return `${left} ${operator} ${right}`
|
|
175
181
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Returning } from './internal/Returning'
|
|
2
|
-
import { With } from './internal/With'
|
|
3
|
-
import { Where } from './internal/Where'
|
|
4
|
-
import { Compiler } from './Compiler'
|
|
5
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
6
|
-
import { Client, Connection } from '../client'
|
|
7
|
-
import { Literal } from '../Literal'
|
|
8
|
-
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
|
|
1
|
+
import { Returning } from './internal/Returning.js'
|
|
2
|
+
import { With } from './internal/With.js'
|
|
3
|
+
import { Where } from './internal/Where.js'
|
|
4
|
+
import { Compiler } from './Compiler.js'
|
|
5
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
6
|
+
import { Client, Connection } from '../client/index.js'
|
|
7
|
+
import { Literal } from '../Literal.js'
|
|
8
|
+
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
|
|
9
9
|
|
|
10
10
|
class DeleteBuilder<Result extends DeleteBuilder.DeleteResult> implements Returning.Aware, With.Aware, Where.Aware, QueryBuilder {
|
|
11
11
|
private constructor(private readonly options: DeleteBuilder.Options) {}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Returning } from './internal/Returning'
|
|
2
|
-
import { With } from './internal/With'
|
|
3
|
-
import { Compiler } from './Compiler'
|
|
4
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
5
|
-
import { Client, Connection } from '../client'
|
|
6
|
-
import { Literal } from '../Literal'
|
|
7
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
8
|
-
import { resolveValues } from './utils'
|
|
9
|
-
import { ConflictActionType } from './ConflictActionType'
|
|
10
|
-
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
|
|
11
|
-
import { Where } from './internal/Where'
|
|
1
|
+
import { Returning } from './internal/Returning.js'
|
|
2
|
+
import { With } from './internal/With.js'
|
|
3
|
+
import { Compiler } from './Compiler.js'
|
|
4
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
5
|
+
import { Client, Connection } from '../client/index.js'
|
|
6
|
+
import { Literal } from '../Literal.js'
|
|
7
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
8
|
+
import { resolveValues } from './utils.js'
|
|
9
|
+
import { ConflictActionType } from './ConflictActionType.js'
|
|
10
|
+
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
|
|
11
|
+
import { Where } from './internal/Where.js'
|
|
12
12
|
|
|
13
13
|
class InsertBuilder<Result extends InsertBuilder.InsertResult> implements With.Aware, QueryBuilder {
|
|
14
14
|
private constructor(private readonly options: InsertBuilder.Options) {}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
2
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
3
|
-
import { Operator } from './ConditionBuilder'
|
|
4
|
-
import { Client } from '../client'
|
|
5
|
-
import { WindowFunction } from './WindowFunction'
|
|
1
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
2
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
3
|
+
import { Operator } from './ConditionBuilder.js'
|
|
4
|
+
import { Client } from '../client/index.js'
|
|
5
|
+
import { WindowFunction } from './WindowFunction.js'
|
|
6
6
|
|
|
7
7
|
type OrderByCallback = <Orderable extends QueryBuilder.Orderable<any> | null>(
|
|
8
8
|
orderable: Orderable,
|
|
@@ -42,7 +42,7 @@ class LimitByGroupWrapper {
|
|
|
42
42
|
wrapperQb = wrapperQb.where(expr => expr.compare(['data', 'rowNumber_'], Operator.lte, start + limit))
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
return await wrapperQb.getResult(db)
|
|
45
|
+
return await wrapperQb.orderBy(['data', 'rowNumber_']).getResult(db)
|
|
46
46
|
} else if (this.orderByCallback) {
|
|
47
47
|
return await this.orderByCallback(null, qb)[1].getResult(db)
|
|
48
48
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Literal } from '../Literal'
|
|
2
|
-
import { Value } from '../types'
|
|
3
|
-
import { ColumnExpressionFactory } from './ColumnExpressionFactory'
|
|
4
|
-
import { Compiler } from './Compiler'
|
|
5
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
1
|
+
import { Literal } from '../Literal.js'
|
|
2
|
+
import { Value } from '../types.js'
|
|
3
|
+
import { ColumnExpressionFactory } from './ColumnExpressionFactory.js'
|
|
4
|
+
import { Compiler } from './Compiler.js'
|
|
5
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
6
6
|
|
|
7
7
|
interface QueryBuilder {
|
|
8
8
|
createQuery(context: Compiler.Context): Literal
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { With } from './internal/With'
|
|
2
|
-
import { Where } from './internal/Where'
|
|
3
|
-
import { aliasLiteral, formatColumnIdentifier } from '../utils'
|
|
4
|
-
import { Compiler } from './Compiler'
|
|
5
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
6
|
-
import { Client, Connection } from '../client'
|
|
7
|
-
import { Literal } from '../Literal'
|
|
8
|
-
import { ConditionBuilder, ConditionExpression } from './ConditionBuilder'
|
|
9
|
-
import { LockModifier, LockType } from './LockType'
|
|
10
|
-
import { columnExpressionToLiteral } from './utils'
|
|
11
|
-
import { createSubQueryLiteralFactory, SubQueryExpression, SubQueryLiteralFactory } from './internal/Subqueries'
|
|
1
|
+
import { With } from './internal/With.js'
|
|
2
|
+
import { Where } from './internal/Where.js'
|
|
3
|
+
import { aliasLiteral, formatColumnIdentifier } from '../utils/index.js'
|
|
4
|
+
import { Compiler } from './Compiler.js'
|
|
5
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
6
|
+
import { Client, Connection } from '../client/index.js'
|
|
7
|
+
import { Literal } from '../Literal.js'
|
|
8
|
+
import { ConditionBuilder, ConditionExpression } from './ConditionBuilder.js'
|
|
9
|
+
import { LockModifier, LockType } from './LockType.js'
|
|
10
|
+
import { columnExpressionToLiteral } from './utils.js'
|
|
11
|
+
import { createSubQueryLiteralFactory, SubQueryExpression, SubQueryLiteralFactory } from './internal/Subqueries.js'
|
|
12
12
|
|
|
13
13
|
export type SelectBuilderSpecification = <Result>(qb: SelectBuilder<Result>) => SelectBuilder<Result>
|
|
14
14
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Returning } from './internal/Returning'
|
|
2
|
-
import { With } from './internal/With'
|
|
3
|
-
import { Where } from './internal/Where'
|
|
4
|
-
import { Compiler } from './Compiler'
|
|
5
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
6
|
-
import { Client, Connection } from '../client'
|
|
7
|
-
import { Literal } from '../Literal'
|
|
8
|
-
import { SelectBuilder } from './SelectBuilder'
|
|
9
|
-
import { resolveValues } from './utils'
|
|
10
|
-
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries'
|
|
1
|
+
import { Returning } from './internal/Returning.js'
|
|
2
|
+
import { With } from './internal/With.js'
|
|
3
|
+
import { Where } from './internal/Where.js'
|
|
4
|
+
import { Compiler } from './Compiler.js'
|
|
5
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
6
|
+
import { Client, Connection } from '../client/index.js'
|
|
7
|
+
import { Literal } from '../Literal.js'
|
|
8
|
+
import { SelectBuilder } from './SelectBuilder.js'
|
|
9
|
+
import { resolveValues } from './utils.js'
|
|
10
|
+
import { createSubQueryLiteralFactory, SubQueryExpression } from './internal/Subqueries.js'
|
|
11
11
|
|
|
12
12
|
class UpdateBuilder<Result extends UpdateBuilder.UpdateResult> implements With.Aware, Where.Aware, QueryBuilder {
|
|
13
13
|
private constructor(private readonly options: UpdateBuilder.Options) {}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
2
|
-
import { Literal } from '../Literal'
|
|
3
|
-
import { columnExpressionToLiteral } from './utils'
|
|
4
|
-
import { formatColumnIdentifier } from '../utils'
|
|
1
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
2
|
+
import { Literal } from '../Literal.js'
|
|
3
|
+
import { columnExpressionToLiteral } from './utils.js'
|
|
4
|
+
import { formatColumnIdentifier } from '../utils/index.js'
|
|
5
|
+
import type { SelectBuilder } from './SelectBuilder.js'
|
|
5
6
|
|
|
6
7
|
class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Orderable<WindowFunction<HasFunction>> {
|
|
7
8
|
private constructor(
|
|
@@ -30,12 +31,12 @@ class WindowFunction<HasFunction extends boolean> implements QueryBuilder.Ordera
|
|
|
30
31
|
|
|
31
32
|
orderBy(
|
|
32
33
|
expression: QueryBuilder.ColumnIdentifier | Literal,
|
|
33
|
-
direction:
|
|
34
|
+
direction: SelectBuilder.OrderByDirection = 'asc',
|
|
34
35
|
): WindowFunction<HasFunction> {
|
|
35
36
|
const raw = expression instanceof Literal ? expression : new Literal(formatColumnIdentifier(expression))
|
|
36
37
|
return new WindowFunction(this.windowFunction, this.partitionByExpr, [
|
|
37
38
|
...this.orderByColumns,
|
|
38
|
-
raw.appendString(direction
|
|
39
|
+
raw.appendString(` ${direction}`),
|
|
39
40
|
])
|
|
40
41
|
}
|
|
41
42
|
|
package/src/builders/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './Compiler'
|
|
2
|
-
export * from './CaseStatement'
|
|
3
|
-
export * from './ConditionBuilder'
|
|
4
|
-
export * from './DeleteBuilder'
|
|
5
|
-
export * from './InsertBuilder'
|
|
6
|
-
export * from './LimitByGroupWrapper'
|
|
7
|
-
export * from './QueryBuilder'
|
|
8
|
-
export * from './SelectBuilder'
|
|
9
|
-
export * from './UpdateBuilder'
|
|
10
|
-
export * from './WindowFunction'
|
|
11
|
-
export * from './LockType'
|
|
12
|
-
export * from './ConflictActionType'
|
|
1
|
+
export * from './Compiler.js'
|
|
2
|
+
export * from './CaseStatement.js'
|
|
3
|
+
export * from './ConditionBuilder.js'
|
|
4
|
+
export * from './DeleteBuilder.js'
|
|
5
|
+
export * from './InsertBuilder.js'
|
|
6
|
+
export * from './LimitByGroupWrapper.js'
|
|
7
|
+
export * from './QueryBuilder.js'
|
|
8
|
+
export * from './SelectBuilder.js'
|
|
9
|
+
export * from './UpdateBuilder.js'
|
|
10
|
+
export * from './WindowFunction.js'
|
|
11
|
+
export * from './LockType.js'
|
|
12
|
+
export * from './ConflictActionType.js'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { QueryBuilder } from '../'
|
|
2
|
-
import { Literal } from '../../Literal'
|
|
3
|
-
import { Connection } from '../../client'
|
|
4
|
-
import { formatColumnIdentifier } from '../../utils'
|
|
1
|
+
import { QueryBuilder } from '../index.js'
|
|
2
|
+
import { Literal } from '../../Literal.js'
|
|
3
|
+
import { Connection } from '../../client/index.js'
|
|
4
|
+
import { formatColumnIdentifier } from '../../utils/index.js'
|
|
5
5
|
|
|
6
6
|
class Returning {
|
|
7
7
|
constructor(private readonly columns: (QueryBuilder.ColumnIdentifier | Literal)[] = []) {}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Compiler } from '../Compiler'
|
|
2
|
-
import { Literal } from '../../Literal'
|
|
3
|
-
import { SelectBuilder } from '../SelectBuilder'
|
|
4
|
-
import { QueryBuilder } from '../QueryBuilder'
|
|
1
|
+
import { Compiler } from '../Compiler.js'
|
|
2
|
+
import { Literal } from '../../Literal.js'
|
|
3
|
+
import { SelectBuilder } from '../SelectBuilder.js'
|
|
4
|
+
import { QueryBuilder } from '../QueryBuilder.js'
|
|
5
5
|
|
|
6
6
|
export type SubQueryLiteralFactory<Builder extends QueryBuilder = QueryBuilder> = (
|
|
7
7
|
context: Compiler.Context,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { wrapIdentifier } from '../../utils'
|
|
2
|
-
import { Literal } from '../../Literal'
|
|
3
|
-
import { ConditionBuilder, ConditionCallback } from '../ConditionBuilder'
|
|
4
|
-
import { Value } from '../../types'
|
|
1
|
+
import { wrapIdentifier } from '../../utils/index.js'
|
|
2
|
+
import { Literal } from '../../Literal.js'
|
|
3
|
+
import { ConditionBuilder, ConditionCallback } from '../ConditionBuilder.js'
|
|
4
|
+
import { Value } from '../../types.js'
|
|
5
5
|
|
|
6
6
|
namespace Where {
|
|
7
7
|
export interface Options {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { wrapIdentifier } from '../../utils'
|
|
2
|
-
import { Literal } from '../../Literal'
|
|
3
|
-
import { Compiler } from '../Compiler'
|
|
4
|
-
import { SubQueryExpression, SubQueryLiteralFactory } from './Subqueries'
|
|
1
|
+
import { wrapIdentifier } from '../../utils/index.js'
|
|
2
|
+
import { Literal } from '../../Literal.js'
|
|
3
|
+
import { Compiler } from '../Compiler.js'
|
|
4
|
+
import { SubQueryExpression, SubQueryLiteralFactory } from './Subqueries.js'
|
|
5
5
|
|
|
6
6
|
namespace With {
|
|
7
7
|
type CteOptions = {
|
package/src/builders/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Literal } from '../Literal'
|
|
2
|
-
import { QueryBuilder } from './QueryBuilder'
|
|
3
|
-
import { ColumnExpressionFactory } from './ColumnExpressionFactory'
|
|
4
|
-
import { formatColumnIdentifier } from '../utils'
|
|
1
|
+
import { Literal } from '../Literal.js'
|
|
2
|
+
import { QueryBuilder } from './QueryBuilder.js'
|
|
3
|
+
import { ColumnExpressionFactory } from './ColumnExpressionFactory.js'
|
|
4
|
+
import { formatColumnIdentifier } from '../utils/index.js'
|
|
5
5
|
|
|
6
6
|
export function resolveValues(values: QueryBuilder.Values): QueryBuilder.ResolvedValues {
|
|
7
7
|
return Object.entries(values)
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { Connection } from './Connection'
|
|
2
|
-
import { EventManager } from './EventManager'
|
|
3
|
-
import { Mutex } from '../utils'
|
|
4
|
-
import { executeTransaction, Transaction } from './Transaction'
|
|
5
|
-
import { ClientErrorCodes } from './errorCodes'
|
|
1
|
+
import { Connection } from './Connection.js'
|
|
2
|
+
import { EventManager } from './EventManager.js'
|
|
3
|
+
import { Mutex, MutexDeadlockError } from '../utils/index.js'
|
|
4
|
+
import { executeTransaction, Transaction } from './Transaction.js'
|
|
5
|
+
import { ClientErrorCodes } from './errorCodes.js'
|
|
6
6
|
import {
|
|
7
7
|
ForeignKeyViolationError,
|
|
8
8
|
InvalidDataError,
|
|
9
9
|
NotNullViolationError,
|
|
10
10
|
QueryError,
|
|
11
11
|
SerializationFailureError,
|
|
12
|
+
TerminatedConnectionError,
|
|
12
13
|
TransactionAbortedError,
|
|
13
14
|
UniqueViolationError,
|
|
14
|
-
} from './errors'
|
|
15
|
-
import { PgClient } from './PgClient'
|
|
16
|
-
import {
|
|
15
|
+
} from './errors.js'
|
|
16
|
+
import { PgClient } from './PgClient.js'
|
|
17
|
+
import { cancelRunningStatement } from './cancelRunningStatement.js'
|
|
18
|
+
import { Notification, Query, QueryResult, QueryResultRow } from 'pg'
|
|
19
|
+
import { RequestMemoryBudget, RequestMemoryBudgetExceededError } from './RequestMemoryBudget.js'
|
|
17
20
|
|
|
18
21
|
export class AcquiredConnection implements Connection.AcquiredConnectionLike {
|
|
19
22
|
private mutex = new Mutex()
|
|
@@ -21,6 +24,7 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
|
|
|
21
24
|
constructor(
|
|
22
25
|
private readonly pgClient: PgClient,
|
|
23
26
|
public readonly eventManager: EventManager,
|
|
27
|
+
private readonly physicalConnection = { terminated: false },
|
|
24
28
|
) {
|
|
25
29
|
}
|
|
26
30
|
|
|
@@ -29,7 +33,7 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
|
|
|
29
33
|
options: { eventManager?: EventManager } = {},
|
|
30
34
|
): Promise<Result> {
|
|
31
35
|
return await this.mutex.execute(async () => {
|
|
32
|
-
return await callback(new AcquiredConnection(this.pgClient, options.eventManager ?? this.eventManager))
|
|
36
|
+
return await callback(new AcquiredConnection(this.pgClient, options.eventManager ?? this.eventManager, this.physicalConnection))
|
|
33
37
|
})
|
|
34
38
|
}
|
|
35
39
|
|
|
@@ -49,51 +53,139 @@ export class AcquiredConnection implements Connection.AcquiredConnectionLike {
|
|
|
49
53
|
parameters: any[] = [],
|
|
50
54
|
meta: Record<string, any> = {},
|
|
51
55
|
): Promise<Connection.Result<Row>> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
// A refusal before queryStart fires no event, so cleanup on a terminated connection stays out of query error metrics.
|
|
57
|
+
this.refuseExhaustedOrTerminated()
|
|
58
|
+
|
|
59
|
+
const query: Connection.Query = { sql, parameters, meta }
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
try {
|
|
62
|
+
this.eventManager.fire(EventManager.Event.queryStart, query)
|
|
63
|
+
|
|
64
|
+
const result = await this.mutex.execute(async (): Promise<Connection.Result<Row>> => {
|
|
65
|
+
// A query queued behind the one that exhausted the budget reports the budget, not the terminated connection.
|
|
66
|
+
this.refuseExhaustedOrTerminated()
|
|
67
|
+
const memoryBudget = this.eventManager.memoryBudget
|
|
57
68
|
const startHrTime = process.hrtime.bigint()
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
const pgResult = memoryBudget && this.eventManager.chargesMemoryBudget
|
|
71
|
+
? await this.queryWithMemoryBudget<Row>(prepareSql(sql), parameters, memoryBudget)
|
|
72
|
+
: await this.pgClient.query(prepareSql(sql), parameters)
|
|
60
73
|
|
|
61
74
|
const endHrTime = process.hrtime.bigint()
|
|
62
75
|
const durationUs = Math.floor(Number(endHrTime - startHrTime) / 1000)
|
|
63
|
-
|
|
64
|
-
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
...pgResult,
|
|
65
79
|
timing: {
|
|
66
80
|
selfDuration: durationUs,
|
|
67
81
|
totalDuration: durationUs,
|
|
68
82
|
},
|
|
69
83
|
}
|
|
84
|
+
})
|
|
70
85
|
|
|
71
|
-
|
|
86
|
+
this.eventManager.fire(EventManager.Event.queryEnd, query, result)
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
return result
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!(error instanceof Error)) {
|
|
91
|
+
throw error
|
|
92
|
+
}
|
|
93
|
+
this.eventManager.fire(EventManager.Event.queryError, query, error)
|
|
94
|
+
|
|
95
|
+
// neither a mutex deadlock nor a budget refusal is a postgres failure, keep them untranslated
|
|
96
|
+
if (error instanceof MutexDeadlockError || error instanceof RequestMemoryBudgetExceededError || error instanceof TerminatedConnectionError) {
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
switch ((error as any).code) {
|
|
101
|
+
case ClientErrorCodes.NOT_NULL_VIOLATION:
|
|
102
|
+
throw new NotNullViolationError(sql, parameters, error)
|
|
103
|
+
case ClientErrorCodes.FOREIGN_KEY_VIOLATION:
|
|
104
|
+
throw new ForeignKeyViolationError(sql, parameters, error)
|
|
105
|
+
case ClientErrorCodes.UNIQUE_VIOLATION:
|
|
106
|
+
throw new UniqueViolationError(sql, parameters, error)
|
|
107
|
+
case ClientErrorCodes.T_R_SERIALIZATION_FAILURE:
|
|
108
|
+
throw new SerializationFailureError(sql, parameters, error)
|
|
109
|
+
case ClientErrorCodes.INVALID_TEXT_REPRESENTATION:
|
|
110
|
+
case ClientErrorCodes.DATETIME_FIELD_OVERFLOW:
|
|
111
|
+
throw new InvalidDataError(sql, parameters, error)
|
|
112
|
+
case ClientErrorCodes.IN_FAILED_SQL_TRANSACTION:
|
|
113
|
+
throw new TransactionAbortedError(sql, parameters, error)
|
|
114
|
+
default:
|
|
115
|
+
throw new QueryError(sql, parameters, error)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private refuseExhaustedOrTerminated(): void {
|
|
121
|
+
// The budget goes first: a connection the budget terminated reports the budget to every query still bound to it.
|
|
122
|
+
this.eventManager.memoryBudget?.check()
|
|
123
|
+
if (this.physicalConnection.terminated) {
|
|
124
|
+
throw new TerminatedConnectionError()
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async queryWithMemoryBudget<Row extends QueryResultRow>(
|
|
129
|
+
sql: string,
|
|
130
|
+
parameters: unknown[],
|
|
131
|
+
budget: RequestMemoryBudget,
|
|
132
|
+
): Promise<Connection.Result<Row>> {
|
|
133
|
+
return await new Promise<Connection.Result<Row>>((resolve, reject) => {
|
|
134
|
+
let rows: Row[] | undefined
|
|
135
|
+
let failure: Error | undefined
|
|
136
|
+
let cleanup = () => {}
|
|
137
|
+
const stop = (error: Error) => {
|
|
138
|
+
failure = error
|
|
139
|
+
if (rows) {
|
|
140
|
+
rows.length = 0
|
|
77
141
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
142
|
+
cleanup()
|
|
143
|
+
// A budget failure invalidates this connection; the enclosing pool scope disposes it.
|
|
144
|
+
this.physicalConnection.terminated = true
|
|
145
|
+
// Ending the socket alone leaves a statement still waiting for its first row running on the server.
|
|
146
|
+
// Cancelling is best effort and must not mask the budget error.
|
|
147
|
+
void cancelRunningStatement(this.pgClient).catch(() => {})
|
|
148
|
+
void this.pgClient.end().catch(reject)
|
|
149
|
+
reject(error)
|
|
150
|
+
}
|
|
151
|
+
const config = {
|
|
152
|
+
text: sql,
|
|
153
|
+
values: parameters,
|
|
154
|
+
callback: (error: Error | null, result?: QueryResult<Row>) => {
|
|
155
|
+
cleanup()
|
|
156
|
+
if (failure || error) {
|
|
157
|
+
reject(failure || error)
|
|
158
|
+
} else if (result) {
|
|
159
|
+
resolve(result)
|
|
160
|
+
} else {
|
|
161
|
+
reject(new Error('PostgreSQL query completed without a result'))
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
const query = new Query<Row>(config)
|
|
166
|
+
// A sibling query of the request may exhaust the budget while this one still waits for its first row.
|
|
167
|
+
cleanup = budget.onExceeded(stop)
|
|
168
|
+
query.on('row', (row, result) => {
|
|
169
|
+
rows = result?.rows
|
|
170
|
+
if (failure) {
|
|
171
|
+
if (rows) {
|
|
172
|
+
rows.length = 0
|
|
173
|
+
}
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
budget.addDatabaseRow(row)
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (!failure) {
|
|
180
|
+
stop(error instanceof Error ? error : new Error('Failed to account for database row', { cause: error }))
|
|
181
|
+
}
|
|
96
182
|
}
|
|
183
|
+
})
|
|
184
|
+
try {
|
|
185
|
+
this.pgClient.query(query)
|
|
186
|
+
} catch (error) {
|
|
187
|
+
cleanup()
|
|
188
|
+
reject(error)
|
|
97
189
|
}
|
|
98
190
|
})
|
|
99
191
|
}
|