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` fields will be truncated to remove its nanoseconds on `Save`, `Insert` or `Update`, since PostgreSQL will not be able to store them. PostgreSQL stores times with timezones as UTC internally. So, times will come back as UTC (you can use `Local` method to convert them back to the local timezone). You can change the timezone that will be used to bring times back from the database in [the PostgreSQL configuration](https://www.postgresql.org/docs/9.6/static/datatype-datetime.html).
605
607
* Multidimensional arrays or slices are **not supported** except inside a JSON field.
606
608
609
+
## Custom operators
610
+
611
+
You can create custom operators with kallax using the `NewOperator` and `NewMultiOperator` functions.
612
+
613
+
`NewOperator` creates an operator with the specified format. It returns a function that given a schema field and a value returns a condition.
614
+
615
+
The format is a string in which `:col:` will get replaced with the schema field and `:arg:` will be replaced with the value.
616
+
617
+
```go
618
+
varGt = kallax.NewOperator(":col: > :arg:")
619
+
620
+
// can be used like this:
621
+
query.Where(Gt(SomeSchemaField, 9000))
622
+
```
623
+
624
+
`NewMultiOperator` does exactly the same as the previous one, but it accepts a variable number of values.
625
+
626
+
```go
627
+
varIn = kallax.NewMultiOperator(":col: IN :arg:")
628
+
629
+
// can be used like this:
630
+
query.Where(In(SomeSchemaField, 4, 5, 6))
631
+
```
632
+
633
+
This function already takes care of wrapping `:arg:` with parenthesis.
634
+
635
+
### Further customization
636
+
637
+
If you need further customization, you can create your own custom operator.
638
+
639
+
You need these things:
640
+
641
+
* A condition constructor (the operator itself) that takes the field and the values to create the proper SQL expression.
642
+
* A `ToSqler` that yields your SQL expression.
643
+
644
+
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.
669
+
607
670
## Debug SQL queries
608
671
609
672
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