replaced NoCoalesce with NullFallback and updated tests

This commit is contained in:
Gani Georgiev
2026-01-15 18:06:15 +02:00
parent b0a5bce4c4
commit bbd7f4e4ae
7 changed files with 85 additions and 55 deletions

View File

@@ -10,15 +10,26 @@ import (
"github.com/pocketbase/pocketbase/tools/list"
)
type NullFallbackPreference int
const (
NullFallbackAuto NullFallbackPreference = 0
NullFallbackDisabled NullFallbackPreference = 1
NullFallbackEnforced NullFallbackPreference = 2
)
// ResolverResult defines a single FieldResolver.Resolve() successfully parsed result.
type ResolverResult struct {
// Identifier is the plain SQL identifier/column that will be used
// in the final db expression as left or right operand.
Identifier string
// NoCoalesce instructs to not use COALESCE or NULL fallbacks
// when building the identifier expression.
NoCoalesce bool
// NullFallback specify the preference for how NULL or empty values
// should be resolved (default to "auto").
//
// Set to NullFallbackDisabled to prevent any COALESCE or NULL fallbacks.
// Set to NullFallbackEnforced to prefer COALESCE or NULL fallbacks when needed.
NullFallback NullFallbackPreference
// Params is a map with db placeholder->value pairs that will be added
// to the query when building both resolved operands/sides in a single expression.
@@ -103,7 +114,7 @@ func (r *SimpleFieldResolver) Resolve(field string) (*ResolverResult, error) {
}
return &ResolverResult{
NoCoalesce: true,
NullFallback: NullFallbackDisabled,
Identifier: fmt.Sprintf(
"JSON_EXTRACT([[%s]], '%s')",
inflector.Columnify(parts[0]),