-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix $in for github.com/lib/pq, add support for jackc/pgx
Add WithArrayDriver to support different database drivers that require specific types for arrays. Added an integration test that uses jackc/pgx. Co-authored-by: Koen Bollen <[email protected]>
- Loading branch information
1 parent
1941b3a
commit aae2ae5
Showing
12 changed files
with
317 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
package filter | ||
|
||
type Nest struct { | ||
} | ||
import ( | ||
"database/sql" | ||
"database/sql/driver" | ||
) | ||
|
||
type Option func(*Converter) | ||
|
||
// WithNestedJSONB is an option to specify the column name that contains the nested | ||
// JSONB object. (e.g. you have a column named `metadata` that contains a nested | ||
// JSONB object) | ||
// | ||
// When this option is set, all keys in the query will be directed to the nested | ||
// column, you can exempt some keys by providing them as the second argument. | ||
// | ||
// Example: | ||
// | ||
// c := filter.NewConverter(filter.WithNestedJSONB("metadata", "created_at", "updated_at")) | ||
func WithNestedJSONB(column string, exemption ...string) Option { | ||
return func(c *Converter) { | ||
c.nestedColumn = column | ||
c.nestedExemptions = exemption | ||
} | ||
} | ||
|
||
// WithArrayDriver is an option to specify a custom driver to convert array values | ||
// to Postgres driver compatible types. | ||
// An example for github.com/lib/pq is: | ||
// | ||
// c := filter.NewConverter(filter.WithArrayDriver(pq.Array)) | ||
// | ||
// For github.com/jackc/pgx this option is not needed. | ||
func WithArrayDriver(f func(a any) interface { | ||
driver.Valuer | ||
sql.Scanner | ||
}) Option { | ||
return func(c *Converter) { | ||
c.arrayDriver = f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Integration tests are in a separate module so that the dependencies are not required for normal builds. | ||
|
||
Requires docker to run the tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.