pcgamedb/db/import.go
nite07 434dbb1dc2
All checks were successful
docker / prepare-and-build (push) Successful in 2m37s
release / goreleaser (push) Successful in 24m0s
refactor DeduplicateGameItems
update games.json
2024-11-22 01:30:26 +08:00

46 lines
860 B
Go

package db
import (
"context"
"encoding/json"
"os"
"pcgamedb/model"
)
func ImportGameInfo(filePath string) error {
var gameInfo []*model.GameInfo
data, err := os.ReadFile(filePath)
if err != nil {
return err
}
err = json.Unmarshal(data, &gameInfo)
if err != nil {
return err
}
docs := make([]interface{}, len(gameInfo))
for i, v := range gameInfo {
docs[i] = v
}
_, err = GameInfoCollection.InsertMany(context.Background(), docs)
return err
}
func ImportGameItem(filePath string) error {
var gameItem []*model.GameItem
data, err := os.ReadFile(filePath)
if err != nil {
return err
}
err = json.Unmarshal(data, &gameItem)
if err != nil {
return err
}
docs := make([]interface{}, len(gameItem))
for i, v := range gameItem {
docs[i] = v
}
_, err = GameItemCollection.InsertMany(context.Background(), docs)
return err
}