From 7bfd9573b12d7c06b66143c04cc171489cb252a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 4 Nov 2023 23:34:23 +0800 Subject: [PATCH] chore: merge v1.13.x to master (#333) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Upgrade v1.13.1 * Merge #305, #306 to v1.13.x (#308) * Upgrade v1.13.1 (#295) * Update README * build(deps): bump the go-modules group with 1 update (#296) Bumps the go-modules group with 1 update: [github.com/bytedance/sonic](https://github.com/bytedance/sonic). - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.10.0...v1.10.1) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#297) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#299) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.0...v1.58.1) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the github-actions group with 1 update (#300) Bumps the github-actions group with 1 update: [codecov/codecov-action](https://github.com/codecov/codecov-action). - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenbo Han * feat: add GetBytes method and test cases (#298) * feat: add GetBytes method and test cases * workflow: remove filesystem * fix: lint * feat: optimize code * feat: optimize test * fix: windows tests * workflow: fix * fix: file not close * feat: optimize code * fix: lint * fix: lint * fix: test * feat: Add interface comments (#292) * Add interface comments to all facades * Add comments for remaining contracts * convert the first letter of word to a lower case in godoc comments * Add a space for each comment after // * build(deps): bump the go-modules group with 1 update (#301) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.7...v2.2.8) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#303) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.1...v1.58.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix:[#263] There is a path error in the filesystem module (#305) * feat: Add Fluent String helpers (#304) * add fluent strings helpers * add more fluent string helpers * add headline helper * add test cases for fluent strings * add test cases for headline function * modify, according to suggestions * modify, according to suggestions * reformat the str file * fix: #267 (#306) * feat: add environment helper * feat: optimize sonic * fix: tests * feat: rename to env * feat: optimize json * fix: optimize tests --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 耗子 Co-authored-by: krishan kumar <84431594+kkumar-gcc@users.noreply.github.com> * fix: [#270] Optimize postgres DNS (#309) * fix: [#270] Optimize postgres DNS * Fix unit test * fix: [#253] [Bug] The With method can't be used with the Cursor method together (#311) * fix: #253 [Bug] The With method can't be used with the Cursor method together * Remove test * Upgrade v1.13.2 * Update README * fix: Register multiple events (#317) * Upgrade v1.13.1 (#295) * Update README * build(deps): bump the go-modules group with 1 update (#296) Bumps the go-modules group with 1 update: [github.com/bytedance/sonic](https://github.com/bytedance/sonic). - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.10.0...v1.10.1) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#297) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#299) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.0...v1.58.1) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the github-actions group with 1 update (#300) Bumps the github-actions group with 1 update: [codecov/codecov-action](https://github.com/codecov/codecov-action). - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenbo Han * feat: add GetBytes method and test cases (#298) * feat: add GetBytes method and test cases * workflow: remove filesystem * fix: lint * feat: optimize code * feat: optimize test * fix: windows tests * workflow: fix * fix: file not close * feat: optimize code * fix: lint * fix: lint * fix: test * feat: Add interface comments (#292) * Add interface comments to all facades * Add comments for remaining contracts * convert the first letter of word to a lower case in godoc comments * Add a space for each comment after // * build(deps): bump the go-modules group with 1 update (#301) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.7...v2.2.8) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#303) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.1...v1.58.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix:[#263] There is a path error in the filesystem module (#305) * feat: Add Fluent String helpers (#304) * add fluent strings helpers * add more fluent string helpers * add headline helper * add test cases for fluent strings * add test cases for headline function * modify, according to suggestions * modify, according to suggestions * reformat the str file * fix: #267 (#306) * feat: add environment helper * feat: optimize sonic * fix: tests * feat: rename to env * feat: optimize json * fix: optimize tests * refactor: move mocks (#307) * feat: update mocks * refactor: move mocks * workflow: remove code review * workflow: fix mockery * fix: update mocks * refactor: move gorm initialize interface to contracts folder * feat: test generate mock * workflow: update mock * chore: update mocks * chore: remove unnecessary go generate tag * workflow: only generate mocks in master branch * workflow: fix lint * workflow: make mockery only run on pr * feat: move Gorm interface to contracts/database/gorm * feat: move Gorm interface to contracts/database/gorm * feat: move interface * chore: update mocks * fix: test --------- Co-authored-by: devhaozi * build(deps): bump the go-modules group with 1 update (#310) Bumps the go-modules group with 1 update: [golang.org/x/crypto](https://github.com/golang/crypto). - [Commits](https://github.com/golang/crypto/compare/v0.13.0...v0.14.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the github-actions group with 1 update (#312) Bumps the github-actions group with 1 update: [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action). - [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases) - [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4...v5) --- updated-dependencies: - dependency-name: stefanzweifel/git-auto-commit-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#313) Bumps the go-modules group with 1 update: [github.com/spf13/viper](https://github.com/spf13/viper). - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.16.0...v1.17.0) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenbo Han * build(deps): bump the go-modules group with 2 updates (#315) Bumps the go-modules group with 2 updates: [github.com/bytedance/sonic](https://github.com/bytedance/sonic) and [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). Updates `github.com/bytedance/sonic` from 1.10.1 to 1.10.2 - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.10.1...v1.10.2) Updates `github.com/golang-module/carbon/v2` from 2.2.8 to 2.2.9 - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.8...v2.2.9) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Register multiple events * Fix typo * Restore * Allow multiple events registeration --------- Signed-off-by: dependabot[bot] Co-authored-by: Wenbo Han Co-authored-by: Bowen Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 耗子 Co-authored-by: krishan kumar <84431594+kkumar-gcc@users.noreply.github.com> Co-authored-by: devhaozi * fix: database variable (#316) * Upgrade v1.13.1 (#295) * Update README * build(deps): bump the go-modules group with 1 update (#296) Bumps the go-modules group with 1 update: [github.com/bytedance/sonic](https://github.com/bytedance/sonic). - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.10.0...v1.10.1) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#297) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.6...v2.2.7) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#299) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.0...v1.58.1) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the github-actions group with 1 update (#300) Bumps the github-actions group with 1 update: [codecov/codecov-action](https://github.com/codecov/codecov-action). - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenbo Han * feat: add GetBytes method and test cases (#298) * feat: add GetBytes method and test cases * workflow: remove filesystem * fix: lint * feat: optimize code * feat: optimize test * fix: windows tests * workflow: fix * fix: file not close * feat: optimize code * fix: lint * fix: lint * fix: test * feat: Add interface comments (#292) * Add interface comments to all facades * Add comments for remaining contracts * convert the first letter of word to a lower case in godoc comments * Add a space for each comment after // * build(deps): bump the go-modules group with 1 update (#301) Bumps the go-modules group with 1 update: [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.7...v2.2.8) --- updated-dependencies: - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#303) Bumps the go-modules group with 1 update: [google.golang.org/grpc](https://github.com/grpc/grpc-go). - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.58.1...v1.58.2) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix:[#263] There is a path error in the filesystem module (#305) * feat: Add Fluent String helpers (#304) * add fluent strings helpers * add more fluent string helpers * add headline helper * add test cases for fluent strings * add test cases for headline function * modify, according to suggestions * modify, according to suggestions * reformat the str file * fix: #267 (#306) * feat: add environment helper * feat: optimize sonic * fix: tests * feat: rename to env * feat: optimize json * fix: optimize tests * refactor: move mocks (#307) * feat: update mocks * refactor: move mocks * workflow: remove code review * workflow: fix mockery * fix: update mocks * refactor: move gorm initialize interface to contracts folder * feat: test generate mock * workflow: update mock * chore: update mocks * chore: remove unnecessary go generate tag * workflow: only generate mocks in master branch * workflow: fix lint * workflow: make mockery only run on pr * feat: move Gorm interface to contracts/database/gorm * feat: move Gorm interface to contracts/database/gorm * feat: move interface * chore: update mocks * fix: test --------- Co-authored-by: devhaozi * build(deps): bump the go-modules group with 1 update (#310) Bumps the go-modules group with 1 update: [golang.org/x/crypto](https://github.com/golang/crypto). - [Commits](https://github.com/golang/crypto/compare/v0.13.0...v0.14.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the github-actions group with 1 update (#312) Bumps the github-actions group with 1 update: [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action). - [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases) - [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4...v5) --- updated-dependencies: - dependency-name: stefanzweifel/git-auto-commit-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump the go-modules group with 1 update (#313) Bumps the go-modules group with 1 update: [github.com/spf13/viper](https://github.com/spf13/viper). - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.16.0...v1.17.0) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wenbo Han * build(deps): bump the go-modules group with 2 updates (#315) Bumps the go-modules group with 2 updates: [github.com/bytedance/sonic](https://github.com/bytedance/sonic) and [github.com/golang-module/carbon/v2](https://github.com/golang-module/carbon). Updates `github.com/bytedance/sonic` from 1.10.1 to 1.10.2 - [Release notes](https://github.com/bytedance/sonic/releases) - [Commits](https://github.com/bytedance/sonic/compare/v1.10.1...v1.10.2) Updates `github.com/golang-module/carbon/v2` from 2.2.8 to 2.2.9 - [Release notes](https://github.com/golang-module/carbon/releases) - [Commits](https://github.com/golang-module/carbon/compare/v2.2.8...v2.2.9) --- updated-dependencies: - dependency-name: github.com/bytedance/sonic dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules - dependency-name: github.com/golang-module/carbon/v2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Fix database variable * Restore * Fix database typo --------- Signed-off-by: dependabot[bot] Co-authored-by: Wenbo Han Co-authored-by: Bowen Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 耗子 Co-authored-by: krishan kumar <84431594+kkumar-gcc@users.noreply.github.com> Co-authored-by: devhaozi * feat: [#265] The Config module supports get system environment variables (#329) --------- Signed-off-by: dependabot[bot] Co-authored-by: Bowen Co-authored-by: Wenbo Han Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: krishan kumar <84431594+kkumar-gcc@users.noreply.github.com> Co-authored-by: Ahmed M. Ammar Co-authored-by: devhaozi --- README.md | 7 +++ README_zh.md | 7 +++ config/application.go | 6 +-- config/application_test.go | 82 ++++++++++++++++++++++----------- database/db/dsn.go | 4 +- database/db/dsn_test.go | 4 +- database/gorm/cursor.go | 15 +++++- database/gorm/dialector_test.go | 4 +- database/gorm/event.go | 5 +- database/gorm/event_test.go | 28 +++++++---- database/gorm/query.go | 78 +++++++++++++++++++------------ database/gorm/query_test.go | 17 +++++-- database/gorm/transaction.go | 5 +- database/gorm/utils_test.go | 4 +- event/application.go | 8 +++- support/constant.go | 2 +- support/database/database.go | 2 +- 17 files changed, 188 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 3f7dc046a..3105d0474 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,13 @@ This project exists thanks to all the people who contribute, to participate in t + + +## Sponsor + +Better development of the project is inseparable from your support, reward us by [Open Collective](https://opencollective.com/goravel). + +

## Group diff --git a/README_zh.md b/README_zh.md index 6effb16dc..ef37dfac9 100644 --- a/README_zh.md +++ b/README_zh.md @@ -67,6 +67,13 @@ Laravel! + + +## 打赏 + +开源项目的发展离不开您的支持,感谢微信打赏。 + +

## 群组 diff --git a/config/application.go b/config/application.go index e472d4544..30b3e8b5c 100644 --- a/config/application.go +++ b/config/application.go @@ -29,15 +29,13 @@ func NewApplication(envPath string) *Application { app.vip = viper.New() app.vip.SetConfigType("env") app.vip.SetConfigFile(envPath) + app.vip.AutomaticEnv() if err := app.vip.ReadInConfig(); err != nil { color.Redln("Invalid Config error: " + err.Error()) os.Exit(0) } - app.vip.SetEnvPrefix("goravel") - app.vip.AutomaticEnv() - appKey := app.Env("APP_KEY") if support.Env != support.EnvArtisan { if appKey == nil { @@ -47,7 +45,7 @@ func NewApplication(envPath string) *Application { } if len(appKey.(string)) != 32 { - color.Redln("Invalid APP_KEY, please reset it.") + color.Redln("Invalid APP_KEY, the length must be 32, please reset it.") color.Warnln("Example command: \ngo run . artisan key:generate") os.Exit(0) } diff --git a/config/application_test.go b/config/application_test.go index 372c771fe..86c001786 100644 --- a/config/application_test.go +++ b/config/application_test.go @@ -12,22 +12,30 @@ import ( type ApplicationTestSuite struct { suite.Suite - config *Application - config2 *Application + config *Application + customConfig *Application } func TestApplicationTestSuite(t *testing.T) { - assert.Nil(t, file.Create(".env", "APP_KEY=12345678901234567890123456789012")) + assert.Nil(t, file.Create(".env", ` +APP_KEY=12345678901234567890123456789012 +APP_DEBUG=true +DB_PORT=3306 +`)) temp, err := os.CreateTemp("", "goravel.env") assert.Nil(t, err) defer os.Remove(temp.Name()) - _, err = temp.Write([]byte("APP_KEY=12345678901234567890123456789012")) + _, err = temp.Write([]byte(` +APP_KEY=12345678901234567890123456789012 +APP_DEBUG=true +DB_PORT=3306 +`)) assert.Nil(t, err) assert.Nil(t, temp.Close()) suite.Run(t, &ApplicationTestSuite{ - config: NewApplication(".env"), - config2: NewApplication(temp.Name()), + config: NewApplication(".env"), + customConfig: NewApplication(temp.Name()), }) assert.Nil(t, file.Remove(".env")) @@ -37,43 +45,61 @@ func (s *ApplicationTestSuite) SetupTest() { } +func (s *ApplicationTestSuite) TestOsVariables() { + s.Nil(os.Setenv("APP_KEY", "12345678901234567890123456789013")) + s.Nil(os.Setenv("OS_APP_NAME", "goravel")) + s.Nil(os.Setenv("OS_APP_PORT", "3306")) + s.Nil(os.Setenv("OS_APP_DEBUG", "true")) + + s.Equal("12345678901234567890123456789013", s.config.GetString("APP_KEY")) + s.Equal("12345678901234567890123456789013", s.customConfig.GetString("APP_KEY")) + s.Equal("goravel", s.config.GetString("OS_APP_NAME")) + s.Equal("goravel", s.customConfig.GetString("OS_APP_NAME")) + s.Equal(3306, s.config.GetInt("OS_APP_PORT")) + s.Equal(3306, s.customConfig.GetInt("OS_APP_PORT")) + s.True(s.config.GetBool("OS_APP_DEBUG")) + s.True(s.customConfig.GetBool("OS_APP_DEBUG")) +} + func (s *ApplicationTestSuite) TestEnv() { + s.Equal("12345678901234567890123456789012", s.config.Env("APP_KEY").(string)) s.Equal("goravel", s.config.Env("APP_NAME", "goravel").(string)) - s.Equal("127.0.0.1", s.config.Env("DB_HOST", "127.0.0.1").(string)) - s.Equal("goravel", s.config2.Env("APP_NAME", "goravel").(string)) - s.Equal("127.0.0.1", s.config2.Env("DB_HOST", "127.0.0.1").(string)) + s.Equal("12345678901234567890123456789012", s.customConfig.Env("APP_KEY").(string)) + s.Equal("goravel", s.customConfig.Env("APP_NAME", "goravel").(string)) } func (s *ApplicationTestSuite) TestAdd() { s.config.Add("app", map[string]any{ "env": "local", }) - s.config2.Add("app", map[string]any{ + s.customConfig.Add("app", map[string]any{ "env": "local", }) s.Equal("local", s.config.GetString("app.env")) - s.Equal("local", s.config2.GetString("app.env")) + s.Equal("local", s.customConfig.GetString("app.env")) s.config.Add("path.with.dot.case1", "value1") - s.config2.Add("path.with.dot.case1", "value1") + s.customConfig.Add("path.with.dot.case1", "value1") s.Equal("value1", s.config.GetString("path.with.dot.case1")) - s.Equal("value1", s.config2.GetString("path.with.dot.case1")) + s.Equal("value1", s.customConfig.GetString("path.with.dot.case1")) s.config.Add("path.with.dot.case2", "value2") - s.config2.Add("path.with.dot.case2", "value2") + s.customConfig.Add("path.with.dot.case2", "value2") s.Equal("value2", s.config.GetString("path.with.dot.case2")) - s.Equal("value2", s.config2.GetString("path.with.dot.case2")) + s.Equal("value2", s.customConfig.GetString("path.with.dot.case2")) s.config.Add("path.with.dot", map[string]any{"case3": "value3"}) - s.config2.Add("path.with.dot", map[string]any{"case3": "value3"}) + s.customConfig.Add("path.with.dot", map[string]any{"case3": "value3"}) s.Equal("value3", s.config.GetString("path.with.dot.case3")) - s.Equal("value3", s.config2.GetString("path.with.dot.case3")) + s.Equal("value3", s.customConfig.GetString("path.with.dot.case3")) } func (s *ApplicationTestSuite) TestGet() { + s.Equal("12345678901234567890123456789012", s.config.Get("APP_KEY").(string)) s.Equal("goravel", s.config.Get("APP_NAME", "goravel").(string)) - s.Equal("goravel", s.config2.Get("APP_NAME", "goravel").(string)) + s.Equal("12345678901234567890123456789012", s.customConfig.Get("APP_KEY").(string)) + s.Equal("goravel", s.customConfig.Get("APP_NAME", "goravel").(string)) } func (s *ApplicationTestSuite) TestGetString() { @@ -85,11 +111,11 @@ func (s *ApplicationTestSuite) TestGetString() { }, }, }) - s.config2.Add("database", map[string]any{ - "default": s.config2.Env("DB_CONNECTION", "mysql"), + s.customConfig.Add("database", map[string]any{ + "default": s.customConfig.Env("DB_CONNECTION", "mysql"), "connections": map[string]any{ "mysql": map[string]any{ - "host": s.config2.Env("DB_HOST", "127.0.0.1"), + "host": s.customConfig.Env("DB_HOST", "127.0.0.1"), }, }, }) @@ -97,17 +123,17 @@ func (s *ApplicationTestSuite) TestGetString() { s.Equal("goravel", s.config.GetString("APP_NAME", "goravel")) s.Equal("127.0.0.1", s.config.GetString("database.connections.mysql.host")) s.Equal("mysql", s.config.GetString("database.default")) - s.Equal("goravel", s.config2.GetString("APP_NAME", "goravel")) - s.Equal("127.0.0.1", s.config2.GetString("database.connections.mysql.host")) - s.Equal("mysql", s.config2.GetString("database.default")) + s.Equal("goravel", s.customConfig.GetString("APP_NAME", "goravel")) + s.Equal("127.0.0.1", s.customConfig.GetString("database.connections.mysql.host")) + s.Equal("mysql", s.customConfig.GetString("database.default")) } func (s *ApplicationTestSuite) TestGetInt() { - s.Equal(s.config.GetInt("DB_PORT", 3306), 3306) - s.Equal(s.config2.GetInt("DB_PORT", 3306), 3306) + s.Equal(3306, s.config.GetInt("DB_PORT")) + s.Equal(3306, s.customConfig.GetInt("DB_PORT")) } func (s *ApplicationTestSuite) TestGetBool() { - s.Equal(true, s.config.GetBool("APP_DEBUG", true)) - s.Equal(true, s.config2.GetBool("APP_DEBUG", true)) + s.Equal(true, s.config.GetBool("APP_DEBUG")) + s.Equal(true, s.customConfig.GetBool("APP_DEBUG")) } diff --git a/database/db/dsn.go b/database/db/dsn.go index aa16aa054..c88c73951 100644 --- a/database/db/dsn.go +++ b/database/db/dsn.go @@ -48,8 +48,8 @@ func (d *DsnImpl) Postgresql(config databasecontract.Config) string { sslmode := d.config.GetString("database.connections." + d.connection + ".sslmode") timezone := d.config.GetString("database.connections." + d.connection + ".timezone") - return fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", - host, config.Username, config.Password, config.Database, config.Port, sslmode, timezone) + return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s&timezone=%s", + config.Username, config.Password, host, config.Port, config.Database, sslmode, timezone) } func (d *DsnImpl) Sqlite(config databasecontract.Config) string { diff --git a/database/db/dsn_test.go b/database/db/dsn_test.go index b816bc0cf..50066a7b7 100644 --- a/database/db/dsn_test.go +++ b/database/db/dsn_test.go @@ -60,8 +60,8 @@ func (s *DsnTestSuite) TestPostgresql() { s.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.sslmode", connection)).Return(sslmode).Once() s.mockConfig.On("GetString", fmt.Sprintf("database.connections.%s.timezone", connection)).Return(timezone).Once() - s.Equal(fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", - testHost, testUsername, testPassword, testDatabase, testPort, sslmode, timezone), dsn.Postgresql(testConfig)) + s.Equal(fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s&timezone=%s", + testUsername, testPassword, testHost, testPort, testDatabase, sslmode, timezone), dsn.Postgresql(testConfig)) } func (s *DsnTestSuite) TestSqlite() { diff --git a/database/gorm/cursor.go b/database/gorm/cursor.go index e783901f7..a60163cdb 100644 --- a/database/gorm/cursor.go +++ b/database/gorm/cursor.go @@ -13,7 +13,8 @@ import ( ) type CursorImpl struct { - row map[string]any + query *QueryImpl + row map[string]any } func (c *CursorImpl) Scan(value any) error { @@ -33,7 +34,17 @@ func (c *CursorImpl) Scan(value any) error { return err } - return decoder.Decode(c.row) + if err := decoder.Decode(c.row); err != nil { + return err + } + + for relation, args := range c.query.with { + if err := c.query.origin.Load(value, relation, args...); err != nil { + return err + } + } + + return nil } func ToTimeHookFunc() mapstructure.DecodeHookFunc { diff --git a/database/gorm/dialector_test.go b/database/gorm/dialector_test.go index 25da2a960..1435a61bb 100644 --- a/database/gorm/dialector_test.go +++ b/database/gorm/dialector_test.go @@ -63,8 +63,8 @@ func (s *DialectorTestSuite) TestPostgresql() { Return("UTC").Once() dialectors, err := dialector.Make([]databasecontract.Config{s.config}) s.Equal(postgres.New(postgres.Config{ - DSN: fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", - s.config.Host, s.config.Username, s.config.Password, s.config.Database, s.config.Port, "disable", "UTC"), + DSN: fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s&timezone=%s", + s.config.Username, s.config.Password, s.config.Host, s.config.Port, s.config.Database, "disable", "UTC"), }), dialectors[0]) s.Nil(err) } diff --git a/database/gorm/event.go b/database/gorm/event.go index 4c257622c..bfeee1cf6 100644 --- a/database/gorm/event.go +++ b/database/gorm/event.go @@ -64,7 +64,10 @@ func (e *Event) IsClean(fields ...string) bool { } func (e *Event) Query() orm.Query { - return NewQueryWithWithoutEvents(e.query.instance.Session(&gorm.Session{NewDB: true}), false, e.query.config) + return NewQueryImplByInstance(e.query.instance.Session(&gorm.Session{NewDB: true}), &QueryImpl{ + config: e.query.config, + withoutEvents: false, + }) } func (e *Event) Context() context.Context { diff --git a/database/gorm/event_test.go b/database/gorm/event_test.go index 7f57ff614..1ec5dc76e 100644 --- a/database/gorm/event_test.go +++ b/database/gorm/event_test.go @@ -21,12 +21,15 @@ type TestEventModel struct { var testNow = time.Now().Add(-1 * time.Second) var testEventModel = TestEventModel{Name: "name", Avatar: "avatar", IsAdmin: true, IsManage: 0, AdminAt: testNow, ManageAt: testNow, high: 1} -var testQuery = NewQueryWithWithoutEvents(&gorm.DB{ +var testQuery = NewQueryImplByInstance(&gorm.DB{ Statement: &gorm.Statement{ Selects: []string{}, Omits: []string{}, }, -}, false, nil) +}, &QueryImpl{ + config: nil, + withoutEvents: false, +}) type EventTestSuite struct { suite.Suite @@ -48,13 +51,16 @@ func (s *EventTestSuite) SetupTest() { func (s *EventTestSuite) TestSetAttribute() { dest := map[string]any{"avatar": "avatar1"} - query := NewQueryWithWithoutEvents(&gorm.DB{ + query := NewQueryImplByInstance(&gorm.DB{ Statement: &gorm.Statement{ Selects: []string{}, Omits: []string{}, Dest: dest, }, - }, false, nil) + }, &QueryImpl{ + config: nil, + withoutEvents: false, + }) event := NewEvent(query, &testEventModel, dest) @@ -148,23 +154,29 @@ func (s *EventTestSuite) TestValidColumn() { s.True(event.validColumn("manage")) s.False(event.validColumn("age")) - event.query = NewQueryWithWithoutEvents(&gorm.DB{ + event.query = NewQueryImplByInstance(&gorm.DB{ Statement: &gorm.Statement{ Selects: []string{"name"}, Omits: []string{}, }, - }, false, nil) + }, &QueryImpl{ + config: nil, + withoutEvents: false, + }) s.True(event.validColumn("Name")) s.True(event.validColumn("name")) s.False(event.validColumn("avatar")) s.False(event.validColumn("Avatar")) - event.query = NewQueryWithWithoutEvents(&gorm.DB{ + event.query = NewQueryImplByInstance(&gorm.DB{ Statement: &gorm.Statement{ Selects: []string{}, Omits: []string{"name"}, }, - }, false, nil) + }, &QueryImpl{ + config: nil, + withoutEvents: false, + }) s.False(event.validColumn("Name")) s.False(event.validColumn("name")) s.True(event.validColumn("avatar")) diff --git a/database/gorm/query.go b/database/gorm/query.go index 5b84d7ae3..a07fd711d 100644 --- a/database/gorm/query.go +++ b/database/gorm/query.go @@ -29,6 +29,8 @@ type QueryImpl struct { config config.Config ctx context.Context instance *gormio.DB + origin *QueryImpl + with map[string][]any withoutEvents bool } @@ -48,8 +50,15 @@ func NewQueryImpl(ctx context.Context, config config.Config, gorm gormcontract.G }, nil } -func NewQueryWithWithoutEvents(instance *gormio.DB, withoutEvents bool, config config.Config) *QueryImpl { - return &QueryImpl{instance: instance, withoutEvents: withoutEvents, config: config, ctx: instance.Statement.Context} +func NewQueryImplByInstance(db *gormio.DB, instance *QueryImpl) *QueryImpl { + queryImpl := &QueryImpl{config: instance.config, ctx: db.Statement.Context, instance: db, origin: instance.origin, with: instance.with, withoutEvents: instance.withoutEvents} + + // The origin is used by the With method to load the relationship. + if instance.origin == nil && instance.instance != nil { + queryImpl.origin = instance + } + + return queryImpl } func (r *QueryImpl) Association(association string) ormcontract.Association { @@ -105,7 +114,7 @@ func (r *QueryImpl) Cursor() (chan ormcontract.Cursor, error) { if err != nil { return } - cursorChan <- &CursorImpl{row: val} + cursorChan <- &CursorImpl{row: val, query: r} } close(cursorChan) }() @@ -137,7 +146,7 @@ func (r *QueryImpl) Delete(dest any, conds ...any) (*ormcontract.Result, error) func (r *QueryImpl) Distinct(args ...any) ormcontract.Query { tx := r.instance.Distinct(args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Exec(sql string, values ...any) (*ormcontract.Result, error) { @@ -307,13 +316,13 @@ func (r *QueryImpl) Get(dest any) error { func (r *QueryImpl) Group(name string) ormcontract.Query { tx := r.instance.Group(name) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Having(query any, args ...any) ormcontract.Query { tx := r.instance.Having(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Instance() *gormio.DB { @@ -322,13 +331,13 @@ func (r *QueryImpl) Instance() *gormio.DB { func (r *QueryImpl) Join(query string, args ...any) ormcontract.Query { tx := r.instance.Joins(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Limit(limit int) ormcontract.Query { tx := r.instance.Limit(limit) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Load(model any, relation string, args ...any) error { @@ -346,8 +355,7 @@ func (r *QueryImpl) Load(model any, relation string, args ...any) error { } copyDest := copyStruct(model) - query := r.With(relation, args...) - err := query.Find(model) + err := r.With(relation, args...).Find(model) t := destType.Elem() v := reflect.ValueOf(model).Elem() @@ -406,11 +414,11 @@ func (r *QueryImpl) LockForUpdate() ormcontract.Query { if driver == mysqlDialector.Name() || driver == postgresqlDialector.Name() { tx := r.instance.Clauses(clause.Locking{Strength: "UPDATE"}) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } else if driver == sqlserverDialector.Name() { tx := r.instance.Clauses(hints.With("rowlock", "updlock", "holdlock")) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } return r @@ -422,31 +430,31 @@ func (r *QueryImpl) Model(value any) ormcontract.Query { } tx := r.instance.Model(value) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Offset(offset int) ormcontract.Query { tx := r.instance.Offset(offset) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Omit(columns ...string) ormcontract.Query { tx := r.instance.Omit(columns...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Order(value any) ormcontract.Query { tx := r.instance.Order(value) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) OrWhere(query any, args ...any) ormcontract.Query { tx := r.instance.Or(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Paginate(page, limit int, dest any, total *int64) error { @@ -473,7 +481,7 @@ func (r *QueryImpl) Pluck(column string, dest any) error { func (r *QueryImpl) Raw(sql string, values ...any) ormcontract.Query { tx := r.instance.Raw(sql, values...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Save(value any) error { @@ -546,14 +554,14 @@ func (r *QueryImpl) Scan(dest any) error { func (r *QueryImpl) Select(query any, args ...any) ormcontract.Query { tx := r.instance.Select(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Scopes(funcs ...func(ormcontract.Query) ormcontract.Query) ormcontract.Query { var gormFuncs []func(*gormio.DB) *gormio.DB for _, item := range funcs { gormFuncs = append(gormFuncs, func(tx *gormio.DB) *gormio.DB { - item(NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config)) + item(NewQueryImplByInstance(tx, r)) return tx }) @@ -561,7 +569,7 @@ func (r *QueryImpl) Scopes(funcs ...func(ormcontract.Query) ormcontract.Query) o tx := r.instance.Scopes(gormFuncs...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) SharedLock() ormcontract.Query { @@ -573,11 +581,11 @@ func (r *QueryImpl) SharedLock() ormcontract.Query { if driver == mysqlDialector.Name() || driver == postgresqlDialector.Name() { tx := r.instance.Clauses(clause.Locking{Strength: "SHARE"}) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } else if driver == sqlserverDialector.Name() { tx := r.instance.Clauses(hints.With("rowlock", "holdlock")) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } return r @@ -590,7 +598,7 @@ func (r *QueryImpl) Sum(column string, dest any) error { func (r *QueryImpl) Table(name string, args ...any) ormcontract.Query { tx := r.instance.Table(name, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) Update(column any, value ...any) (*ormcontract.Result, error) { @@ -653,17 +661,20 @@ func (r *QueryImpl) UpdateOrCreate(dest any, attributes any, values any) error { func (r *QueryImpl) Where(query any, args ...any) ormcontract.Query { tx := r.instance.Where(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) WithoutEvents() ormcontract.Query { - return NewQueryWithWithoutEvents(r.instance, true, r.config) + return NewQueryImplByInstance(r.instance, &QueryImpl{ + config: r.config, + withoutEvents: true, + }) } func (r *QueryImpl) WithTrashed() ormcontract.Query { tx := r.instance.Unscoped() - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } func (r *QueryImpl) With(query string, args ...any) ormcontract.Query { @@ -672,7 +683,7 @@ func (r *QueryImpl) With(query string, args ...any) ormcontract.Query { case func(ormcontract.Query) ormcontract.Query: newArgs := []any{ func(tx *gormio.DB) *gormio.DB { - query := arg(NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config)) + query := arg(NewQueryImplByInstance(tx, r)) return query.(*QueryImpl).instance }, @@ -680,13 +691,20 @@ func (r *QueryImpl) With(query string, args ...any) ormcontract.Query { tx := r.instance.Preload(query, newArgs...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + return NewQueryImplByInstance(tx, r) } } tx := r.instance.Preload(query, args...) - return NewQueryWithWithoutEvents(tx, r.withoutEvents, r.config) + queryImpl := NewQueryImplByInstance(tx, r) + if queryImpl.with == nil { + queryImpl.with = make(map[string][]any) + } + + queryImpl.with[query] = args + + return queryImpl } func (r *QueryImpl) refreshConnection(value any) error { diff --git a/database/gorm/query_test.go b/database/gorm/query_test.go index 3adce6123..373c936ae 100644 --- a/database/gorm/query_test.go +++ b/database/gorm/query_test.go @@ -769,8 +769,10 @@ func (s *QueryTestSuite) TestCreate() { func (s *QueryTestSuite) TestCursor() { for driver, query := range s.queries { s.Run(driver.String(), func() { - user := User{Name: "cursor_user", Avatar: "cursor_avatar"} - s.Nil(query.Create(&user)) + user := User{Name: "cursor_user", Avatar: "cursor_avatar", Address: &Address{Name: "cursor_address"}, Books: []*Book{ + {Name: "cursor_book"}, + }} + s.Nil(query.Select(orm.Associations).Create(&user)) s.True(user.ID > 0) user1 := User{Name: "cursor_user", Avatar: "cursor_avatar1"} @@ -784,9 +786,11 @@ func (s *QueryTestSuite) TestCursor() { s.Nil(err) s.Equal(int64(1), res.RowsAffected) - users, err := query.Model(&User{}).Where("name = ?", "cursor_user").WithTrashed().Cursor() + users, err := query.Model(&User{}).Where("name = ?", "cursor_user").WithTrashed().With("Address").With("Books").Cursor() s.Nil(err) var size int + var addressNum int + var bookNum int for row := range users { var tempUser User s.Nil(row.Scan(&tempUser)) @@ -796,8 +800,15 @@ func (s *QueryTestSuite) TestCursor() { s.NotEmpty(tempUser.UpdatedAt.String()) s.Equal(tempUser.DeletedAt.Valid, tempUser.ID == user2.ID) size++ + + if tempUser.Address != nil { + addressNum++ + } + bookNum += len(tempUser.Books) } s.Equal(3, size) + s.Equal(1, addressNum) + s.Equal(1, bookNum) }) } } diff --git a/database/gorm/transaction.go b/database/gorm/transaction.go index e72ffe958..61bb91ac6 100644 --- a/database/gorm/transaction.go +++ b/database/gorm/transaction.go @@ -13,7 +13,10 @@ type Transaction struct { } func NewTransaction(tx *gorm.DB, config config.Config) *Transaction { - return &Transaction{Query: NewQueryWithWithoutEvents(tx, false, config), instance: tx} + return &Transaction{Query: NewQueryImplByInstance(tx, &QueryImpl{ + config: config, + withoutEvents: false, + }), instance: tx} } func (r *Transaction) Commit() error { diff --git a/database/gorm/utils_test.go b/database/gorm/utils_test.go index 236d8c134..e6b352b1f 100644 --- a/database/gorm/utils_test.go +++ b/database/gorm/utils_test.go @@ -4,8 +4,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "github.com/goravel/framework/support/debug" ) func TestCopyStruct(t *testing.T) { @@ -15,7 +13,7 @@ func TestCopyStruct(t *testing.T) { } data := copyStruct(Data{Name: "name", age: 18}) - debug.Dump(data) + assert.Equal(t, "name", data.Field(0).Interface().(string)) assert.Panics(t, func() { data.Field(1).Interface() diff --git a/event/application.go b/event/application.go index 64f117400..4a6809163 100644 --- a/event/application.go +++ b/event/application.go @@ -17,10 +17,14 @@ func NewApplication(queue queuecontract.Queue) *Application { } func (app *Application) Register(events map[event.Event][]event.Listener) { - app.events = events var jobs []queuecontract.Job - for _, listeners := range events { + if app.events == nil { + app.events = map[event.Event][]event.Listener{} + } + + for e, listeners := range events { + app.events[e] = listeners for _, listener := range listeners { jobs = append(jobs, listener) } diff --git a/support/constant.go b/support/constant.go index 3ed7f418e..580836b96 100644 --- a/support/constant.go +++ b/support/constant.go @@ -1,6 +1,6 @@ package support -const Version string = "v1.13.1" +const Version string = "v1.14.0" const ( EnvRuntime = "runtime" diff --git a/support/database/database.go b/support/database/database.go index f29786c74..7fd79cd66 100644 --- a/support/database/database.go +++ b/support/database/database.go @@ -30,7 +30,7 @@ func GetIDByReflect(t reflect.Type, v reflect.Value) any { if t.Field(i).Name == "Model" && v.Field(i).Type().Kind() == reflect.Struct { structField := v.Field(i).Type() for j := 0; j < structField.NumField(); j++ { - if !structField.Field(i).IsExported() { + if !structField.Field(j).IsExported() { continue } if strings.Contains(structField.Field(j).Tag.Get("gorm"), "primaryKey") {