Skip to content

Commit

Permalink
Consider numbers bit size for type-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Apr 5, 2023
1 parent 896212f commit 0da9fdd
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 111 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ For non-native types (such as `*null.Time`), you should always use the `filterTy
Available broad types are:
- `text` / `text[]`
- `bool` / `bool[]`
- `int` / `int[]`
- `uint` / `uint[]`
- `float` / `float[]`
- `int8` / `int8[]`, `int16` / `int16[]`, `int32` / `int32[]`, `int64` / `int64[]`
- `uint` / `uint[]`, `uint16` / `uint16[]`, `uint32` / `uint32[]`, `uint64` / `uint64[]`
- `float32` / `float32[]`, `float64` / `float64[]`
- `time` / `time[]`
- `-`: unsupported data type. Fields tagged with `-` will be ignored in filters and search: no condition will be added to the `WHERE` clause.

Expand Down Expand Up @@ -370,11 +370,11 @@ func init() {
switch dataType {
case filter.DataTypeTextArray, filter.DataTypeTimeArray:
return bindArrayArg[string](tx, query, f, dataType)
case filter.DataTypeFloatArray:
case filter.DataTypeFloat32Array, filter.DataTypeFloat64Array:
return bindArrayArg[float64](tx, query, f, dataType)
case filter.DataTypeUintArray:
case filter.DataTypeUint8Array, filter.DataTypeUint16Array, filter.DataTypeUint32Array, filter.DataTypeUint64Array:
return bindArrayArg[uint64](tx, query, f, dataType)
case filter.DataTypeIntArray:
case filter.DataTypeInt8Array, filter.DataTypeInt16Array, filter.DataTypeInt32Array, filter.DataTypeInt64Array:
return bindArrayArg[int64](tx, query, f, dataType)
}

Expand Down
48 changes: 24 additions & 24 deletions operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestEquals(t *testing.T) {
op: "$eq",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeFloat,
dataType: DataTypeUint64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestNotEquals(t *testing.T) {
op: "$ne",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeFloat,
dataType: DataTypeUint64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestGreaterThan(t *testing.T) {
op: "$gt",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -168,7 +168,7 @@ func TestGreaterThan(t *testing.T) {
op: "$gt",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeIntArray,
dataType: DataTypeInt64Array,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -185,7 +185,7 @@ func TestGreaterThan(t *testing.T) {
op: "$gt",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestLowerThan(t *testing.T) {
op: "$lt",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -232,7 +232,7 @@ func TestLowerThan(t *testing.T) {
op: "$lt",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeIntArray,
dataType: DataTypeInt64Array,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -249,7 +249,7 @@ func TestLowerThan(t *testing.T) {
op: "$lt",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestGreaterThanEqual(t *testing.T) {
op: "$gte",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -296,7 +296,7 @@ func TestGreaterThanEqual(t *testing.T) {
op: "$gte",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeIntArray,
dataType: DataTypeInt64Array,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -313,7 +313,7 @@ func TestGreaterThanEqual(t *testing.T) {
op: "$gte",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestLowerThanEqual(t *testing.T) {
op: "$lte",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -360,7 +360,7 @@ func TestLowerThanEqual(t *testing.T) {
op: "$lte",
filter: &Filter{Field: "age", Args: []string{"18"}},
column: "`test_models`.`age`",
dataType: DataTypeIntArray,
dataType: DataTypeInt64Array,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand All @@ -377,7 +377,7 @@ func TestLowerThanEqual(t *testing.T) {
op: "$lte",
filter: &Filter{Field: "age", Args: []string{"test"}},
column: "`test_models`.`age`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestStarts(t *testing.T) {
op: "$starts",
filter: &Filter{Field: "name", Args: []string{"te%_st"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestEnds(t *testing.T) {
op: "$ends",
filter: &Filter{Field: "name", Args: []string{"te%_st"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestContains(t *testing.T) {
op: "$cont",
filter: &Filter{Field: "name", Args: []string{"te%_st"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -633,7 +633,7 @@ func TestNotContains(t *testing.T) {
op: "$excl",
filter: &Filter{Field: "name", Args: []string{"te%_st"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -697,7 +697,7 @@ func TestIn(t *testing.T) {
op: "$in",
filter: &Filter{Field: "name", Args: []string{"18", "val2"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -761,7 +761,7 @@ func TestNotIn(t *testing.T) {
op: "$notin",
filter: &Filter{Field: "name", Args: []string{"18", "val2"}},
column: "`test_models`.`name`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -851,7 +851,7 @@ func TestBetween(t *testing.T) {
op: "$between",
filter: &Filter{Field: "age", Args: []string{"18", "25"}},
column: "`test_models`.`age`",
dataType: DataTypeUint,
dataType: DataTypeUint64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -902,7 +902,7 @@ func TestBetween(t *testing.T) {
op: "$between",
filter: &Filter{Field: "age", Args: []string{"18", "val2"}},
column: "`test_models`.`age`",
dataType: DataTypeUint,
dataType: DataTypeUint64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -949,7 +949,7 @@ func TestIsTrue(t *testing.T) {
op: "$istrue",
filter: &Filter{Field: "is_active"},
column: "`test_models`.`is_active`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down Expand Up @@ -996,7 +996,7 @@ func TestIsFalse(t *testing.T) {
op: "$isfalse",
filter: &Filter{Field: "is_active"},
column: "`test_models`.`is_active`",
dataType: DataTypeInt,
dataType: DataTypeInt64,
want: map[string]clause.Clause{
"WHERE": {
Name: "WHERE",
Expand Down
Loading

0 comments on commit 0da9fdd

Please sign in to comment.