@getstrata/core 2.2.60 → 3.0.3
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/CHANGELOG.md +22 -0
- package/dist/core/audit/exportAuditLogs.d.ts +12 -3
- package/dist/core/audit/exportStore.d.ts +6 -2
- package/dist/core/audit/siemFormatter.d.ts +2 -2
- package/dist/core/auth/abilityCatalog.d.ts +1 -9
- package/dist/core/auth/authContext.d.ts +2 -0
- package/dist/core/auth/authOutcome.d.ts +32 -0
- package/dist/core/auth/authReader.d.ts +22 -0
- package/dist/core/auth/basicAuthGuard.d.ts +19 -3
- package/dist/core/auth/emailVerification.d.ts +1 -1
- package/dist/core/auth/guard.d.ts +27 -6
- package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
- package/dist/core/auth/jwt.d.ts +5 -4
- package/dist/core/auth/jwtGuard.d.ts +7 -6
- package/dist/core/auth/membershipContext.d.ts +10 -7
- package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
- package/dist/core/auth/membershipMiddleware.d.ts +1 -2
- package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
- package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
- package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
- package/dist/core/auth/oauth/providers.d.ts +3 -1
- package/dist/core/auth/oneTimeToken.d.ts +2 -3
- package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
- package/dist/core/auth/passwordLogin.d.ts +5 -5
- package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
- package/dist/core/auth/policy.d.ts +23 -10
- package/dist/core/auth/requireAuthCapability.d.ts +3 -0
- package/dist/core/auth/resolveMembershipService.d.ts +3 -2
- package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
- package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
- package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
- package/dist/core/auth/sessionCookie.d.ts +20 -9
- package/dist/core/auth/sessionGuard.d.ts +14 -3
- package/dist/core/cache/createCacheStore.d.ts +6 -3
- package/dist/core/cache/redisCacheStore.d.ts +5 -1
- package/dist/core/cache/repository.d.ts +5 -1
- package/dist/core/cache/simpleCache.d.ts +2 -1
- package/dist/core/cache/tokens.d.ts +8 -0
- package/dist/core/config/applicationConfig.d.ts +21 -0
- package/dist/core/config/configSnapshot.d.ts +3 -0
- package/dist/core/config/envSchema.d.ts +3 -2
- package/dist/core/contracts/application.d.ts +153 -0
- package/dist/core/contracts/authUserDirectory.d.ts +24 -7
- package/dist/core/contracts/container.d.ts +20 -23
- package/dist/core/contracts/di.d.ts +4 -2
- package/dist/core/contracts/executionContext.d.ts +5 -0
- package/dist/core/contracts/executionOperations.d.ts +10 -0
- package/dist/core/contracts/executionOwnership.d.ts +38 -0
- package/dist/core/contracts/persistence.d.ts +20 -0
- package/dist/core/contracts/serviceTokens.d.ts +32 -18
- package/dist/core/contracts/services.d.ts +63 -0
- package/dist/core/contracts/token.d.ts +19 -0
- package/dist/core/crypto/fieldEncryption.d.ts +19 -7
- package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
- package/dist/core/crypto/mfaSecret.d.ts +10 -3
- package/dist/core/database/baseRepository.d.ts +14 -10
- package/dist/core/database/bindings.d.ts +6 -0
- package/dist/core/database/bunSql.d.ts +3 -12
- package/dist/core/database/definitions.d.ts +209 -0
- package/dist/core/database/dialect.d.ts +5 -24
- package/dist/core/database/driverPorts.d.ts +116 -0
- package/dist/core/database/errors.d.ts +47 -7
- package/dist/core/database/factory.d.ts +51 -31
- package/dist/core/database/index.d.ts +9 -10
- package/dist/core/database/keyset.d.ts +2 -1
- package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
- package/dist/core/database/manager.d.ts +12 -0
- package/dist/core/database/model.d.ts +91 -97
- package/dist/core/database/modelQuery.d.ts +9 -5
- package/dist/core/database/modelRegistry.d.ts +52 -33
- package/dist/core/database/mysqlConnection.d.ts +1 -19
- package/dist/core/database/mysqlNative.d.ts +38 -0
- package/dist/core/database/nativeTransactions.d.ts +16 -0
- package/dist/core/database/ormInternal.d.ts +85 -0
- package/dist/core/database/ormRuntime.d.ts +4 -0
- package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
- package/dist/core/database/postgresNative.d.ts +11 -0
- package/dist/core/database/query.d.ts +24 -23
- package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
- package/dist/core/database/rawMysql.d.ts +7 -0
- package/dist/core/database/rawPostgres.d.ts +23 -0
- package/dist/core/database/rawSqlite.d.ts +6 -0
- package/dist/core/database/relationQueries.d.ts +3 -2
- package/dist/core/database/relationQuery.d.ts +24 -6
- package/dist/core/database/repositoryQuery.d.ts +6 -1
- package/dist/core/database/schema/driver.d.ts +1 -1
- package/dist/core/database/seeders/types.d.ts +1 -1
- package/dist/core/database/session.d.ts +13 -0
- package/dist/core/database/sessionFactory.d.ts +9 -0
- package/dist/core/database/sqlDialects.d.ts +22 -0
- package/dist/core/database/tokens.d.ts +7 -0
- package/dist/core/database/transactionSession.d.ts +43 -0
- package/dist/core/errors/http.d.ts +4 -1
- package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
- package/dist/core/events/index.d.ts +2 -3
- package/dist/core/events/outbox/index.d.ts +44 -13
- package/dist/core/events/outbox/metrics.d.ts +4 -4
- package/dist/core/events/outbox/workerTransport.d.ts +17 -0
- package/dist/core/http/authMiddleware.d.ts +2 -2
- package/dist/core/http/authorizeMiddleware.d.ts +2 -2
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
- package/dist/core/http/conditionalResponse.d.ts +7 -2
- package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
- package/dist/core/http/corsMiddleware.d.ts +2 -1
- package/dist/core/http/csrfMiddleware.d.ts +6 -1
- package/dist/core/http/csrfToken.d.ts +17 -7
- package/dist/core/http/databaseError.d.ts +4 -0
- package/dist/core/http/etag.d.ts +5 -2
- package/dist/core/http/flashMiddleware.d.ts +1 -1
- package/dist/core/http/flashSession.d.ts +13 -7
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
- package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
- package/dist/core/http/parseMultipartUpload.d.ts +3 -2
- package/dist/core/http/requestMetaContext.d.ts +5 -0
- package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
- package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
- package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
- package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
- package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
- package/dist/core/http/response.d.ts +4 -3
- package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
- package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
- package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
- package/dist/core/http/signedUrl.d.ts +8 -6
- package/dist/core/http/throttleMiddleware.d.ts +9 -5
- package/dist/core/http/uploads.d.ts +9 -3
- package/dist/core/http/webErrorResponse.d.ts +8 -2
- package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
- package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
- package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
- package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
- package/dist/core/mail/mailer.d.ts +7 -5
- package/dist/core/openapi/generator.d.ts +12 -4
- package/dist/core/openapi/registeredRoute.d.ts +4 -4
- package/dist/core/queue/createAppQueue.d.ts +9 -4
- package/dist/core/queue/failedJobMetrics.d.ts +11 -2
- package/dist/core/queue/failedJobRepository.d.ts +6 -3
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/core/queue/index.d.ts +16 -6
- package/dist/core/queue/jobRegistry.d.ts +3 -2
- package/dist/core/queue/jobRunner.d.ts +10 -4
- package/dist/core/queue/publicQueue.d.ts +18 -9
- package/dist/core/queue/queueConfig.d.ts +20 -10
- package/dist/core/queue/queueHandoff.d.ts +31 -0
- package/dist/core/queue/queueMetrics.d.ts +10 -3
- package/dist/core/queue/queueServices.d.ts +28 -0
- package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
- package/dist/core/queue/redisQueue.d.ts +19 -10
- package/dist/core/queue/redisQueueKeys.d.ts +5 -5
- package/dist/core/queue/redisStreams.d.ts +17 -10
- package/dist/core/queue/resilientQueue.d.ts +10 -4
- package/dist/core/queue/types.d.ts +1 -0
- package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
- package/dist/core/runtime/application.d.ts +7 -0
- package/dist/core/runtime/executionContext.d.ts +9 -0
- package/dist/core/runtime/executionTasks.d.ts +49 -0
- package/dist/core/runtime/resourceJournal.d.ts +67 -0
- package/dist/core/runtime/serviceGraph.d.ts +14 -0
- package/dist/core/security/oauthState.d.ts +13 -9
- package/dist/core/security/publicReads.d.ts +2 -2
- package/dist/core/security/safeFetch.d.ts +1 -0
- package/dist/core/security/safeUrl.d.ts +3 -0
- package/dist/core/security/scimTenantTokens.d.ts +1 -1
- package/dist/core/security/tokenExpiry.d.ts +1 -1
- package/dist/core/security/webhookSignature.d.ts +1 -1
- package/dist/core/storage/storage.d.ts +24 -16
- package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
- package/dist/core/tenant/resolveTenant.d.ts +2 -2
- package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
- package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
- package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
- package/dist/core/tracing/otel.d.ts +4 -6
- package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
- package/dist/core/view/etaViewEngine.d.ts +1 -1
- package/dist/core/view/index.d.ts +5 -4
- package/dist/core/view/tokens.d.ts +8 -0
- package/dist/core/view/viewRenderer.d.ts +2 -2
- package/dist/core/view/webErrorView.d.ts +8 -7
- package/dist/core/view/webLayoutData.d.ts +6 -4
- package/dist/entries/audit/exportAuditLogs.js +87 -1024
- package/dist/entries/audit/siemFormatter.js +4 -90
- package/dist/entries/auth/abilityCatalog.js +28 -0
- package/dist/entries/auth/accessControl.js +5 -16
- package/dist/entries/auth/accountStateMigration.js +216 -236
- package/dist/entries/auth/authOutcome.js +80 -0
- package/dist/entries/auth/authReader.js +68 -0
- package/dist/entries/auth/basicAuthGuard.js +144 -1249
- package/dist/entries/auth/emailVerification.js +2 -2
- package/dist/entries/auth/intendedUrlCookie.js +35 -59
- package/dist/entries/auth/jwt.js +22 -47
- package/dist/entries/auth/jwtGuard.js +99 -231
- package/dist/entries/auth/membershipMiddleware.js +71 -10
- package/dist/entries/auth/membershipScope.js +16 -22
- package/dist/entries/auth/membershipService.js +11 -28
- package/dist/entries/auth/oauth/oidcProvider.js +59 -64
- package/dist/entries/auth/oauth/providers.js +12 -95
- package/dist/entries/auth/oauth/samlProvider.js +53 -1080
- package/dist/entries/auth/oneTimeToken.js +27 -289
- package/dist/entries/auth/passwordConfirmCookie.js +40 -63
- package/dist/entries/auth/passwordLogin.js +94 -399
- package/dist/entries/auth/pendingMfaCookie.js +6 -6
- package/dist/entries/auth/policy.js +22 -56
- package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
- package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
- package/dist/entries/auth/sessionCookie.js +58 -73
- package/dist/entries/auth/sessionGuard.js +95 -248
- package/dist/entries/auth/tokenHash.js +11 -43
- package/dist/entries/cache/createCacheStore.js +126 -117
- package/dist/entries/cache/repository.js +25 -0
- package/dist/entries/cache/simpleCache.js +12 -7
- package/dist/entries/cache/tokens.js +9 -0
- package/dist/entries/config/applicationConfig.js +163 -0
- package/dist/entries/config/envSchema.js +21 -4
- package/dist/entries/contracts/application.js +1 -0
- package/dist/entries/contracts/authUserDirectory.js +10 -0
- package/dist/entries/contracts/container.js +99 -26
- package/dist/entries/contracts/di.js +3 -0
- package/dist/entries/contracts/executionContext.js +7 -0
- package/dist/entries/contracts/executionOperations.js +7 -0
- package/dist/entries/contracts/executionOwnership.js +7 -0
- package/dist/entries/contracts/membership.js +1 -0
- package/dist/entries/contracts/persistence.js +1 -0
- package/dist/entries/contracts/serviceTokens.js +26 -116
- package/dist/entries/contracts/services.js +98 -0
- package/dist/entries/contracts/token.js +41 -0
- package/dist/entries/crypto/fieldEncryption.js +49 -50
- package/dist/entries/crypto/mfaSecret.js +86 -82
- package/dist/entries/database/acquisitionMetrics.js +107 -0
- package/dist/entries/database/baseRepository.d.ts +2 -0
- package/dist/entries/database/bindings.js +2082 -0
- package/dist/entries/database/definitions.js +175 -0
- package/dist/entries/database/errors.js +114 -89
- package/dist/entries/database/factory.js +67 -28
- package/dist/entries/database/migrations.js +172 -224
- package/dist/entries/database/model.d.ts +1 -0
- package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
- package/dist/entries/database/query.js +159 -161
- package/dist/entries/database/repositoryQuery.d.ts +1 -0
- package/dist/entries/database/repositoryQuery.js +1 -1373
- package/dist/entries/database/schema.js +216 -236
- package/dist/entries/database/session.js +1 -0
- package/dist/entries/database/sqliteConnection.js +525 -83
- package/dist/entries/database/tokens.js +9 -0
- package/dist/entries/errors/http.js +118 -1
- package/dist/entries/http/authMiddleware.js +8 -5
- package/dist/entries/http/authorizeMiddleware.js +1 -1
- package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
- package/dist/entries/http/clientIp.js +2 -2
- package/dist/entries/http/conditionalResponse.js +19 -7
- package/dist/entries/http/corsMiddleware.js +6 -101
- package/dist/entries/http/csrfMiddleware.js +92 -106
- package/dist/entries/http/csrfToken.js +58 -94
- package/dist/entries/http/etag.js +7 -4
- package/dist/entries/http/flashMiddleware.js +57 -99
- package/dist/entries/http/flashSession.js +41 -68
- package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
- package/dist/entries/http/metricsMiddleware.js +2 -16
- package/dist/entries/http/parseMultipartUpload.js +15 -29
- package/dist/entries/http/requireAbilityMiddleware.js +2 -2
- package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
- package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
- package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
- package/dist/entries/http/response.js +67 -233
- package/dist/entries/http/routeMiddleware.js +0 -14
- package/dist/entries/http/scimThrottleMiddleware.js +43 -237
- package/dist/entries/http/securedRouteModelBinding.js +37 -25
- package/dist/entries/http/securityHeadersMiddleware.js +8 -25
- package/dist/entries/http/signedUrl.js +20 -110
- package/dist/entries/http/throttleMiddleware.js +41 -185
- package/dist/entries/http/uploads.js +9 -24
- package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
- package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
- package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
- package/dist/entries/mail/mailer.js +68 -78
- package/dist/entries/openapi/generator.js +33 -100
- package/dist/entries/queue/createAppQueue.js +416 -256
- package/dist/entries/queue/failedJobRepository.js +17 -8
- package/dist/entries/queue/failedJobService.js +1 -0
- package/dist/entries/queue/jobRunner.js +141 -66
- package/dist/entries/queue/publicQueue.js +411 -257
- package/dist/entries/queue/queueConfig.js +61 -0
- package/dist/entries/queue/queueHandoff.js +318 -0
- package/dist/entries/queue/queueMetrics.js +989 -1386
- package/dist/entries/queue/queueServices.js +133 -0
- package/dist/entries/queue/queueWorkerTransport.js +1703 -0
- package/dist/entries/queue/redisQueue.js +282 -180
- package/dist/entries/queue.js +6 -45
- package/dist/entries/runtime/application.js +1585 -0
- package/dist/entries/runtime/asyncContextStore.js +0 -16
- package/dist/entries/security/oauthState.js +35 -67
- package/dist/entries/security/publicReads.js +4 -4
- package/dist/entries/security/safeFetch.js +1 -0
- package/dist/entries/security/scimTenantTokens.js +3 -3
- package/dist/entries/security/tokenExpiry.js +2 -2
- package/dist/entries/security/totp.js +1 -87
- package/dist/entries/security/webhookSignature.js +2 -90
- package/dist/entries/storage/storage.js +120 -45
- package/dist/entries/tenant/databaseTenantContext.js +6 -907
- package/dist/entries/tenant/publicTenantHost.js +78 -0
- package/dist/entries/tenant/resolveTenant.js +14 -0
- package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
- package/dist/entries/tenant/tenancyConfig.js +1 -19
- package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
- package/dist/entries/tracing/tracingMiddleware.js +104 -173
- package/dist/entries/view/tokens.js +11 -0
- package/dist/framework/public-api.d.ts +62 -44
- package/dist/index.js +10435 -11351
- package/dist/internal/ormInternal.js +117 -0
- package/dist/internal/ormRuntime.js +5000 -0
- package/package.json +158 -46
- package/dist/core/database/bindConnection.d.ts +0 -1
- package/dist/core/database/boundConnection.d.ts +0 -5
- package/dist/core/database/defaultConnection.d.ts +0 -7
- package/dist/core/database/namedConnections.d.ts +0 -15
- package/dist/core/database/readOnlyCollector.d.ts +0 -7
- package/dist/core/database/repositoryConnection.d.ts +0 -4
- package/dist/core/database/transaction.d.ts +0 -23
- package/dist/core/database/transactionControl.d.ts +0 -6
- package/dist/core/events/deferredModelEvents.d.ts +0 -7
- package/dist/core/facades/index.d.ts +0 -10
- package/dist/core/runtime/applicationRegistry.d.ts +0 -18
- package/dist/entries/database/bindConnection.js +0 -1
- package/dist/entries/database/boundConnection.js +0 -1
- package/dist/entries/database/defaultConnection.js +0 -1
- package/dist/entries/database/namedConnections.js +0 -1
- package/dist/entries/database/repositoryConnection.js +0 -1
- package/dist/entries/database/transaction.js +0 -1
- package/dist/entries/facades.js +0 -711
- package/dist/entries/runtime/applicationRegistry.js +0 -1
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// ../../src/core/database/query.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return currentSqlDialect().quoteIdentifier(identifier);
|
|
3
|
+
function quoteIdentifier(dialect, identifier) {
|
|
4
|
+
return dialect.quoteIdentifier(identifier);
|
|
6
5
|
}
|
|
7
|
-
function returningSuffix(columns) {
|
|
8
|
-
return
|
|
6
|
+
function returningSuffix(dialect, columns) {
|
|
7
|
+
return dialect.returningClause(columns);
|
|
9
8
|
}
|
|
10
|
-
function qualifyColumn(tableName, column) {
|
|
11
|
-
return `${quoteIdentifier(tableName)}.${quoteIdentifier(column)}`;
|
|
9
|
+
function qualifyColumn(dialect, tableName, column) {
|
|
10
|
+
return `${quoteIdentifier(dialect, tableName)}.${quoteIdentifier(dialect, column)}`;
|
|
12
11
|
}
|
|
13
|
-
function resolveQualifiedColumn(defaultTable, columnName) {
|
|
12
|
+
function resolveQualifiedColumn(dialect, defaultTable, columnName) {
|
|
14
13
|
if (columnName.includes(".")) {
|
|
15
14
|
const [table, column] = columnName.split(".", 2);
|
|
16
15
|
if (!table || !column) {
|
|
17
16
|
throw new Error(`Invalid qualified column: ${columnName}`);
|
|
18
17
|
}
|
|
19
|
-
return qualifyColumn(table, column);
|
|
18
|
+
return qualifyColumn(dialect, table, column);
|
|
20
19
|
}
|
|
21
|
-
return qualifyColumn(defaultTable, columnName);
|
|
20
|
+
return qualifyColumn(dialect, defaultTable, columnName);
|
|
22
21
|
}
|
|
23
22
|
function parseQualifiedColumn(reference) {
|
|
24
23
|
const [table, column] = reference.split(".", 2);
|
|
@@ -33,9 +32,9 @@ function normalizeDirection(direction = "ASC") {
|
|
|
33
32
|
function isQueryOperator(value) {
|
|
34
33
|
return value !== null && !Array.isArray(value) && !(value instanceof Date) && typeof value === "object";
|
|
35
34
|
}
|
|
36
|
-
function pushParam(values, value) {
|
|
35
|
+
function pushParam(dialect, values, value) {
|
|
37
36
|
values.push(value);
|
|
38
|
-
return
|
|
37
|
+
return dialect.placeholder(values.length);
|
|
39
38
|
}
|
|
40
39
|
var SUPPORTED_OPERATORS = new Set([
|
|
41
40
|
"eq",
|
|
@@ -50,14 +49,14 @@ var SUPPORTED_OPERATORS = new Set([
|
|
|
50
49
|
"ilike",
|
|
51
50
|
"tsMatch"
|
|
52
51
|
]);
|
|
53
|
-
function buildInClause(column, values, params, negated = false) {
|
|
52
|
+
function buildInClause(dialect, column, values, params, negated = false) {
|
|
54
53
|
if (values.length === 0) {
|
|
55
54
|
return negated ? "1 = 1" : "1 = 0";
|
|
56
55
|
}
|
|
57
|
-
const placeholders = values.map((value) => pushParam(params, value)).join(", ");
|
|
56
|
+
const placeholders = values.map((value) => pushParam(dialect, params, value)).join(", ");
|
|
58
57
|
return `${column}${negated ? " NOT" : ""} IN (${placeholders})`;
|
|
59
58
|
}
|
|
60
|
-
function buildOperatorClauses(column, operator, params) {
|
|
59
|
+
function buildOperatorClauses(dialect, column, operator, params) {
|
|
61
60
|
const clauses = [];
|
|
62
61
|
const unsupported = Object.keys(operator).filter((key) => !SUPPORTED_OPERATORS.has(key));
|
|
63
62
|
if (unsupported.length > 0) {
|
|
@@ -73,71 +72,71 @@ function buildOperatorClauses(column, operator, params) {
|
|
|
73
72
|
if (operator.eq === null) {
|
|
74
73
|
clauses.push(`${column} IS NULL`);
|
|
75
74
|
} else {
|
|
76
|
-
clauses.push(`${column} = ${pushParam(params, operator.eq)}`);
|
|
75
|
+
clauses.push(`${column} = ${pushParam(dialect, params, operator.eq)}`);
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
if (operator.ne !== undefined) {
|
|
80
79
|
if (operator.ne === null) {
|
|
81
80
|
clauses.push(`${column} IS NOT NULL`);
|
|
82
81
|
} else {
|
|
83
|
-
clauses.push(`${column} <> ${pushParam(params, operator.ne)}`);
|
|
82
|
+
clauses.push(`${column} <> ${pushParam(dialect, params, operator.ne)}`);
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
if (operator.in !== undefined) {
|
|
87
|
-
clauses.push(buildInClause(column, operator.in, params));
|
|
86
|
+
clauses.push(buildInClause(dialect, column, operator.in, params));
|
|
88
87
|
}
|
|
89
88
|
if (operator.notIn !== undefined) {
|
|
90
|
-
clauses.push(buildInClause(column, operator.notIn, params, true));
|
|
89
|
+
clauses.push(buildInClause(dialect, column, operator.notIn, params, true));
|
|
91
90
|
}
|
|
92
91
|
if (operator.gt !== undefined) {
|
|
93
|
-
clauses.push(`${column} > ${pushParam(params, operator.gt)}`);
|
|
92
|
+
clauses.push(`${column} > ${pushParam(dialect, params, operator.gt)}`);
|
|
94
93
|
}
|
|
95
94
|
if (operator.gte !== undefined) {
|
|
96
|
-
clauses.push(`${column} >= ${pushParam(params, operator.gte)}`);
|
|
95
|
+
clauses.push(`${column} >= ${pushParam(dialect, params, operator.gte)}`);
|
|
97
96
|
}
|
|
98
97
|
if (operator.lt !== undefined) {
|
|
99
|
-
clauses.push(`${column} < ${pushParam(params, operator.lt)}`);
|
|
98
|
+
clauses.push(`${column} < ${pushParam(dialect, params, operator.lt)}`);
|
|
100
99
|
}
|
|
101
100
|
if (operator.lte !== undefined) {
|
|
102
|
-
clauses.push(`${column} <= ${pushParam(params, operator.lte)}`);
|
|
101
|
+
clauses.push(`${column} <= ${pushParam(dialect, params, operator.lte)}`);
|
|
103
102
|
}
|
|
104
103
|
if (operator.ilike !== undefined) {
|
|
105
|
-
clauses.push(`${column} ${
|
|
104
|
+
clauses.push(`${column} ${dialect.ilikeOperator()} ${pushParam(dialect, params, operator.ilike)}`);
|
|
106
105
|
}
|
|
107
106
|
if (operator.tsMatch !== undefined) {
|
|
108
|
-
if (
|
|
107
|
+
if (dialect.driver !== "pgsql") {
|
|
109
108
|
throw new Error("Full-text search (tsMatch) is only available on PostgreSQL.");
|
|
110
109
|
}
|
|
111
|
-
clauses.push(`${column} @@ plainto_tsquery('english', ${pushParam(params, operator.tsMatch)})`);
|
|
110
|
+
clauses.push(`${column} @@ plainto_tsquery('english', ${pushParam(dialect, params, operator.tsMatch)})`);
|
|
112
111
|
}
|
|
113
112
|
return clauses;
|
|
114
113
|
}
|
|
115
|
-
function appendWhereParts(tableName, where, params) {
|
|
114
|
+
function appendWhereParts(dialect, tableName, where, params) {
|
|
116
115
|
const clauses = [];
|
|
117
116
|
for (const [columnName, filterValue] of Object.entries(where)) {
|
|
118
117
|
if (filterValue === undefined) {
|
|
119
118
|
continue;
|
|
120
119
|
}
|
|
121
|
-
const column = resolveQualifiedColumn(tableName, columnName);
|
|
120
|
+
const column = resolveQualifiedColumn(dialect, tableName, columnName);
|
|
122
121
|
if (Array.isArray(filterValue)) {
|
|
123
|
-
clauses.push(buildInClause(column, filterValue, params));
|
|
122
|
+
clauses.push(buildInClause(dialect, column, filterValue, params));
|
|
124
123
|
continue;
|
|
125
124
|
}
|
|
126
125
|
if (isQueryOperator(filterValue)) {
|
|
127
|
-
clauses.push(...buildOperatorClauses(column, filterValue, params));
|
|
126
|
+
clauses.push(...buildOperatorClauses(dialect, column, filterValue, params));
|
|
128
127
|
continue;
|
|
129
128
|
}
|
|
130
129
|
if (filterValue === null) {
|
|
131
130
|
clauses.push(`${column} IS NULL`);
|
|
132
131
|
continue;
|
|
133
132
|
}
|
|
134
|
-
clauses.push(`${column} = ${pushParam(params, filterValue)}`);
|
|
133
|
+
clauses.push(`${column} = ${pushParam(dialect, params, filterValue)}`);
|
|
135
134
|
}
|
|
136
135
|
return clauses.join(" AND ");
|
|
137
136
|
}
|
|
138
|
-
function buildWhereClause(tableName, where = {}) {
|
|
137
|
+
function buildWhereClause(dialect, tableName, where = {}) {
|
|
139
138
|
const params = [];
|
|
140
|
-
const body = appendWhereParts(tableName, where, params);
|
|
139
|
+
const body = appendWhereParts(dialect, tableName, where, params);
|
|
141
140
|
return {
|
|
142
141
|
clause: body.length > 0 ? ` WHERE ${body}` : "",
|
|
143
142
|
params
|
|
@@ -148,30 +147,30 @@ function remapExistsSql(sql, existsParams, params) {
|
|
|
148
147
|
params.push(...existsParams);
|
|
149
148
|
return sql.replace(/\$(\d+)/g, (_match, index) => `$${offset + Number(index)}`);
|
|
150
149
|
}
|
|
151
|
-
function buildWhereNodeClause(tableName, node, params) {
|
|
150
|
+
function buildWhereNodeClause(dialect, tableName, node, params) {
|
|
152
151
|
if ("compareRow" in node) {
|
|
153
152
|
const { columns, operator, values } = node.compareRow;
|
|
154
153
|
if (!Array.isArray(columns) || !columns.length || !Array.isArray(values) || columns.length !== values.length || !["lt", "gt"].includes(operator) || Array.from(columns).some((column) => typeof column !== "string" || !column.length))
|
|
155
154
|
throw new TypeError("Invalid row comparison columns, values or operator.");
|
|
156
|
-
return `(${columns.map((column) => qualifyColumn(tableName, column)).join(", ")}) ${operator === "lt" ? "<" : ">"} (${values.map((value) => pushParam(params, value)).join(", ")})`;
|
|
155
|
+
return `(${columns.map((column) => qualifyColumn(dialect, tableName, column)).join(", ")}) ${operator === "lt" ? "<" : ">"} (${values.map((value) => pushParam(dialect, params, value)).join(", ")})`;
|
|
157
156
|
}
|
|
158
157
|
if ("exists" in node) {
|
|
159
158
|
const body = remapExistsSql(node.exists.sql, node.exists.params, params);
|
|
160
159
|
return `${node.exists.not ? "NOT " : ""}EXISTS (${body})`;
|
|
161
160
|
}
|
|
162
161
|
if ("where" in node) {
|
|
163
|
-
return appendWhereParts(tableName, node.where, params);
|
|
162
|
+
return appendWhereParts(dialect, tableName, node.where, params);
|
|
164
163
|
}
|
|
165
|
-
const grouped = buildWhereGroupClause(tableName, node.group, params);
|
|
164
|
+
const grouped = buildWhereGroupClause(dialect, tableName, node.group, params);
|
|
166
165
|
if (!grouped) {
|
|
167
166
|
return "";
|
|
168
167
|
}
|
|
169
168
|
return grouped.includes(" OR ") ? `(${grouped})` : grouped;
|
|
170
169
|
}
|
|
171
|
-
function buildWhereGroupClause(tableName, nodes, params) {
|
|
170
|
+
function buildWhereGroupClause(dialect, tableName, nodes, params) {
|
|
172
171
|
let result = "";
|
|
173
172
|
for (const node of nodes) {
|
|
174
|
-
const part = buildWhereNodeClause(tableName, node, params);
|
|
173
|
+
const part = buildWhereNodeClause(dialect, tableName, node, params);
|
|
175
174
|
if (!part) {
|
|
176
175
|
continue;
|
|
177
176
|
}
|
|
@@ -186,13 +185,13 @@ function buildWhereGroupClause(tableName, nodes, params) {
|
|
|
186
185
|
}
|
|
187
186
|
return result;
|
|
188
187
|
}
|
|
189
|
-
function buildAdvancedWhereClause(tableName, where = {}, whereNodes = [], params = []) {
|
|
188
|
+
function buildAdvancedWhereClause(dialect, tableName, where = {}, whereNodes = [], params = []) {
|
|
190
189
|
const nodes = [];
|
|
191
190
|
if (Object.keys(where).length > 0) {
|
|
192
191
|
nodes.push({ kind: "and", where });
|
|
193
192
|
}
|
|
194
193
|
nodes.push(...whereNodes);
|
|
195
|
-
const combined = buildWhereGroupClause(tableName, nodes, params);
|
|
194
|
+
const combined = buildWhereGroupClause(dialect, tableName, nodes, params);
|
|
196
195
|
return {
|
|
197
196
|
clause: combined ? ` WHERE ${combined}` : "",
|
|
198
197
|
params
|
|
@@ -207,12 +206,12 @@ function resolveSoftDeleteColumn(table) {
|
|
|
207
206
|
}
|
|
208
207
|
return table.softDeletes.column ?? "deleted_at";
|
|
209
208
|
}
|
|
210
|
-
function appendSoftDeleteScope(table, options, clauses) {
|
|
209
|
+
function appendSoftDeleteScope(dialect, table, options, clauses) {
|
|
211
210
|
const column = resolveSoftDeleteColumn(table);
|
|
212
211
|
if (!column) {
|
|
213
212
|
return;
|
|
214
213
|
}
|
|
215
|
-
const qualifiedColumn = qualifyColumn(table.name, column);
|
|
214
|
+
const qualifiedColumn = qualifyColumn(dialect, table.name, column);
|
|
216
215
|
if (options.onlyTrashed) {
|
|
217
216
|
clauses.push(`${qualifiedColumn} IS NOT NULL`);
|
|
218
217
|
return;
|
|
@@ -221,10 +220,10 @@ function appendSoftDeleteScope(table, options, clauses) {
|
|
|
221
220
|
clauses.push(`${qualifiedColumn} IS NULL`);
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
|
-
function buildQueryWhereClause(table, options = {}, whereNodes = [], params = []) {
|
|
225
|
-
const { clause, params: whereParams } = buildAdvancedWhereClause(table.name, options.where ?? {}, whereNodes, params);
|
|
223
|
+
function buildQueryWhereClause(dialect, table, options = {}, whereNodes = [], params = []) {
|
|
224
|
+
const { clause, params: whereParams } = buildAdvancedWhereClause(dialect, table.name, options.where ?? {}, whereNodes, params);
|
|
226
225
|
const softDeleteClauses = [];
|
|
227
|
-
appendSoftDeleteScope(table, options, softDeleteClauses);
|
|
226
|
+
appendSoftDeleteScope(dialect, table, options, softDeleteClauses);
|
|
228
227
|
if (softDeleteClauses.length === 0) {
|
|
229
228
|
return { clause, params: whereParams };
|
|
230
229
|
}
|
|
@@ -253,42 +252,42 @@ function normalizeOrderBy(orderBy) {
|
|
|
253
252
|
direction
|
|
254
253
|
}));
|
|
255
254
|
}
|
|
256
|
-
function buildOrderByClause(tableName, orderBy) {
|
|
255
|
+
function buildOrderByClause(dialect, tableName, orderBy) {
|
|
257
256
|
const parts = normalizeOrderBy(orderBy).map(({ column, direction, nulls }) => {
|
|
258
257
|
if (nulls !== undefined && nulls !== "first" && nulls !== "last") {
|
|
259
258
|
throw new TypeError("Invalid null ordering: expected first or last.");
|
|
260
259
|
}
|
|
261
|
-
const reference = resolveQualifiedColumn(tableName, column);
|
|
260
|
+
const reference = resolveQualifiedColumn(dialect, tableName, column);
|
|
262
261
|
const ordered = `${reference} ${normalizeDirection(direction)}`;
|
|
263
262
|
if (nulls === undefined)
|
|
264
263
|
return ordered;
|
|
265
|
-
if (
|
|
264
|
+
if (dialect.driver === "mysql") {
|
|
266
265
|
return `(${reference} IS NULL) ${nulls === "first" ? "DESC" : "ASC"}, ${ordered}`;
|
|
267
266
|
}
|
|
268
267
|
return `${ordered} NULLS ${nulls.toUpperCase()}`;
|
|
269
268
|
});
|
|
270
269
|
return parts.length > 0 ? ` ORDER BY ${parts.join(", ")}` : "";
|
|
271
270
|
}
|
|
272
|
-
function buildGroupByClause(tableName, groupBy) {
|
|
271
|
+
function buildGroupByClause(dialect, tableName, groupBy) {
|
|
273
272
|
if (!groupBy) {
|
|
274
273
|
return "";
|
|
275
274
|
}
|
|
276
275
|
const columns = (Array.isArray(groupBy) ? groupBy : [groupBy]).map((column) => String(column));
|
|
277
|
-
const parts = columns.map((column) => resolveQualifiedColumn(tableName, column));
|
|
276
|
+
const parts = columns.map((column) => resolveQualifiedColumn(dialect, tableName, column));
|
|
278
277
|
return parts.length > 0 ? ` GROUP BY ${parts.join(", ")}` : "";
|
|
279
278
|
}
|
|
280
|
-
function buildHavingClause(tableName, having, params) {
|
|
279
|
+
function buildHavingClause(dialect, tableName, having, params) {
|
|
281
280
|
if (!having) {
|
|
282
281
|
return "";
|
|
283
282
|
}
|
|
284
|
-
const body = appendWhereParts(tableName, having, params);
|
|
283
|
+
const body = appendWhereParts(dialect, tableName, having, params);
|
|
285
284
|
return body.length > 0 ? ` HAVING ${body}` : "";
|
|
286
285
|
}
|
|
287
|
-
function buildJoinClause(joins = []) {
|
|
286
|
+
function buildJoinClause(dialect, joins = []) {
|
|
288
287
|
return joins.map((join) => {
|
|
289
288
|
const joinType = join.type === "left" ? "LEFT JOIN" : "INNER JOIN";
|
|
290
|
-
const onClause = join.on.map(({ left, right }) => `${qualifyColumn(left.table, left.column)} = ${qualifyColumn(right.table, right.column)}`).join(" AND ");
|
|
291
|
-
return ` ${joinType} ${quoteIdentifier(join.table)} ON ${onClause}`;
|
|
289
|
+
const onClause = join.on.map(({ left, right }) => `${qualifyColumn(dialect, left.table, left.column)} = ${qualifyColumn(dialect, right.table, right.column)}`).join(" AND ");
|
|
290
|
+
return ` ${joinType} ${quoteIdentifier(dialect, join.table)} ON ${onClause}`;
|
|
292
291
|
}).join("");
|
|
293
292
|
}
|
|
294
293
|
function buildLimitClause(limit) {
|
|
@@ -309,34 +308,33 @@ function buildOffsetClause(offset) {
|
|
|
309
308
|
}
|
|
310
309
|
return ` OFFSET ${offset}`;
|
|
311
310
|
}
|
|
312
|
-
function buildReturningColumns(table) {
|
|
313
|
-
return table.columns.map((column) => qualifyColumn(table.name, column)).join(", ");
|
|
311
|
+
function buildReturningColumns(dialect, table) {
|
|
312
|
+
return table.columns.map((column) => qualifyColumn(dialect, table.name, column)).join(", ");
|
|
314
313
|
}
|
|
315
|
-
function buildSelectList(table, select, params = []) {
|
|
314
|
+
function buildSelectList(dialect, table, select, params = []) {
|
|
316
315
|
if (!select || select.length === 0) {
|
|
317
|
-
return buildReturningColumns(table);
|
|
316
|
+
return buildReturningColumns(dialect, table);
|
|
318
317
|
}
|
|
319
318
|
return select.map((item) => {
|
|
320
319
|
if (item.kind === "column") {
|
|
321
|
-
const column = qualifyColumn(item.table, item.column);
|
|
322
|
-
return item.as ? `${column} AS ${quoteIdentifier(item.as)}` : column;
|
|
320
|
+
const column = qualifyColumn(dialect, item.table, item.column);
|
|
321
|
+
return item.as ? `${column} AS ${quoteIdentifier(dialect, item.as)}` : column;
|
|
323
322
|
}
|
|
324
323
|
if (item.kind === "textColumn") {
|
|
325
|
-
const
|
|
326
|
-
const column = qualifyColumn(item.table, item.column);
|
|
324
|
+
const column = qualifyColumn(dialect, item.table, item.column);
|
|
327
325
|
const text = dialect.driver === "sqlite" ? `CASE WHEN typeof(${column}) = 'real' THEN printf('%!.26g', ${column}) ELSE ${dialect.castToText(column)} END` : dialect.castToText(column);
|
|
328
|
-
return `${text} AS ${quoteIdentifier(item.as)}`;
|
|
326
|
+
return `${text} AS ${quoteIdentifier(dialect, item.as)}`;
|
|
329
327
|
}
|
|
330
328
|
if (item.kind === "literalText") {
|
|
331
|
-
return `${
|
|
329
|
+
return `${dialect.castToText(pushParam(dialect, params, item.value))} AS ${quoteIdentifier(dialect, item.as)}`;
|
|
332
330
|
}
|
|
333
331
|
if (item.kind === "subqueryCount") {
|
|
334
332
|
const body = remapExistsSql(item.sql, item.params, params);
|
|
335
|
-
return `(${body}) AS ${quoteIdentifier(item.as)}`;
|
|
333
|
+
return `(${body}) AS ${quoteIdentifier(dialect, item.as)}`;
|
|
336
334
|
}
|
|
337
|
-
const column = qualifyColumn(item.table, item.column);
|
|
338
|
-
const placeholder = pushParam(params, item.query);
|
|
339
|
-
return `ts_rank(${column}, plainto_tsquery('english', ${placeholder})) AS ${quoteIdentifier(item.as)}`;
|
|
335
|
+
const column = qualifyColumn(dialect, item.table, item.column);
|
|
336
|
+
const placeholder = pushParam(dialect, params, item.query);
|
|
337
|
+
return `ts_rank(${column}, plainto_tsquery('english', ${placeholder})) AS ${quoteIdentifier(dialect, item.as)}`;
|
|
340
338
|
}).join(", ");
|
|
341
339
|
}
|
|
342
340
|
function getDefinedColumnEntries(table, values, options = {}) {
|
|
@@ -353,11 +351,11 @@ function getDefinedColumnEntries(table, values, options = {}) {
|
|
|
353
351
|
return [[column, value]];
|
|
354
352
|
});
|
|
355
353
|
}
|
|
356
|
-
function buildSelectLock(table, options) {
|
|
354
|
+
function buildSelectLock(dialect, table, options) {
|
|
357
355
|
const lock = options.lock;
|
|
358
356
|
if (!lock)
|
|
359
357
|
return "";
|
|
360
|
-
const driver =
|
|
358
|
+
const driver = dialect.driver;
|
|
361
359
|
if (driver === "sqlite")
|
|
362
360
|
throw new Error("Row locks are not supported on SQLite; use an explicit write transaction.");
|
|
363
361
|
if (lock.mode !== "update" && lock.mode !== "share")
|
|
@@ -373,29 +371,29 @@ function buildSelectLock(table, options) {
|
|
|
373
371
|
const tables = [table.name, ...(options.joins ?? []).map((join) => join.table)];
|
|
374
372
|
if (!lock.of.length || lock.of.some((name) => !tables.includes(name)))
|
|
375
373
|
throw new TypeError("Row lock targets must name tables in this query.");
|
|
376
|
-
target = ` OF ${lock.of.map(quoteIdentifier).join(", ")}`;
|
|
374
|
+
target = ` OF ${lock.of.map((column) => quoteIdentifier(dialect, column)).join(", ")}`;
|
|
377
375
|
}
|
|
378
376
|
const wait = lock.wait === "nowait" ? " NOWAIT" : lock.wait === "skipLocked" ? " SKIP LOCKED" : "";
|
|
379
377
|
return ` FOR ${lock.mode === "update" ? "UPDATE" : "SHARE"}${target}${wait}`;
|
|
380
378
|
}
|
|
381
|
-
function buildSelectQuery(table, options = {}, whereNodes = []) {
|
|
379
|
+
function buildSelectQuery(dialect, table, options = {}, whereNodes = []) {
|
|
382
380
|
const params = [];
|
|
383
|
-
const columns = buildSelectList(table, options.select, params);
|
|
384
|
-
const { clause } = buildQueryWhereClause(table, options, whereNodes, params);
|
|
385
|
-
const joins = buildJoinClause(options.joins);
|
|
386
|
-
const groupBy = buildGroupByClause(table.name, options.groupBy);
|
|
387
|
-
const havingClause = buildHavingClause(table.name, options.having, params);
|
|
388
|
-
const orderBy = buildOrderByClause(table.name, options.orderBy ?? table.defaultOrderBy);
|
|
381
|
+
const columns = buildSelectList(dialect, table, options.select, params);
|
|
382
|
+
const { clause } = buildQueryWhereClause(dialect, table, options, whereNodes, params);
|
|
383
|
+
const joins = buildJoinClause(dialect, options.joins);
|
|
384
|
+
const groupBy = buildGroupByClause(dialect, table.name, options.groupBy);
|
|
385
|
+
const havingClause = buildHavingClause(dialect, table.name, options.having, params);
|
|
386
|
+
const orderBy = buildOrderByClause(dialect, table.name, options.orderBy ?? table.defaultOrderBy);
|
|
389
387
|
const limit = buildLimitClause(options.limit);
|
|
390
388
|
const offset = buildOffsetClause(options.offset);
|
|
391
|
-
const lock = buildSelectLock(table, options);
|
|
389
|
+
const lock = buildSelectLock(dialect, table, options);
|
|
392
390
|
return {
|
|
393
|
-
text: `SELECT ${columns} FROM ${quoteIdentifier(table.name)}${joins}${clause}${groupBy}${havingClause}${orderBy}${limit}${offset}${lock}`,
|
|
391
|
+
text: `SELECT ${columns} FROM ${quoteIdentifier(dialect, table.name)}${joins}${clause}${groupBy}${havingClause}${orderBy}${limit}${offset}${lock}`,
|
|
394
392
|
params
|
|
395
393
|
};
|
|
396
394
|
}
|
|
397
395
|
var EAGER_ROW_NUMBER = "__strata_eager_row_number";
|
|
398
|
-
function buildLimitedRelationQuery(table, options, partition, source) {
|
|
396
|
+
function buildLimitedRelationQuery(dialect, table, options, partition, source) {
|
|
399
397
|
if (options.lock || options.groupBy?.length || options.having) {
|
|
400
398
|
throw new Error("Limited eager relations do not support row locks, grouping or HAVING.");
|
|
401
399
|
}
|
|
@@ -411,51 +409,51 @@ function buildLimitedRelationQuery(table, options, partition, source) {
|
|
|
411
409
|
if (!order.some((item) => item.column === table.primaryKey || item.column === `${table.name}.${table.primaryKey}`)) {
|
|
412
410
|
order.push({ column: table.primaryKey, direction: "ASC" });
|
|
413
411
|
}
|
|
414
|
-
const ordering = buildOrderByClause(table.name, order);
|
|
412
|
+
const ordering = buildOrderByClause(dialect, table.name, order);
|
|
415
413
|
const params = [];
|
|
416
|
-
const columns = buildSelectList(table, options.select, params);
|
|
417
|
-
const rank = `ROW_NUMBER() OVER (PARTITION BY ${qualifyColumn(partition.table, partition.column)}${ordering}) AS ${quoteIdentifier(EAGER_ROW_NUMBER)}`;
|
|
414
|
+
const columns = buildSelectList(dialect, table, options.select, params);
|
|
415
|
+
const rank = `ROW_NUMBER() OVER (PARTITION BY ${qualifyColumn(dialect, partition.table, partition.column)}${ordering}) AS ${quoteIdentifier(dialect, EAGER_ROW_NUMBER)}`;
|
|
418
416
|
const sql = source(columns, rank, params);
|
|
419
417
|
const offset = options.offset ?? 0;
|
|
420
|
-
const upper = options.limit === undefined ? "" : ` AND ${quoteIdentifier(EAGER_ROW_NUMBER)} <= ${offset + options.limit}`;
|
|
418
|
+
const upper = options.limit === undefined ? "" : ` AND ${quoteIdentifier(dialect, EAGER_ROW_NUMBER)} <= ${offset + options.limit}`;
|
|
421
419
|
return {
|
|
422
|
-
text: `SELECT * FROM (${sql}) AS ${quoteIdentifier("__strata_eager")} WHERE ${quoteIdentifier(EAGER_ROW_NUMBER)} > ${offset}${upper} ORDER BY ${quoteIdentifier(EAGER_ROW_NUMBER)}`,
|
|
420
|
+
text: `SELECT * FROM (${sql}) AS ${quoteIdentifier(dialect, "__strata_eager")} WHERE ${quoteIdentifier(dialect, EAGER_ROW_NUMBER)} > ${offset}${upper} ORDER BY ${quoteIdentifier(dialect, EAGER_ROW_NUMBER)}`,
|
|
423
421
|
params
|
|
424
422
|
};
|
|
425
423
|
}
|
|
426
|
-
function buildLimitedHasManyQuery(table, options, partition) {
|
|
427
|
-
return buildLimitedRelationQuery(table, options, partition, (columns, rank, params) => {
|
|
428
|
-
const { clause } = buildQueryWhereClause(table, options, options.whereNodes, params);
|
|
429
|
-
const owner = partition.ownerAlias ? `, ${qualifyColumn(partition.table, partition.column)} AS ${quoteIdentifier(partition.ownerAlias)}` : "";
|
|
430
|
-
return `SELECT ${columns}${owner}, ${rank} FROM ${quoteIdentifier(table.name)}${buildJoinClause(options.joins)}${clause}`;
|
|
424
|
+
function buildLimitedHasManyQuery(dialect, table, options, partition) {
|
|
425
|
+
return buildLimitedRelationQuery(dialect, table, options, partition, (columns, rank, params) => {
|
|
426
|
+
const { clause } = buildQueryWhereClause(dialect, table, options, options.whereNodes, params);
|
|
427
|
+
const owner = partition.ownerAlias ? `, ${qualifyColumn(dialect, partition.table, partition.column)} AS ${quoteIdentifier(dialect, partition.ownerAlias)}` : "";
|
|
428
|
+
return `SELECT ${columns}${owner}, ${rank} FROM ${quoteIdentifier(dialect, table.name)}${buildJoinClause(dialect, options.joins)}${clause}`;
|
|
431
429
|
});
|
|
432
430
|
}
|
|
433
|
-
function buildCountQuery(table, where = {}, options = {}, whereNodes = []) {
|
|
431
|
+
function buildCountQuery(dialect, table, where = {}, options = {}, whereNodes = []) {
|
|
434
432
|
const params = [];
|
|
435
|
-
const { clause, params: whereParams } = buildQueryWhereClause(table, {
|
|
433
|
+
const { clause, params: whereParams } = buildQueryWhereClause(dialect, table, {
|
|
436
434
|
where,
|
|
437
435
|
withTrashed: options.withTrashed,
|
|
438
436
|
onlyTrashed: options.onlyTrashed
|
|
439
437
|
}, whereNodes);
|
|
440
438
|
params.push(...whereParams);
|
|
441
|
-
const joins = buildJoinClause(options.joins);
|
|
442
|
-
const groupBy = buildGroupByClause(table.name, options.groupBy);
|
|
439
|
+
const joins = buildJoinClause(dialect, options.joins);
|
|
440
|
+
const groupBy = buildGroupByClause(dialect, table.name, options.groupBy);
|
|
443
441
|
return {
|
|
444
|
-
text: `SELECT COUNT(*) AS count FROM ${quoteIdentifier(table.name)}${joins}${clause}${groupBy}`,
|
|
442
|
+
text: `SELECT COUNT(*) AS count FROM ${quoteIdentifier(dialect, table.name)}${joins}${clause}${groupBy}`,
|
|
445
443
|
params
|
|
446
444
|
};
|
|
447
445
|
}
|
|
448
|
-
function buildProjectionQuery(table, expression, alias, options = {}, whereNodes = []) {
|
|
446
|
+
function buildProjectionQuery(dialect, table, expression, alias, options = {}, whereNodes = []) {
|
|
449
447
|
assertSafeProjectionExpression(expression);
|
|
450
448
|
const params = [];
|
|
451
|
-
const { clause, params: whereParams } = buildQueryWhereClause(table, options, whereNodes);
|
|
449
|
+
const { clause, params: whereParams } = buildQueryWhereClause(dialect, table, options, whereNodes);
|
|
452
450
|
params.push(...whereParams);
|
|
453
|
-
const joins = buildJoinClause(options.joins);
|
|
454
|
-
const groupBy = buildGroupByClause(table.name, options.groupBy);
|
|
455
|
-
const orderBy = buildOrderByClause(table.name, options.orderBy);
|
|
451
|
+
const joins = buildJoinClause(dialect, options.joins);
|
|
452
|
+
const groupBy = buildGroupByClause(dialect, table.name, options.groupBy);
|
|
453
|
+
const orderBy = buildOrderByClause(dialect, table.name, options.orderBy);
|
|
456
454
|
const limit = buildLimitClause(options.limit);
|
|
457
455
|
return {
|
|
458
|
-
text: `SELECT ${expression} AS ${quoteIdentifier(alias)} FROM ${quoteIdentifier(table.name)}${joins}${clause}${groupBy}${orderBy}${limit}`,
|
|
456
|
+
text: `SELECT ${expression} AS ${quoteIdentifier(dialect, alias)} FROM ${quoteIdentifier(dialect, table.name)}${joins}${clause}${groupBy}${orderBy}${limit}`,
|
|
459
457
|
params
|
|
460
458
|
};
|
|
461
459
|
}
|
|
@@ -465,46 +463,46 @@ function assertSafeProjectionExpression(expression) {
|
|
|
465
463
|
throw new Error(`Unsafe projection expression: ${expression}`);
|
|
466
464
|
}
|
|
467
465
|
}
|
|
468
|
-
function buildGroupedSumQuery(table, groupColumn, column, options = {}, whereNodes = options.whereNodes ?? []) {
|
|
466
|
+
function buildGroupedSumQuery(dialect, table, groupColumn, column, options = {}, whereNodes = options.whereNodes ?? []) {
|
|
469
467
|
if (!table.columns.includes(groupColumn) || !table.columns.includes(column))
|
|
470
468
|
throw new TypeError("Grouped sums require declared columns.");
|
|
471
469
|
for (const key of Object.keys(options))
|
|
472
470
|
if (!["where", "whereNodes", "withTrashed", "onlyTrashed"].includes(key))
|
|
473
471
|
throw new TypeError("Grouped sums do not support joins, selection, ordering, pagination, grouping or locks.");
|
|
474
|
-
const group = qualifyColumn(table.name, groupColumn);
|
|
475
|
-
const total =
|
|
476
|
-
const { clause, params } = buildQueryWhereClause(table, options, whereNodes);
|
|
472
|
+
const group = qualifyColumn(dialect, table.name, groupColumn);
|
|
473
|
+
const total = dialect.castToText(`SUM(${qualifyColumn(dialect, table.name, column)})`);
|
|
474
|
+
const { clause, params } = buildQueryWhereClause(dialect, table, options, whereNodes);
|
|
477
475
|
return {
|
|
478
|
-
text: `SELECT ${group} AS ${quoteIdentifier("value")}, ${total} AS ${quoteIdentifier("sum")} FROM ${quoteIdentifier(table.name)}${clause} GROUP BY ${group} ORDER BY ${group} ASC`,
|
|
476
|
+
text: `SELECT ${group} AS ${quoteIdentifier(dialect, "value")}, ${total} AS ${quoteIdentifier(dialect, "sum")} FROM ${quoteIdentifier(dialect, table.name)}${clause} GROUP BY ${group} ORDER BY ${group} ASC`,
|
|
479
477
|
params
|
|
480
478
|
};
|
|
481
479
|
}
|
|
482
|
-
function buildGroupedCountQuery(table, column, where = {}, options = {}) {
|
|
483
|
-
const qualifiedColumn = qualifyColumn(table.name, column);
|
|
484
|
-
const { clause, params } = buildQueryWhereClause(table, {
|
|
480
|
+
function buildGroupedCountQuery(dialect, table, column, where = {}, options = {}) {
|
|
481
|
+
const qualifiedColumn = qualifyColumn(dialect, table.name, column);
|
|
482
|
+
const { clause, params } = buildQueryWhereClause(dialect, table, {
|
|
485
483
|
where,
|
|
486
484
|
...options
|
|
487
485
|
});
|
|
488
486
|
return {
|
|
489
|
-
text: `SELECT ${qualifiedColumn} AS ${quoteIdentifier("value")}, COUNT(*) AS ${quoteIdentifier("count")} FROM ${quoteIdentifier(table.name)}${clause} GROUP BY ${qualifiedColumn} ORDER BY ${qualifiedColumn} ASC`,
|
|
487
|
+
text: `SELECT ${qualifiedColumn} AS ${quoteIdentifier(dialect, "value")}, COUNT(*) AS ${quoteIdentifier(dialect, "count")} FROM ${quoteIdentifier(dialect, table.name)}${clause} GROUP BY ${qualifiedColumn} ORDER BY ${qualifiedColumn} ASC`,
|
|
490
488
|
params
|
|
491
489
|
};
|
|
492
490
|
}
|
|
493
|
-
function buildInsertQuery(table, values) {
|
|
491
|
+
function buildInsertQuery(dialect, table, values) {
|
|
494
492
|
const entries = getDefinedColumnEntries(table, values);
|
|
495
493
|
if (entries.length === 0) {
|
|
496
494
|
throw new Error(`Cannot insert into ${table.name} without any column values.`);
|
|
497
495
|
}
|
|
498
496
|
const params = [];
|
|
499
|
-
const columns = entries.map(([column]) => quoteIdentifier(column)).join(", ");
|
|
500
|
-
const placeholders = entries.map(([, value]) => pushParam(params, value)).join(", ");
|
|
501
|
-
const returningColumns = buildReturningColumns(table);
|
|
497
|
+
const columns = entries.map(([column]) => quoteIdentifier(dialect, column)).join(", ");
|
|
498
|
+
const placeholders = entries.map(([, value]) => pushParam(dialect, params, value)).join(", ");
|
|
499
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
502
500
|
return {
|
|
503
|
-
text: `INSERT INTO ${quoteIdentifier(table.name)} (${columns}) VALUES (${placeholders})${returningSuffix(returningColumns)}`,
|
|
501
|
+
text: `INSERT INTO ${quoteIdentifier(dialect, table.name)} (${columns}) VALUES (${placeholders})${returningSuffix(dialect, returningColumns)}`,
|
|
504
502
|
params
|
|
505
503
|
};
|
|
506
504
|
}
|
|
507
|
-
function buildUpsertQuery(table, values, conflictColumns, updateColumns) {
|
|
505
|
+
function buildUpsertQuery(dialect, table, values, conflictColumns, updateColumns) {
|
|
508
506
|
const entries = getDefinedColumnEntries(table, values);
|
|
509
507
|
if (entries.length === 0) {
|
|
510
508
|
throw new Error(`Cannot upsert into ${table.name} without any column values.`);
|
|
@@ -516,16 +514,16 @@ function buildUpsertQuery(table, values, conflictColumns, updateColumns) {
|
|
|
516
514
|
const conflict = new Set(conflictColumns);
|
|
517
515
|
const updatable = (updateColumns ?? entries.map(([column]) => column).filter((c) => !conflict.has(c))).filter((column) => insertable.has(column));
|
|
518
516
|
const params = [];
|
|
519
|
-
const columns = entries.map(([column]) => quoteIdentifier(column)).join(", ");
|
|
520
|
-
const placeholders = entries.map(([, value]) => pushParam(params, value)).join(", ");
|
|
521
|
-
const returningColumns = buildReturningColumns(table);
|
|
522
|
-
const suffix =
|
|
517
|
+
const columns = entries.map(([column]) => quoteIdentifier(dialect, column)).join(", ");
|
|
518
|
+
const placeholders = entries.map(([, value]) => pushParam(dialect, params, value)).join(", ");
|
|
519
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
520
|
+
const suffix = dialect.upsertSuffix(conflictColumns, updatable);
|
|
523
521
|
return {
|
|
524
|
-
text: `INSERT INTO ${quoteIdentifier(table.name)} (${columns}) VALUES (${placeholders})${suffix}${returningSuffix(returningColumns)}`,
|
|
522
|
+
text: `INSERT INTO ${quoteIdentifier(dialect, table.name)} (${columns}) VALUES (${placeholders})${suffix}${returningSuffix(dialect, returningColumns)}`,
|
|
525
523
|
params
|
|
526
524
|
};
|
|
527
525
|
}
|
|
528
|
-
function buildIncrementQuery(table, id, column, amount, extra = {}) {
|
|
526
|
+
function buildIncrementQuery(dialect, table, id, column, amount, extra = {}) {
|
|
529
527
|
if (!Number.isFinite(amount)) {
|
|
530
528
|
throw new Error("Increment amount must be a finite number.");
|
|
531
529
|
}
|
|
@@ -533,24 +531,24 @@ function buildIncrementQuery(table, id, column, amount, extra = {}) {
|
|
|
533
531
|
throw new Error(`Unknown column ${String(column)} on ${table.name}.`);
|
|
534
532
|
}
|
|
535
533
|
const params = [];
|
|
536
|
-
const target = quoteIdentifier(column);
|
|
537
|
-
const assignments = [`${target} = ${target} + ${pushParam(params, amount)}`];
|
|
534
|
+
const target = quoteIdentifier(dialect, column);
|
|
535
|
+
const assignments = [`${target} = ${target} + ${pushParam(dialect, params, amount)}`];
|
|
538
536
|
for (const [name, value] of getDefinedColumnEntries(table, extra, {
|
|
539
537
|
exclude: [table.primaryKey, column]
|
|
540
538
|
})) {
|
|
541
|
-
assignments.push(`${quoteIdentifier(name)} = ${pushParam(params, value)}`);
|
|
539
|
+
assignments.push(`${quoteIdentifier(dialect, name)} = ${pushParam(dialect, params, value)}`);
|
|
542
540
|
}
|
|
543
|
-
const primaryKeyPlaceholder = pushParam(params, id);
|
|
544
|
-
const returningColumns = buildReturningColumns(table);
|
|
541
|
+
const primaryKeyPlaceholder = pushParam(dialect, params, id);
|
|
542
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
545
543
|
const scopeClauses = [];
|
|
546
|
-
appendSoftDeleteScope(table, {}, scopeClauses);
|
|
544
|
+
appendSoftDeleteScope(dialect, table, {}, scopeClauses);
|
|
547
545
|
const scopeSuffix = scopeClauses.length > 0 ? ` AND ${scopeClauses.join(" AND ")}` : "";
|
|
548
546
|
return {
|
|
549
|
-
text: `UPDATE ${quoteIdentifier(table.name)} SET ${assignments.join(", ")} WHERE ${quoteIdentifier(table.primaryKey)} = ${primaryKeyPlaceholder}${scopeSuffix}${returningSuffix(returningColumns)}`,
|
|
547
|
+
text: `UPDATE ${quoteIdentifier(dialect, table.name)} SET ${assignments.join(", ")} WHERE ${quoteIdentifier(dialect, table.primaryKey)} = ${primaryKeyPlaceholder}${scopeSuffix}${returningSuffix(dialect, returningColumns)}`,
|
|
550
548
|
params
|
|
551
549
|
};
|
|
552
550
|
}
|
|
553
|
-
function buildUpdateQuery(table, id, changes) {
|
|
551
|
+
function buildUpdateQuery(dialect, table, id, changes) {
|
|
554
552
|
const entries = getDefinedColumnEntries(table, changes, {
|
|
555
553
|
exclude: [table.primaryKey]
|
|
556
554
|
});
|
|
@@ -558,58 +556,58 @@ function buildUpdateQuery(table, id, changes) {
|
|
|
558
556
|
throw new Error(`Cannot update ${table.name} without any changed column values.`);
|
|
559
557
|
}
|
|
560
558
|
const params = [];
|
|
561
|
-
const setClause = entries.map(([column, value]) => `${quoteIdentifier(column)} = ${pushParam(params, value)}`).join(", ");
|
|
562
|
-
const primaryKeyPlaceholder = pushParam(params, id);
|
|
563
|
-
const returningColumns = buildReturningColumns(table);
|
|
559
|
+
const setClause = entries.map(([column, value]) => `${quoteIdentifier(dialect, column)} = ${pushParam(dialect, params, value)}`).join(", ");
|
|
560
|
+
const primaryKeyPlaceholder = pushParam(dialect, params, id);
|
|
561
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
564
562
|
const scopeClauses = [];
|
|
565
|
-
appendSoftDeleteScope(table, {}, scopeClauses);
|
|
563
|
+
appendSoftDeleteScope(dialect, table, {}, scopeClauses);
|
|
566
564
|
const scopeSuffix = scopeClauses.length > 0 ? ` AND ${scopeClauses.join(" AND ")}` : "";
|
|
567
565
|
return {
|
|
568
|
-
text: `UPDATE ${quoteIdentifier(table.name)} SET ${setClause} WHERE ${quoteIdentifier(table.primaryKey)} = ${primaryKeyPlaceholder}${scopeSuffix}${returningSuffix(returningColumns)}`,
|
|
566
|
+
text: `UPDATE ${quoteIdentifier(dialect, table.name)} SET ${setClause} WHERE ${quoteIdentifier(dialect, table.primaryKey)} = ${primaryKeyPlaceholder}${scopeSuffix}${returningSuffix(dialect, returningColumns)}`,
|
|
569
567
|
params
|
|
570
568
|
};
|
|
571
569
|
}
|
|
572
|
-
function buildSoftDeleteByIdQuery(table, id, deletedAt) {
|
|
570
|
+
function buildSoftDeleteByIdQuery(dialect, table, id, deletedAt) {
|
|
573
571
|
const deletedAtColumn = resolveSoftDeleteColumn(table);
|
|
574
572
|
if (!deletedAtColumn) {
|
|
575
573
|
throw new Error(`Table ${table.name} does not support soft deletes.`);
|
|
576
574
|
}
|
|
577
|
-
const returningColumns = buildReturningColumns(table);
|
|
575
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
578
576
|
const scopeClauses = [];
|
|
579
|
-
appendSoftDeleteScope(table, {}, scopeClauses);
|
|
577
|
+
appendSoftDeleteScope(dialect, table, {}, scopeClauses);
|
|
580
578
|
const scopeSuffix = scopeClauses.length > 0 ? ` AND ${scopeClauses.join(" AND ")}` : "";
|
|
581
579
|
const params = [];
|
|
582
|
-
const deletedAtPlaceholder = pushParam(params, deletedAt);
|
|
583
|
-
const idPlaceholder = pushParam(params, id);
|
|
580
|
+
const deletedAtPlaceholder = pushParam(dialect, params, deletedAt);
|
|
581
|
+
const idPlaceholder = pushParam(dialect, params, id);
|
|
584
582
|
return {
|
|
585
|
-
text: `UPDATE ${quoteIdentifier(table.name)} SET ${quoteIdentifier(deletedAtColumn)} = ${deletedAtPlaceholder} WHERE ${quoteIdentifier(table.primaryKey)} = ${idPlaceholder}${scopeSuffix}${returningSuffix(returningColumns)}`,
|
|
583
|
+
text: `UPDATE ${quoteIdentifier(dialect, table.name)} SET ${quoteIdentifier(dialect, deletedAtColumn)} = ${deletedAtPlaceholder} WHERE ${quoteIdentifier(dialect, table.primaryKey)} = ${idPlaceholder}${scopeSuffix}${returningSuffix(dialect, returningColumns)}`,
|
|
586
584
|
params
|
|
587
585
|
};
|
|
588
586
|
}
|
|
589
|
-
function buildRestoreByIdQuery(table, id) {
|
|
587
|
+
function buildRestoreByIdQuery(dialect, table, id) {
|
|
590
588
|
const deletedAtColumn = resolveSoftDeleteColumn(table);
|
|
591
589
|
if (!deletedAtColumn) {
|
|
592
590
|
throw new Error(`Table ${table.name} does not support soft deletes.`);
|
|
593
591
|
}
|
|
594
|
-
const returningColumns = buildReturningColumns(table);
|
|
592
|
+
const returningColumns = buildReturningColumns(dialect, table);
|
|
595
593
|
const params = [];
|
|
596
|
-
const deletedAtPlaceholder = pushParam(params, null);
|
|
597
|
-
const idPlaceholder = pushParam(params, id);
|
|
594
|
+
const deletedAtPlaceholder = pushParam(dialect, params, null);
|
|
595
|
+
const idPlaceholder = pushParam(dialect, params, id);
|
|
598
596
|
return {
|
|
599
|
-
text: `UPDATE ${quoteIdentifier(table.name)} SET ${quoteIdentifier(deletedAtColumn)} = ${deletedAtPlaceholder} WHERE ${quoteIdentifier(table.primaryKey)} = ${idPlaceholder} AND ${qualifyColumn(table.name, deletedAtColumn)} IS NOT NULL${returningSuffix(returningColumns)}`,
|
|
597
|
+
text: `UPDATE ${quoteIdentifier(dialect, table.name)} SET ${quoteIdentifier(dialect, deletedAtColumn)} = ${deletedAtPlaceholder} WHERE ${quoteIdentifier(dialect, table.primaryKey)} = ${idPlaceholder} AND ${qualifyColumn(dialect, table.name, deletedAtColumn)} IS NOT NULL${returningSuffix(dialect, returningColumns)}`,
|
|
600
598
|
params
|
|
601
599
|
};
|
|
602
600
|
}
|
|
603
|
-
function buildDeleteByIdQuery(table, id) {
|
|
601
|
+
function buildDeleteByIdQuery(dialect, table, id) {
|
|
604
602
|
const params = [];
|
|
605
|
-
const idPlaceholder = pushParam(params, id);
|
|
606
|
-
const returning = returningSuffix(`${quoteIdentifier(table.primaryKey)} AS ${quoteIdentifier("deleted_id")}`);
|
|
603
|
+
const idPlaceholder = pushParam(dialect, params, id);
|
|
604
|
+
const returning = returningSuffix(dialect, `${quoteIdentifier(dialect, table.primaryKey)} AS ${quoteIdentifier(dialect, "deleted_id")}`);
|
|
607
605
|
return {
|
|
608
|
-
text: `DELETE FROM ${quoteIdentifier(table.name)} WHERE ${quoteIdentifier(table.primaryKey)} = ${idPlaceholder}${returning}`,
|
|
606
|
+
text: `DELETE FROM ${quoteIdentifier(dialect, table.name)} WHERE ${quoteIdentifier(dialect, table.primaryKey)} = ${idPlaceholder}${returning}`,
|
|
609
607
|
params
|
|
610
608
|
};
|
|
611
609
|
}
|
|
612
|
-
function buildConditionalWriteQuery(table, operation, changes, options, returning) {
|
|
610
|
+
function buildConditionalWriteQuery(dialect, table, operation, changes, options, returning) {
|
|
613
611
|
for (const key of [
|
|
614
612
|
"joins",
|
|
615
613
|
"groupBy",
|
|
@@ -624,10 +622,10 @@ function buildConditionalWriteQuery(table, operation, changes, options, returnin
|
|
|
624
622
|
throw new Error(`Conditional writes do not support ${key}.`);
|
|
625
623
|
}
|
|
626
624
|
const params = [];
|
|
627
|
-
const predicate = buildAdvancedWhereClause(table.name, options.where ?? {}, options.whereNodes ?? []);
|
|
625
|
+
const predicate = buildAdvancedWhereClause(dialect, table.name, options.where ?? {}, options.whereNodes ?? []);
|
|
628
626
|
if (!predicate.clause)
|
|
629
627
|
throw new Error("Conditional writes require an explicit predicate.");
|
|
630
|
-
if (returning !== undefined &&
|
|
628
|
+
if (returning !== undefined && dialect.driver === "mysql")
|
|
631
629
|
throw new Error("Mutation RETURNING is not supported on MySQL.");
|
|
632
630
|
const columns = returning ?? [table.primaryKey];
|
|
633
631
|
if (!columns.length || columns.some((column) => !table.columns.includes(column)))
|
|
@@ -641,13 +639,13 @@ function buildConditionalWriteQuery(table, operation, changes, options, returnin
|
|
|
641
639
|
throw new Error("Conditional updates require at least one value.");
|
|
642
640
|
if (entries.some(([column]) => column === table.primaryKey || !table.columns.includes(column)))
|
|
643
641
|
throw new Error("Conditional updates require declared non-primary-key columns.");
|
|
644
|
-
const assignments = entries.map(([column, value]) => `${quoteIdentifier(column)} = ${pushParam(params, value)}`);
|
|
645
|
-
prefix = `UPDATE ${quoteIdentifier(table.name)} SET ${assignments.join(", ")}`;
|
|
642
|
+
const assignments = entries.map(([column, value]) => `${quoteIdentifier(dialect, column)} = ${pushParam(dialect, params, value)}`);
|
|
643
|
+
prefix = `UPDATE ${quoteIdentifier(dialect, table.name)} SET ${assignments.join(", ")}`;
|
|
646
644
|
} else
|
|
647
|
-
prefix = `DELETE FROM ${quoteIdentifier(table.name)}`;
|
|
648
|
-
const { clause } = buildQueryWhereClause(table, options, options.whereNodes ?? [], params);
|
|
645
|
+
prefix = `DELETE FROM ${quoteIdentifier(dialect, table.name)}`;
|
|
646
|
+
const { clause } = buildQueryWhereClause(dialect, table, options, options.whereNodes ?? [], params);
|
|
649
647
|
return {
|
|
650
|
-
text: prefix + clause + returningSuffix(columns.map(quoteIdentifier).join(", ")),
|
|
648
|
+
text: prefix + clause + returningSuffix(dialect, columns.map((column) => quoteIdentifier(dialect, column)).join(", ")),
|
|
651
649
|
params
|
|
652
650
|
};
|
|
653
651
|
}
|