Skip to content

Commit

Permalink
With ID
Browse files Browse the repository at this point in the history
  • Loading branch information
high-moctane committed Dec 30, 2021
1 parent 56feebd commit 2d363dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func Save(ctx context.Context, conn *gorm.DB, r io.Reader, query Query, cache Ca
if !ok {
continue
}
val := TwoGramRecord{word1, word2, score}
val := TwoGramRecord{Word1: word1, Word2: word2, Score: score}
res := conn.Create(&val)
if res.Error != nil {
return fmt.Errorf("failed to save: %w", res.Error)
Expand All @@ -394,7 +394,7 @@ func Save(ctx context.Context, conn *gorm.DB, r io.Reader, query Query, cache Ca
if !ok {
continue
}
val := ThreeGramRecord{word1, word2, word3, score}
val := ThreeGramRecord{Word1: word1, Word2: word2, Word3: word3, Score: score}
res := conn.Create(&val)
if res.Error != nil {
return fmt.Errorf("failed to save: %w", res.Error)
Expand All @@ -416,7 +416,7 @@ func Save(ctx context.Context, conn *gorm.DB, r io.Reader, query Query, cache Ca
if !ok {
continue
}
val := FourGramRecord{word1, word2, word3, word4, score}
val := FourGramRecord{Word1: word1, Word2: word2, Word3: word3, Word4: word4, Score: score}
res := conn.Create(&val)
if res.Error != nil {
return fmt.Errorf("failed to save: %w", res.Error)
Expand All @@ -442,7 +442,7 @@ func Save(ctx context.Context, conn *gorm.DB, r io.Reader, query Query, cache Ca
if !ok {
continue
}
val := FiveGramRecord{word1, word2, word3, word4, word5, score}
val := FiveGramRecord{Word1: word1, Word2: word2, Word3: word3, Word4: word4, Word5: word5, Score: score}
res := conn.Create(&val)
if res.Error != nil {
return fmt.Errorf("failed to save: %w", res.Error)
Expand Down
32 changes: 18 additions & 14 deletions entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,35 @@ type OneGramRecord struct {
}

type TwoGramRecord struct {
Word1 int64 `gorm:"primaryKey"`
Word2 int64 `gorm:"primaryKey"`
ID int64
Word1 int64
Word2 int64
Score int64
}

type ThreeGramRecord struct {
Word1 int64 `gorm:"primaryKey"`
Word2 int64 `gorm:"primaryKey"`
Word3 int64 `gorm:"primaryKey"`
ID int64
Word1 int64
Word2 int64
Word3 int64
Score int64
}

type FourGramRecord struct {
Word1 int64 `gorm:"primaryKey"`
Word2 int64 `gorm:"primaryKey"`
Word3 int64 `gorm:"primaryKey"`
Word4 int64 `gorm:"primaryKey"`
ID int64
Word1 int64
Word2 int64
Word3 int64
Word4 int64
Score int64
}

type FiveGramRecord struct {
Word1 int64 `gorm:"primaryKey"`
Word2 int64 `gorm:"primaryKey"`
Word3 int64 `gorm:"primaryKey"`
Word4 int64 `gorm:"primaryKey"`
Word5 int64 `gorm:"primaryKey"`
ID int64
Word1 int64
Word2 int64
Word3 int64
Word4 int64
Word5 int64
Score int64
}

0 comments on commit 2d363dd

Please sign in to comment.