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

feat: custom database connection for model #254

Merged
merged 24 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
aedcab4
overwrite default connection for model
kkumar-gcc Jul 29, 2023
521e42d
Merge branch 'master' into kkumar-gcc/#182
hwbrzzl Jul 30, 2023
40630ca
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 2, 2023
b7e0e73
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 5, 2023
b0596be
remove `Model` from orm
kkumar-gcc Aug 5, 2023
11ce9d6
remove test for `Model` method
kkumar-gcc Aug 5, 2023
897d15c
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 7, 2023
4ed66af
[bug fix] gorm instance missing all conditions
kkumar-gcc Aug 10, 2023
2c82d61
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 16, 2023
8945365
add `person` model to test custom connection
kkumar-gcc Aug 19, 2023
8f9845d
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 19, 2023
5701495
add test cases for custom connection
kkumar-gcc Aug 19, 2023
3427325
add a separate test case for custom connection
kkumar-gcc Aug 20, 2023
c3dba76
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 21, 2023
31335b2
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 22, 2023
3db9df1
re-implement refresh connection
kkumar-gcc Aug 22, 2023
8062a63
[bug fix] missing conditions
kkumar-gcc Aug 23, 2023
aab53dc
remove `Connection` method for User Model
kkumar-gcc Aug 23, 2023
0a2998a
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 23, 2023
5dc17cd
skipping tests of using docker
kkumar-gcc Aug 24, 2023
e233a4b
Merge remote-tracking branch 'origin/kkumar-gcc/#182' into kkumar-gcc…
kkumar-gcc Aug 24, 2023
5b7cba0
refactor refreshConnection
kkumar-gcc Aug 25, 2023
c0a44f6
add model review and person for custom connection testing
kkumar-gcc Aug 25, 2023
54dad30
Merge branch 'master' into kkumar-gcc/#182
kkumar-gcc Aug 25, 2023
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
11 changes: 5 additions & 6 deletions contracts/database/orm/mocks/Association.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 65 additions & 11 deletions contracts/database/orm/mocks/Transaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions contracts/database/orm/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ type Association interface {
Count() int64
}

type ConnectionModel interface {
Connection() string
}

//go:generate mockery --name=Cursor
type Cursor interface {
Scan(value any) error
Expand Down
2 changes: 1 addition & 1 deletion database/gorm/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e *Event) IsClean(fields ...string) bool {
}

func (e *Event) Query() orm.Query {
return NewQueryWithWithoutEvents(e.query.instance.Session(&gorm.Session{NewDB: true}), false)
return NewQueryWithWithoutEvents(e.query.instance.Session(&gorm.Session{NewDB: true}), false, e.query.config)
}

func (e *Event) Context() context.Context {
Expand Down
8 changes: 4 additions & 4 deletions database/gorm/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var testQuery = NewQueryWithWithoutEvents(&gorm.DB{
Selects: []string{},
Omits: []string{},
},
}, false)
}, false, nil)

type EventTestSuite struct {
suite.Suite
Expand Down Expand Up @@ -53,7 +53,7 @@ func (s *EventTestSuite) TestSetAttribute() {
Omits: []string{},
Dest: dest,
},
}, false)
}, false, nil)

event := NewEvent(query, &testEventModel, dest)

Expand Down Expand Up @@ -152,7 +152,7 @@ func (s *EventTestSuite) TestValidColumn() {
Selects: []string{"name"},
Omits: []string{},
},
}, false)
}, false, nil)
s.True(event.validColumn("Name"))
s.True(event.validColumn("name"))
s.False(event.validColumn("avatar"))
Expand All @@ -163,7 +163,7 @@ func (s *EventTestSuite) TestValidColumn() {
Selects: []string{},
Omits: []string{"name"},
},
}, false)
}, false, nil)
s.False(event.validColumn("Name"))
s.False(event.validColumn("name"))
s.True(event.validColumn("avatar"))
Expand Down
Loading
Loading