Skip to content

Commit aff647d

Browse files
paganotonizepatriknaemonokyrozeterareggieriser
authored
Latest Development (#716)
* fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Latest from master (#620) * Latest from development (#617) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * adding goreleaser syntaz (#619) Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Resolve issues in UPDATE and DELETE when using schemas (#618) * Resolve MySQL issues and improve test migrations * Bump CockroachDB to maintained and supported versions Version 2.1 has reached EoL in 2019 Signed-off-by: aeneasr <[email protected]> * Use `PaginatorPageKey` and `PaginatorPerPageKey` variables (#615) * update pagination_test * Pass Time structure into timestamp update functions. (#625) Closes #624 * Allow nullable JSONB and resolve MySQL regression (#639) * Allow passing args to `Order` (#630) * Added connection maximum idle time configuration (#635) This PR add the possibility to configure the connection maximum idle time (https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime). Closes #632 BREAKING CHANGE: Requires Go 1.15 from now on. * Bump sqlite to 3.35.4 / 1.14.7 (#642) * Update pg, pgx, sqlx (#643) - `jackc/pgx` to version `v4.11.0`. - `jmoiron/sqlx` to version`v1.3.3` - `lib/pq` to version`v1.10.1` * Fix Inner has many associations when passing on multiple arguments (#633) * Fix Inner has many associations when passing on multiple arguments for inner fields * Fix broken tests * clean up extractFieldAndInnerFields function Co-authored-by: hackerman <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * Remove many to many TX condition for EagerPreload (#645) * Remove the need to use Tx when loading many to many associations * replace TX access to create a new tx.Store.Transaction() object * Added fix/tests for has_many with pointer foreign key (#647) Co-authored-by: Antonio Pagano <[email protected]> * Export WhereID, Alias, WhereNamedID (#637) This patch export some model convenience functions which are useful when constructing queries outside of pop: custom updates, deletes, inserts, ... Signed-off-by: aeneasr <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * fix: log model values everywhere (#656) Some SQL logs were missing the values as argument. This adds all places * Add delete to query builder (#658) This allows writing delete queries without knowing the exact primary key or for composite keys. `Destroy` only allows to delete by primary key, but there are many cases where you want to delete multiple rows or by some other query than the ID. See #29 * Sort down migrations (#657) Basically, just reversing the up migration order does not work, as that puts "all" migrations before specific ones. Therefore, I added implemented the proper `Less` function for down migrations explicitly. Related #533 Co-authored-by: hackerman <[email protected]> * Preserve eager information when validating models (#664) (#665) Co-authored-by: Karl Haas <[email protected]> * Migrate from packr to fs (#667) * Updating Pgx (#660) * adding goreleaser syntaz * updating pgx now really * Migrate from packr to fs * Migrate to v6 * Use old build tags * Update error handling * Fix error after rebase * Fix error handling * Fix filenames for embed Go 1.16 usage Co-authored-by: Antonio Pagano <[email protected]> * Task merging master (#669) * v5.3.4 (#644) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Latest from master (#620) * Latest from development (#617) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * adding goreleaser syntaz (#619) Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Resolve issues in UPDATE and DELETE when using schemas (#618) * Resolve MySQL issues and improve test migrations * Bump CockroachDB to maintained and supported versions Version 2.1 has reached EoL in 2019 Signed-off-by: aeneasr <[email protected]> * Use `PaginatorPageKey` and `PaginatorPerPageKey` variables (#615) * update pagination_test * Pass Time structure into timestamp update functions. (#625) Closes #624 * Allow nullable JSONB and resolve MySQL regression (#639) * Allow passing args to `Order` (#630) * Added connection maximum idle time configuration (#635) This PR add the possibility to configure the connection maximum idle time (https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime). Closes #632 BREAKING CHANGE: Requires Go 1.15 from now on. * Bump sqlite to 3.35.4 / 1.14.7 (#642) * Update pg, pgx, sqlx (#643) - `jackc/pgx` to version `v4.11.0`. - `jmoiron/sqlx` to version`v1.3.3` - `lib/pq` to version`v1.10.1` * Fix Inner has many associations when passing on multiple arguments (#633) * Fix Inner has many associations when passing on multiple arguments for inner fields * Fix broken tests * clean up extractFieldAndInnerFields function Co-authored-by: hackerman <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * Remove many to many TX condition for EagerPreload (#645) * Remove the need to use Tx when loading many to many associations * replace TX access to create a new tx.Store.Transaction() object * Added fix/tests for has_many with pointer foreign key (#647) Co-authored-by: Antonio Pagano <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> * Updating Pgx (#660) * adding goreleaser syntaz * updating pgx now really * tidying Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> * Replace removed command The command has been removed from the CLI. This patch introduces a new mechanism to reliably dump the SQL schema for CockroachDB. * Resolve `EagerPreload` panic caused for pointer references Resolves a panic where `EagerPreload` tried to set `reflect.Struct` for a `reflect.Pointer` on 1.. associations. Signed-off-by: aeneasr <[email protected]> * Resolve `EagerPreload` panic caused by NullUUID Resolves a panic where `EagerPreload` was trying to set UUID into NullUUID. Signed-off-by: aeneasr <[email protected]> * Support pointers in n+1 `Eager` loading Resolves an issue where n+1 eager associations would error with a double pointer in `associations.ForStruct`. Signed-off-by: aeneasr <[email protected]> * Improve error message of associations.ForStruct Signed-off-by: aeneasr <[email protected]> * Add test cases for `IsZeroOfUnderlyingType` Signed-off-by: aeneasr <[email protected]> * Resolve an obscure bug where empty structs got loaded for NULL foreign keys Closes #139 Signed-off-by: aeneasr <[email protected]> * Resolve association regression in finders.go Signed-off-by: aeneasr <[email protected]> * Use dedicated migrations for preloading regression test Signed-off-by: aeneasr <[email protected]> * Fix code regression Signed-off-by: aeneasr <[email protected]> * Fix test code regressions Signed-off-by: aeneasr <[email protected]> * Fix sql migration order Signed-off-by: aeneasr <[email protected]> * Resolve order issue in test * Ignore order when testing for nil values in test * Pass Context during exec in create. (#688) * feat: support embedded struct fields (#691) * test: use `T.TempDir` to create temporary test directory This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `ioutil.TempDir` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <[email protected]> * task: adding next version number * fix: associations for embedded fields * test: add other fields to duplicate type, because of some kind of query builder cache * feat: implement UpdateQuery This commit introduces a new function, UpdateQuery, that enables updating all rows matched by a query. It can be used for conditional updates. * feat: allow customizing the time used for CreatedAt/UpdatedAt * feat: allow using SQLite without built tag via include (#662) * preparing go1.18 support (package specific workflow) * feat: darwin arm64 binary (#690) * feat: arm64 binary * v6.0.2 (#704) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Latest from master (#620) * Latest from development (#617) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * adding goreleaser syntaz (#619) Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Resolve issues in UPDATE and DELETE when using schemas (#618) * Resolve MySQL issues and improve test migrations * Bump CockroachDB to maintained and supported versions Version 2.1 has reached EoL in 2019 Signed-off-by: aeneasr <[email protected]> * Use `PaginatorPageKey` and `PaginatorPerPageKey` variables (#615) * update pagination_test * Pass Time structure into timestamp update functions. (#625) Closes #624 * Allow nullable JSONB and resolve MySQL regression (#639) * Allow passing args to `Order` (#630) * Added connection maximum idle time configuration (#635) This PR add the possibility to configure the connection maximum idle time (https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime). Closes #632 BREAKING CHANGE: Requires Go 1.15 from now on. * Bump sqlite to 3.35.4 / 1.14.7 (#642) * Update pg, pgx, sqlx (#643) - `jackc/pgx` to version `v4.11.0`. - `jmoiron/sqlx` to version`v1.3.3` - `lib/pq` to version`v1.10.1` * Fix Inner has many associations when passing on multiple arguments (#633) * Fix Inner has many associations when passing on multiple arguments for inner fields * Fix broken tests * clean up extractFieldAndInnerFields function Co-authored-by: hackerman <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * Remove many to many TX condition for EagerPreload (#645) * Remove the need to use Tx when loading many to many associations * replace TX access to create a new tx.Store.Transaction() object * Added fix/tests for has_many with pointer foreign key (#647) Co-authored-by: Antonio Pagano <[email protected]> * Export WhereID, Alias, WhereNamedID (#637) This patch export some model convenience functions which are useful when constructing queries outside of pop: custom updates, deletes, inserts, ... Signed-off-by: aeneasr <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * fix: log model values everywhere (#656) Some SQL logs were missing the values as argument. This adds all places * Add delete to query builder (#658) This allows writing delete queries without knowing the exact primary key or for composite keys. `Destroy` only allows to delete by primary key, but there are many cases where you want to delete multiple rows or by some other query than the ID. See #29 * Sort down migrations (#657) Basically, just reversing the up migration order does not work, as that puts "all" migrations before specific ones. Therefore, I added implemented the proper `Less` function for down migrations explicitly. Related #533 Co-authored-by: hackerman <[email protected]> * Preserve eager information when validating models (#664) (#665) Co-authored-by: Karl Haas <[email protected]> * Migrate from packr to fs (#667) * Updating Pgx (#660) * adding goreleaser syntaz * updating pgx now really * Migrate from packr to fs * Migrate to v6 * Use old build tags * Update error handling * Fix error after rebase * Fix error handling * Fix filenames for embed Go 1.16 usage Co-authored-by: Antonio Pagano <[email protected]> * Task merging master (#669) * v5.3.4 (#644) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Latest from master (#620) * Latest from development (#617) * fix: improve model ID field customization (#604) Updates places where `"id"` was hardcoded instead of using `model.IDField()`. * Ensure uninitialized map is initialized when unmarshaling json Add tests for this scenario * exclude migration_table_name from connection string * add test for OptionsString * Add support for pointer FKs when preloading a belongs_to association (#602) * feat: support context-aware tablenames (#614) This patch adds a feature which enables pop to pass down the connection context to the model's TableName() function by implementing TableName(ctx context.Context) string. The context can be used to dynamically generate tablenames which can be important for prefixed or generic tables and other use cases. * Bump pg deps (#616) * Reset to development * bumping pgx and pgconn versions Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * adding goreleaser syntaz (#619) Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> * Resolve issues in UPDATE and DELETE when using schemas (#618) * Resolve MySQL issues and improve test migrations * Bump CockroachDB to maintained and supported versions Version 2.1 has reached EoL in 2019 Signed-off-by: aeneasr <[email protected]> * Use `PaginatorPageKey` and `PaginatorPerPageKey` variables (#615) * update pagination_test * Pass Time structure into timestamp update functions. (#625) Closes #624 * Allow nullable JSONB and resolve MySQL regression (#639) * Allow passing args to `Order` (#630) * Added connection maximum idle time configuration (#635) This PR add the possibility to configure the connection maximum idle time (https://golang.org/pkg/database/sql/#DB.SetConnMaxIdleTime). Closes #632 BREAKING CHANGE: Requires Go 1.15 from now on. * Bump sqlite to 3.35.4 / 1.14.7 (#642) * Update pg, pgx, sqlx (#643) - `jackc/pgx` to version `v4.11.0`. - `jmoiron/sqlx` to version`v1.3.3` - `lib/pq` to version`v1.10.1` * Fix Inner has many associations when passing on multiple arguments (#633) * Fix Inner has many associations when passing on multiple arguments for inner fields * Fix broken tests * clean up extractFieldAndInnerFields function Co-authored-by: hackerman <[email protected]> Co-authored-by: Antonio Pagano <[email protected]> * Remove many to many TX condition for EagerPreload (#645) * Remove the need to use Tx when loading many to many associations * replace TX access to create a new tx.Store.Transaction() object * Added fix/tests for has_many with pointer foreign key (#647) Co-authored-by: Antonio Pagano <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> * Updating Pgx (#660) * adding goreleaser syntaz * updating pgx now really * tidying Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> * Replace removed command The command has been removed from the CLI. This patch introduces a new mechanism to reliably dump the SQL schema for CockroachDB. * Resolve `EagerPreload` panic caused for pointer references Resolves a panic where `EagerPreload` tried to set `reflect.Struct` for a `reflect.Pointer` on 1.. associations. Signed-off-by: aeneasr <[email protected]> * Resolve `EagerPreload` panic caused by NullUUID Resolves a panic where `EagerPreload` was trying to set UUID into NullUUID. Signed-off-by: aeneasr <[email protected]> * Support pointers in n+1 `Eager` loading Resolves an issue where n+1 eager associations would error with a double pointer in `associations.ForStruct`. Signed-off-by: aeneasr <[email protected]> * Improve error message of associations.ForStruct Signed-off-by: aeneasr <[email protected]> * Add test cases for `IsZeroOfUnderlyingType` Signed-off-by: aeneasr <[email protected]> * Resolve an obscure bug where empty structs got loaded for NULL foreign keys Closes #139 Signed-off-by: aeneasr <[email protected]> * Resolve association regression in finders.go Signed-off-by: aeneasr <[email protected]> * Use dedicated migrations for preloading regression test Signed-off-by: aeneasr <[email protected]> * Fix code regression Signed-off-by: aeneasr <[email protected]> * Fix test code regressions Signed-off-by: aeneasr <[email protected]> * Fix sql migration order Signed-off-by: aeneasr <[email protected]> * Resolve order issue in test * Ignore order when testing for nil values in test * Pass Context during exec in create. (#688) * feat: support embedded struct fields (#691) * test: use `T.TempDir` to create temporary test directory This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `ioutil.TempDir` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <[email protected]> * task: adding next version number Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> Co-authored-by: karlhaas <[email protected]> Co-authored-by: Karl Haas <[email protected]> Co-authored-by: Matthias Fasching <[email protected]> Co-authored-by: Martin Eigenbrodt <[email protected]> Co-authored-by: Eng Zer Jun <[email protected]> * play time * chore: updates * chore: reset formatting Co-authored-by: Antonio Pagano <[email protected]> Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> Co-authored-by: karlhaas <[email protected]> Co-authored-by: Karl Haas <[email protected]> Co-authored-by: Matthias Fasching <[email protected]> Co-authored-by: Martin Eigenbrodt <[email protected]> Co-authored-by: Eng Zer Jun <[email protected]> * task: adding release-env in the gitignore * task: its release-env * task: adding .release-env to the release-dry-run make * task: changing the order of release steps * task:changing the token Co-authored-by: Patrik <[email protected]> Co-authored-by: Michael Montgomery <[email protected]> Co-authored-by: kyrozetera <[email protected]> Co-authored-by: Reggie Riser <[email protected]> Co-authored-by: hackerman <[email protected]> Co-authored-by: Stanislas Michalak <[email protected]> Co-authored-by: Larry M Jordan <[email protected]> Co-authored-by: Brian Buchholz <[email protected]> Co-authored-by: Mike Pontillo <[email protected]> Co-authored-by: Benjamin Blattberg <[email protected]> Co-authored-by: Jonathan Duck <[email protected]> Co-authored-by: Arthur Knoepflin <[email protected]> Co-authored-by: karlhaas <[email protected]> Co-authored-by: Karl Haas <[email protected]> Co-authored-by: Matthias Fasching <[email protected]> Co-authored-by: Martin Eigenbrodt <[email protected]> Co-authored-by: Eng Zer Jun <[email protected]> Co-authored-by: Grant Zvolsky <[email protected]> Co-authored-by: Andrew Hobson <[email protected]> Co-authored-by: Yonghwan SO <[email protected]> Co-authored-by: Joey Freeland <[email protected]>
1 parent f8046b2 commit aff647d

19 files changed

+505
-50
lines changed

.github/workflows/release.yml

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ jobs:
99
name: Release
1010
runs-on: ubuntu-latest
1111
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v3
14+
1215
- name: Set up Go 1.17
1316
uses: actions/setup-go@v3
1417
with:
1518
go-version: 1.17
16-
id: go
17-
18-
- name: Checkout Code
19-
uses: actions/checkout@v3
2019

2120
- name: Fetch tags
2221
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
2322

24-
- name: Run GoReleaser
25-
uses: goreleaser/goreleaser-action@v2
26-
env:
27-
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
28-
with:
29-
version: latest
30-
args: release --rm-dist
23+
- name: setup release environment
24+
run: |-
25+
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_TOKEN }}' > .release-env
26+
27+
- name: release publish
28+
run: make release
29+

.github/workflows/tests.yml

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
go-version:
1515
- "1.16.x"
1616
- "1.17.x"
17+
- "1.18.x"
1718

1819
services:
1920
mysql:
@@ -57,6 +58,7 @@ jobs:
5758
go-version:
5859
- "1.16.x"
5960
- "1.17.x"
61+
- "1.18.x"
6062

6163
services:
6264
postgres:
@@ -102,6 +104,7 @@ jobs:
102104
go-version:
103105
- "1.16.x"
104106
- "1.17.x"
107+
- "1.18.x"
105108

106109
steps:
107110
- uses: actions/checkout@v3
@@ -145,6 +148,7 @@ jobs:
145148
go-version:
146149
- "1.16.x"
147150
- "1.17.x"
151+
- "1.18.x"
148152

149153
steps:
150154
- uses: actions/checkout@v3
@@ -185,6 +189,7 @@ jobs:
185189
go-version:
186190
- "1.16.x"
187191
- "1.17.x"
192+
- "1.18.x"
188193
os:
189194
- "macos-latest"
190195
- "windows-latest"

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ testdata/migrations/schema.sql
3232
.grifter/
3333
vendor/
3434
.env
35+
.release-env
3536

3637
# test data
3738
cockroach-data/

.goreleaser.yml

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# GoReleaser config
22

3+
---
34
before:
45
hooks:
56
- go mod tidy
@@ -14,17 +15,32 @@ builds:
1415
- amd64
1516
env:
1617
- CGO_ENABLED=1
17-
- CC=o64-clang
18-
- CXX=o64-clang++
18+
- CC=/osxcross/target/bin/o64-clang
19+
- CXX=/osxcross/target/bin/o64-clang++
1920
flags:
2021
- -tags
2122
- sqlite
2223

23-
- id: pop_linux
24+
- id: pop_darwin_arm64
2425
binary: soda
2526
main: soda/main.go
27+
goos:
28+
- darwin
29+
goarch:
30+
- arm64
2631
env:
2732
- CGO_ENABLED=1
33+
- CC=/osxcross/target/bin/oa64-clang
34+
- CXX=/osxcross/target/bin/oa64-clang++
35+
flags:
36+
- -tags
37+
- sqlite
38+
39+
- id: pop_linux
40+
binary: soda
41+
main: soda/main.go
42+
env:
43+
- CGO_ENABLED=0
2844
flags:
2945
- -tags
3046
- sqlite

Makefile

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
PACKAGE_NAME := github.com/gobuffalo/pop
2+
GOLANG_CROSS_VERSION ?= v1.17.6
3+
14
TAGS ?= "sqlite"
25
GO_BIN ?= go
36

@@ -37,5 +40,42 @@ endif
3740
release-test:
3841
./test.sh
3942

43+
.PHONY: sysroot-pack
44+
sysroot-pack:
45+
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)
46+
47+
.PHONY: sysroot-unpack
48+
sysroot-unpack:
49+
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -
50+
51+
.PHONY: release-dry-run
52+
release-dry-run:
53+
@docker run \
54+
--rm \
55+
--privileged \
56+
-e CGO_ENABLED=1 \
57+
--env-file .release-env \
58+
-v /var/run/docker.sock:/var/run/docker.sock \
59+
-v `pwd`:/go/src/$(PACKAGE_NAME) \
60+
-v `pwd`/sysroot:/sysroot \
61+
-w /go/src/$(PACKAGE_NAME) \
62+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
63+
--rm-dist --skip-validate --skip-publish --snapshot
64+
65+
.PHONY: release
4066
release:
41-
release -y -f soda/cmd/version.go
67+
@if [ ! -f ".release-env" ]; then \
68+
echo "\033[91m.release-env is required for release\033[0m";\
69+
exit 1;\
70+
fi
71+
docker run \
72+
--rm \
73+
--privileged \
74+
-e CGO_ENABLED=1 \
75+
--env-file .release-env \
76+
-v /var/run/docker.sock:/var/run/docker.sock \
77+
-v `pwd`:/go/src/$(PACKAGE_NAME) \
78+
-v `pwd`/sysroot:/sysroot \
79+
-w /go/src/$(PACKAGE_NAME) \
80+
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
81+
release --rm-dist

associations/associations_for_struct.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ var associationBuilders = map[string]associationBuilder{}
2727
// it throws an error when it finds a field that does
2828
// not exist for a model.
2929
func ForStruct(s interface{}, fields ...string) (Associations, error) {
30+
return forStruct(s, s, fields)
31+
}
32+
33+
// forStruct is a recursive helper that passes the root model down for embedded fields
34+
func forStruct(parent, s interface{}, fields []string) (Associations, error) {
3035
t, v := getModelDefinition(s)
3136
if t.Kind() != reflect.Struct {
3237
return nil, fmt.Errorf("could not get struct associations: not a struct but %T", s)
@@ -74,7 +79,20 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {
7479

7580
// inline embedded field
7681
if f.Anonymous {
77-
innerAssociations, err := ForStruct(v.Field(i).Interface(), fields...)
82+
field := v.Field(i)
83+
// we need field to be a pointer, so that we can later set the value
84+
// if the embedded field is of type struct {...}, we have to take its address
85+
if field.Kind() != reflect.Ptr {
86+
field = field.Addr()
87+
}
88+
if fieldIsNil(field) {
89+
// initialize zero value
90+
field = reflect.New(field.Type().Elem())
91+
// we can only get in this case if v.Field(i) is a pointer type because it could not be nil otherwise
92+
// => it is safe to set it here as is
93+
v.Field(i).Set(field)
94+
}
95+
innerAssociations, err := forStruct(parent, field.Interface(), fields)
7896
if err != nil {
7997
return nil, err
8098
}
@@ -92,11 +110,12 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {
92110
for name, builder := range associationBuilders {
93111
tag := tags.Find(name)
94112
if !tag.Empty() {
113+
pt, pv := getModelDefinition(parent)
95114
params := associationParams{
96115
field: f,
97-
model: s,
98-
modelType: t,
99-
modelValue: v,
116+
model: parent,
117+
modelType: pt,
118+
modelValue: pv,
100119
popTags: tags,
101120
innerAssociations: fieldsWithInnerAssociation[f.Name],
102121
}

dialect.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type crudable interface {
1212
SelectMany(store, *Model, Query) error
1313
Create(store, *Model, columns.Columns) error
1414
Update(store, *Model, columns.Columns) error
15+
UpdateQuery(store, *Model, columns.Columns, Query) (int64, error)
1516
Destroy(store, *Model) error
1617
Delete(store, *Model, Query) error
1718
}

dialect_cockroach.go

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func (p *cockroach) Update(s store, model *Model, cols columns.Columns) error {
106106
return genericUpdate(s, model, cols, p)
107107
}
108108

109+
func (p *cockroach) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
110+
return genericUpdateQuery(s, model, cols, p, query, sqlx.DOLLAR)
111+
}
112+
109113
func (p *cockroach) Destroy(s store, model *Model) error {
110114
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", p.Quote(model.TableName()), model.Alias(), model.WhereID()))
111115
_, err := genericExec(s, stmt, model.ID())

dialect_common.go

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/gobuffalo/pop/v6/columns"
1515
"github.com/gobuffalo/pop/v6/logging"
1616
"github.com/gofrs/uuid"
17+
"github.com/jmoiron/sqlx"
1718
)
1819

1920
func init() {
@@ -110,6 +111,32 @@ func genericUpdate(s store, model *Model, cols columns.Columns, quoter quotable)
110111
return nil
111112
}
112113

114+
func genericUpdateQuery(s store, model *Model, cols columns.Columns, quoter quotable, query Query, bindType int) (int64, error) {
115+
q := fmt.Sprintf("UPDATE %s AS %s SET %s", quoter.Quote(model.TableName()), model.Alias(), cols.Writeable().QuotedUpdateString(quoter))
116+
117+
q, updateArgs, err := sqlx.Named(q, model.Value)
118+
if err != nil {
119+
return 0, err
120+
}
121+
122+
sb := query.toSQLBuilder(model)
123+
q = sb.buildWhereClauses(q)
124+
125+
q = sqlx.Rebind(bindType, q)
126+
127+
result, err := genericExec(s, q, append(updateArgs, sb.args...)...)
128+
if err != nil {
129+
return 0, err
130+
}
131+
132+
n, err := result.RowsAffected()
133+
if err != nil {
134+
return 0, err
135+
}
136+
137+
return n, err
138+
}
139+
113140
func genericDestroy(s store, model *Model, quoter quotable) error {
114141
stmt := fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", quoter.Quote(model.TableName()), model.Alias(), model.WhereID())
115142
_, err := genericExec(s, stmt, model.ID())

dialect_mysql.go

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/gobuffalo/pop/v6/columns"
1414
"github.com/gobuffalo/pop/v6/internal/defaults"
1515
"github.com/gobuffalo/pop/v6/logging"
16+
"github.com/jmoiron/sqlx"
1617
)
1718

1819
const nameMySQL = "mysql"
@@ -94,6 +95,14 @@ func (m *mysql) Update(s store, model *Model, cols columns.Columns) error {
9495
return nil
9596
}
9697

98+
func (m *mysql) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
99+
if n, err := genericUpdateQuery(s, model, cols, m, query, sqlx.QUESTION); err != nil {
100+
return n, fmt.Errorf("mysql update query: %w", err)
101+
} else {
102+
return n, nil
103+
}
104+
}
105+
97106
func (m *mysql) Destroy(s store, model *Model) error {
98107
stmt := fmt.Sprintf("DELETE FROM %s WHERE %s = ?", m.Quote(model.TableName()), model.IDField())
99108
_, err := genericExec(s, stmt, model.ID())

dialect_postgresql.go

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func (p *postgresql) Update(s store, model *Model, cols columns.Columns) error {
9090
return genericUpdate(s, model, cols, p)
9191
}
9292

93+
func (p *postgresql) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
94+
return genericUpdateQuery(s, model, cols, p, query, sqlx.DOLLAR)
95+
}
96+
9397
func (p *postgresql) Destroy(s store, model *Model) error {
9498
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", p.Quote(model.TableName()), model.Alias(), model.WhereID()))
9599
_, err := genericExec(s, stmt, model.ID())

0 commit comments

Comments
 (0)