replaced exists bool db scans with int for broader drivers compatibility

This commit is contained in:
Gani Georgiev
2025-01-20 14:16:00 +02:00
parent 0ebe9c4faa
commit a4a228b368
11 changed files with 25 additions and 23 deletions

View File

@@ -734,7 +734,7 @@ func realtimeCanAccessRecord(
return false
}
var exists bool
var exists int
q := app.DB().Select("(1)").
From(record.Collection().Name).
@@ -751,5 +751,5 @@ func realtimeCanAccessRecord(
err = q.Limit(1).Row(&exists)
return err == nil && exists
return err == nil && exists > 0
}

View File

@@ -314,9 +314,9 @@ func recordCreate(optFinalizer func(data any) error) func(e *core.RequestEvent)
resolver.UpdateQuery(ruleQuery)
var exists bool
var exists int
err = ruleQuery.Limit(1).Row(&exists)
if err != nil || !exists {
if err != nil || exists == 0 {
return e.BadRequestError("Failed to create record", fmt.Errorf("create rule failure: %w", err))
}
}
@@ -720,9 +720,9 @@ func hasAuthManageAccess(app core.App, requestInfo *core.RequestInfo, collection
resolver.UpdateQuery(query)
var exists bool
var exists int
err = query.Limit(1).Row(&exists)
return err == nil && exists
return err == nil && exists > 0
}

View File

@@ -146,7 +146,7 @@ func wantsMFA(e *core.RequestEvent, record *core.Record) (bool, error) {
return true, err
}
var exists bool
var exists int
query := e.App.RecordQuery(record.Collection()).
Select("(1)").
@@ -165,7 +165,7 @@ func wantsMFA(e *core.RequestEvent, record *core.Record) (bool, error) {
return true, err
}
return exists, nil
return exists > 0, nil
}
// checkMFA handles any MFA auth checks that needs to be performed for the specified request event.