Skip to content

Commit

Permalink
fix: limit Terms query types to primitives and their derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
GokselKUCUKSAHIN committed Feb 19, 2025
1 parent 0942520 commit b3f9c3b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion es/terms_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type termsType Object
// Returns:
//
// An es.termsType object containing the specified terms query.
func Terms(key string, values ...any) termsType {
func Terms[T primitive](key string, values ...T) termsType {
return termsType{
"terms": Object{
key: values,
Expand Down
2 changes: 1 addition & 1 deletion es/terms_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Test_Terms_should_exist_on_es_package(t *testing.T) {
t.Parallel()
// Given When Then
assert.NotNil(t, es.Terms)
assert.NotNil(t, es.Terms[string])
}

func Test_Terms_should_create_json_with_terms_field_inside_query(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions es/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ type Object map[string]any

type Array []any

type signed interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}

type unsigned interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type integer interface {
signed | unsigned
}

type float interface {
~float32 | ~float64
}

type complexNumber interface {
~complex64 | ~complex128
}

type number interface {
integer | float | complexNumber
}

type primitive interface {
number | ~string | ~bool | ~rune
}

func unsafeIsNil(x any) bool {
return (*[2]uintptr)(unsafe.Pointer(&x))[1] == 0
}
Expand Down

0 comments on commit b3f9c3b

Please sign in to comment.