You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`time.Time` and `url.URL` need to be used as is. That is, you can not use a type `Foo` being `type Foo time.Time`. `time.Time` and `url.URL` are types that are treated in a special way, if you do that, it would be the same as saying `type Foo struct { ... }` and kallax would no longer be able to identify the correct type.
604
606
* Multidimensional arrays or slices are **not supported** except inside a JSON field.
605
607
608
+
## Custom operators
609
+
610
+
You can create custom operators with kallax using the `NewOperator` and `NewMultiOperator` functions.
611
+
612
+
`NewOperator` creates an operator with the specified format. It returns a function that given a schema field and a value returns a condition.
613
+
614
+
The format is a string in which `:col:` will get replaced with the schema field and `:arg:` will be replaced with the value.
615
+
616
+
```go
617
+
varGt = kallax.NewOperator(":col: > :arg:")
618
+
619
+
// can be used like this:
620
+
query.Where(Gt(SomeSchemaField, 9000))
621
+
```
622
+
623
+
`NewMultiOperator` does exactly the same as the previous one, but it accepts a variable number of values.
624
+
625
+
```go
626
+
varIn = kallax.NewMultiOperator(":col: IN :arg:")
627
+
628
+
// can be used like this:
629
+
query.Where(In(SomeSchemaField, 4, 5, 6))
630
+
```
631
+
632
+
This function already takes care of wrapping `:arg:` with parenthesis.
633
+
634
+
### Further customization
635
+
636
+
If you need further customization, you can create your own custom operator.
637
+
638
+
You need these things:
639
+
640
+
* A condition constructor (the operator itself) that takes the field and the values to create the proper SQL expression.
641
+
* A `ToSqler` that yields your SQL expression.
642
+
643
+
Imagine we want a greater than operator that only works with integers.
With most of the operators, `NewOperator` and `NewMultiOperator` are enough, so the usage of these functions is preferred over the completely custom approach. Use it only if there is no other way to build your custom operator.
668
+
606
669
## Debug SQL queries
607
670
608
671
It is possible to debug the SQL queries being executed with kallax. To do that, you just need to call the `Debug` method of a store. This returns a new store with debugging enabled.
0 commit comments