Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest Development #716

Merged
merged 61 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f36afb5
fix: improve model ID field customization (#604)
zepatrik Oct 29, 2020
4d0d826
Ensure uninitialized map is initialized when unmarshaling json
naemono Dec 15, 2020
81e5f2d
exclude migration_table_name from connection string
kyrozetera Dec 23, 2020
0e3d2e2
add test for OptionsString
kyrozetera Dec 23, 2020
b2918a3
Add support for pointer FKs when preloading a belongs_to association …
reggieriser Jan 5, 2021
0fb7635
feat: support context-aware tablenames (#614)
aeneasr Jan 18, 2021
119c0d2
Bump pg deps (#616)
paganotoni Jan 27, 2021
f252caa
Latest from master (#620)
paganotoni Jan 28, 2021
ad18e4d
Resolve issues in UPDATE and DELETE when using schemas (#618)
aeneasr Feb 6, 2021
e314840
Use `PaginatorPageKey` and `PaginatorPerPageKey` variables (#615)
bhb603 Feb 6, 2021
46cfd45
Pass Time structure into timestamp update functions. (#625)
mpontillo Mar 8, 2021
fbf43b4
Allow nullable JSONB and resolve MySQL regression (#639)
Apr 13, 2021
1b7b5ef
Allow passing args to `Order` (#630)
duckbrain Apr 13, 2021
83cf49c
Added connection maximum idle time configuration (#635)
ArthurKnoep Apr 14, 2021
51f7117
Bump sqlite to 3.35.4 / 1.14.7 (#642)
aeneasr Apr 27, 2021
cf0a600
Update pg, pgx, sqlx (#643)
paganotoni May 5, 2021
e947d1b
merging master
paganotoni May 5, 2021
96f8e48
Fix Inner has many associations when passing on multiple arguments (#…
larrymjordan May 5, 2021
aeb9b56
Remove many to many TX condition for EagerPreload (#645)
larrymjordan May 6, 2021
bef765a
Added fix/tests for has_many with pointer foreign key (#647)
reggieriser May 6, 2021
bb07a37
Export WhereID, Alias, WhereNamedID (#637)
aeneasr Jun 8, 2021
d279000
fix: log model values everywhere (#656)
zepatrik Jun 28, 2021
0ecad25
Add delete to query builder (#658)
zepatrik Jul 16, 2021
bb7527e
Sort down migrations (#657)
zepatrik Aug 10, 2021
e383983
Preserve eager information when validating models (#664) (#665)
karlhaas Oct 3, 2021
45bb170
Migrate from packr to fs (#667)
fasmat Nov 23, 2021
d2bb309
merging master
paganotoni Nov 23, 2021
86d67a1
Task merging master (#669)
paganotoni Nov 23, 2021
a61a3fd
Merge branch 'development' of https://github.com/gobuffalo/pop into d…
paganotoni Nov 23, 2021
b72810f
Replace removed command
aeneasr Dec 3, 2021
94d331f
Resolve `EagerPreload` panic caused for pointer references
aeneasr Dec 8, 2021
d4a4f55
Resolve `EagerPreload` panic caused by NullUUID
aeneasr Dec 8, 2021
321cc6a
Support pointers in n+1 `Eager` loading
aeneasr Dec 9, 2021
cd4d78c
Improve error message of associations.ForStruct
aeneasr Dec 9, 2021
8817167
Add test cases for `IsZeroOfUnderlyingType`
aeneasr Dec 9, 2021
e867f2c
Resolve an obscure bug where empty structs got loaded for NULL foreig…
aeneasr Dec 9, 2021
7c217b9
Resolve association regression in finders.go
aeneasr Dec 10, 2021
3ba6312
Use dedicated migrations for preloading regression test
aeneasr Dec 10, 2021
134d8a6
Fix code regression
aeneasr Dec 10, 2021
08f34ff
Fix test code regressions
aeneasr Dec 10, 2021
bf0ffb2
Fix sql migration order
aeneasr Dec 10, 2021
20bb080
Resolve order issue in test
aeneasr Dec 10, 2021
d148b95
Ignore order when testing for nil values in test
aeneasr Dec 10, 2021
f7abee9
Pass Context during exec in create. (#688)
martinei Feb 14, 2022
32f6994
feat: support embedded struct fields (#691)
zepatrik Feb 22, 2022
2ff8b3f
test: use `T.TempDir` to create temporary test directory
Juneezee Apr 10, 2022
0656433
task: merging master into development
paganotoni Apr 16, 2022
d6d7437
task: adding next version number
paganotoni Apr 16, 2022
1dad15a
fix: associations for embedded fields
zepatrik Apr 20, 2022
d60e1cf
test: add other fields to duplicate type, because of some kind of que…
zepatrik Apr 20, 2022
e6ba76b
feat: implement UpdateQuery
grantzvolsky Apr 14, 2022
d722117
feat: allow customizing the time used for CreatedAt/UpdatedAt
Apr 21, 2022
6abef98
feat: allow using SQLite without built tag via include (#662)
duckbrain Apr 23, 2022
1173792
preparing go1.18 support (package specific workflow)
sio4 May 13, 2022
ca4f9fd
feat: darwin arm64 binary (#690)
jfreeland May 15, 2022
e3075ec
task: adding release-env in the gitignore
paganotoni May 15, 2022
d87f42d
task: its release-env
paganotoni May 15, 2022
26aa9b0
task: adding .release-env to the release-dry-run make
paganotoni May 15, 2022
b62eb16
task: changing the order of release steps
paganotoni May 15, 2022
34037d1
task:changing the token
paganotoni May 15, 2022
1c3fa0f
Merge branch 'master' into development
paganotoni May 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Go 1.17
uses: actions/setup-go@v3
with:
go-version: 1.17
id: go

- name: Checkout Code
uses: actions/checkout@v3

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

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
with:
version: latest
args: release --rm-dist
- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_TOKEN }}' > .release-env

- name: release publish
run: make release

5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
go-version:
- "1.16.x"
- "1.17.x"
- "1.18.x"

services:
mysql:
Expand Down Expand Up @@ -57,6 +58,7 @@ jobs:
go-version:
- "1.16.x"
- "1.17.x"
- "1.18.x"

services:
postgres:
Expand Down Expand Up @@ -102,6 +104,7 @@ jobs:
go-version:
- "1.16.x"
- "1.17.x"
- "1.18.x"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -145,6 +148,7 @@ jobs:
go-version:
- "1.16.x"
- "1.17.x"
- "1.18.x"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -185,6 +189,7 @@ jobs:
go-version:
- "1.16.x"
- "1.17.x"
- "1.18.x"
os:
- "macos-latest"
- "windows-latest"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ testdata/migrations/schema.sql
.grifter/
vendor/
.env
.release-env

# test data
cockroach-data/
22 changes: 19 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# GoReleaser config

---
before:
hooks:
- go mod tidy
Expand All @@ -14,17 +15,32 @@ builds:
- amd64
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
- CC=/osxcross/target/bin/o64-clang
- CXX=/osxcross/target/bin/o64-clang++
flags:
- -tags
- sqlite

- id: pop_linux
- id: pop_darwin_arm64
binary: soda
main: soda/main.go
goos:
- darwin
goarch:
- arm64
env:
- CGO_ENABLED=1
- CC=/osxcross/target/bin/oa64-clang
- CXX=/osxcross/target/bin/oa64-clang++
flags:
- -tags
- sqlite

- id: pop_linux
binary: soda
main: soda/main.go
env:
- CGO_ENABLED=0
flags:
- -tags
- sqlite
Expand Down
42 changes: 41 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/gobuffalo/pop
GOLANG_CROSS_VERSION ?= v1.17.6

TAGS ?= "sqlite"
GO_BIN ?= go

Expand Down Expand Up @@ -37,5 +40,42 @@ endif
release-test:
./test.sh

.PHONY: sysroot-pack
sysroot-pack:
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)

.PHONY: sysroot-unpack
sysroot-unpack:
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -

.PHONY: release-dry-run
release-dry-run:
@docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate --skip-publish --snapshot

.PHONY: release
release:
release -y -f soda/cmd/version.go
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist
27 changes: 23 additions & 4 deletions associations/associations_for_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var associationBuilders = map[string]associationBuilder{}
// it throws an error when it finds a field that does
// not exist for a model.
func ForStruct(s interface{}, fields ...string) (Associations, error) {
return forStruct(s, s, fields)
}

// forStruct is a recursive helper that passes the root model down for embedded fields
func forStruct(parent, s interface{}, fields []string) (Associations, error) {
t, v := getModelDefinition(s)
if t.Kind() != reflect.Struct {
return nil, fmt.Errorf("could not get struct associations: not a struct but %T", s)
Expand Down Expand Up @@ -74,7 +79,20 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {

// inline embedded field
if f.Anonymous {
innerAssociations, err := ForStruct(v.Field(i).Interface(), fields...)
field := v.Field(i)
// we need field to be a pointer, so that we can later set the value
// if the embedded field is of type struct {...}, we have to take its address
if field.Kind() != reflect.Ptr {
field = field.Addr()
}
if fieldIsNil(field) {
// initialize zero value
field = reflect.New(field.Type().Elem())
// we can only get in this case if v.Field(i) is a pointer type because it could not be nil otherwise
// => it is safe to set it here as is
v.Field(i).Set(field)
}
innerAssociations, err := forStruct(parent, field.Interface(), fields)
if err != nil {
return nil, err
}
Expand All @@ -92,11 +110,12 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {
for name, builder := range associationBuilders {
tag := tags.Find(name)
if !tag.Empty() {
pt, pv := getModelDefinition(parent)
params := associationParams{
field: f,
model: s,
modelType: t,
modelValue: v,
model: parent,
modelType: pt,
modelValue: pv,
popTags: tags,
innerAssociations: fieldsWithInnerAssociation[f.Name],
}
Expand Down
1 change: 1 addition & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type crudable interface {
SelectMany(store, *Model, Query) error
Create(store, *Model, columns.Columns) error
Update(store, *Model, columns.Columns) error
UpdateQuery(store, *Model, columns.Columns, Query) (int64, error)
Destroy(store, *Model) error
Delete(store, *Model, Query) error
}
Expand Down
4 changes: 4 additions & 0 deletions dialect_cockroach.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (p *cockroach) Update(s store, model *Model, cols columns.Columns) error {
return genericUpdate(s, model, cols, p)
}

func (p *cockroach) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
return genericUpdateQuery(s, model, cols, p, query, sqlx.DOLLAR)
}

func (p *cockroach) Destroy(s store, model *Model) error {
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", p.Quote(model.TableName()), model.Alias(), model.WhereID()))
_, err := genericExec(s, stmt, model.ID())
Expand Down
27 changes: 27 additions & 0 deletions dialect_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gobuffalo/pop/v6/columns"
"github.com/gobuffalo/pop/v6/logging"
"github.com/gofrs/uuid"
"github.com/jmoiron/sqlx"
)

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

func genericUpdateQuery(s store, model *Model, cols columns.Columns, quoter quotable, query Query, bindType int) (int64, error) {
q := fmt.Sprintf("UPDATE %s AS %s SET %s", quoter.Quote(model.TableName()), model.Alias(), cols.Writeable().QuotedUpdateString(quoter))

q, updateArgs, err := sqlx.Named(q, model.Value)
if err != nil {
return 0, err
}

sb := query.toSQLBuilder(model)
q = sb.buildWhereClauses(q)

q = sqlx.Rebind(bindType, q)

result, err := genericExec(s, q, append(updateArgs, sb.args...)...)
if err != nil {
return 0, err
}

n, err := result.RowsAffected()
if err != nil {
return 0, err
}

return n, err
}

func genericDestroy(s store, model *Model, quoter quotable) error {
stmt := fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", quoter.Quote(model.TableName()), model.Alias(), model.WhereID())
_, err := genericExec(s, stmt, model.ID())
Expand Down
9 changes: 9 additions & 0 deletions dialect_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/gobuffalo/pop/v6/columns"
"github.com/gobuffalo/pop/v6/internal/defaults"
"github.com/gobuffalo/pop/v6/logging"
"github.com/jmoiron/sqlx"
)

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

func (m *mysql) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
if n, err := genericUpdateQuery(s, model, cols, m, query, sqlx.QUESTION); err != nil {
return n, fmt.Errorf("mysql update query: %w", err)
} else {
return n, nil
}
}

func (m *mysql) Destroy(s store, model *Model) error {
stmt := fmt.Sprintf("DELETE FROM %s WHERE %s = ?", m.Quote(model.TableName()), model.IDField())
_, err := genericExec(s, stmt, model.ID())
Expand Down
4 changes: 4 additions & 0 deletions dialect_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (p *postgresql) Update(s store, model *Model, cols columns.Columns) error {
return genericUpdate(s, model, cols, p)
}

func (p *postgresql) UpdateQuery(s store, model *Model, cols columns.Columns, query Query) (int64, error) {
return genericUpdateQuery(s, model, cols, p, query, sqlx.DOLLAR)
}

func (p *postgresql) Destroy(s store, model *Model) error {
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s AS %s WHERE %s", p.Quote(model.TableName()), model.Alias(), model.WhereID()))
_, err := genericExec(s, stmt, model.ID())
Expand Down
Loading