Skip to content

Commit

Permalink
Making foreign key fields in json field table primary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
panyam committed Mar 25, 2022
1 parent 870a91b commit 9a6d28f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions db/gormdb/authdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestSaveAuth(t *testing.T) {

auth.CallbackUrl = "http://hello.world.com"
a1 := map[string]interface{}{
"a": 1,
"a": float64(11),
"b": "hello",
"c": true,
"expires_in": 60.0,
Expand All @@ -71,7 +71,7 @@ func TestSaveAuth(t *testing.T) {
auth.SetAuthToken(a1)

b1 := map[string]interface{}{
"x": 42,
"x": float64(42),
"y": "world",
"z": false,
}
Expand All @@ -83,6 +83,8 @@ func TestSaveAuth(t *testing.T) {
fetched, err := db.GetAuth("testclient1")
assert.Equal(t, err, nil, "GetAuth should succeed")
assert.NotEqual(t, fetched, nil, "GetAuth should succeed")
auth.AuthToken.LastUpdatedAt = fetched.AuthToken.LastUpdatedAt
auth.UserPrincipals.LastUpdatedAt = fetched.UserPrincipals.LastUpdatedAt
log.Println("Saved: ", auth)
log.Println("Fetched: ", fetched)
assert.Equal(t, auth, fetched, "Saved and Fetched auth should be equal")
Expand Down
4 changes: 2 additions & 2 deletions models/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

type AuthTokenJsonField struct {
*Json
AuthClientId string
AuthClientId string `gorm:"primaryKey"`
}

type UserPrincipalsJsonField struct {
*Json
AuthClientId string
AuthClientId string `gorm:"primaryKey"`
}

type Auth struct {
Expand Down
5 changes: 3 additions & 2 deletions models/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
var InvalidJsonKeyError = errors.New("InvalidJsonKeyError")

type Json struct {
ValueJson string
value interface{}
ValueJson string
LastUpdatedAt int64 `gorm:"autoUpdateTime:milli"`
value interface{}
}

func NewJson(value interface{}) *Json {
Expand Down
8 changes: 4 additions & 4 deletions models/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

type OptionJsonField struct {
*Json
OptionSymbol string
OptionDateString string
OptionIsCall bool
OptionPriceString string
OptionSymbol string `gorm:"primaryKey"`
OptionDateString string `gorm:"primaryKey"`
OptionIsCall bool `gorm:"primaryKey"`
OptionPriceString string `gorm:"primaryKey"`
}

type Option struct {
Expand Down
2 changes: 1 addition & 1 deletion models/tickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type TickerJsonField struct {
*Json
TickerSymbol string
TickerSymbol string `gorm:"primaryKey"`
}

type Ticker struct {
Expand Down

0 comments on commit 9a6d28f

Please sign in to comment.