timetable-mgr/dbAccess/corpus.go
Fred Boniface 493fb41da8
Some checks failed
Go Test / test (push) Failing after 48s
Reorganise repo
2024-04-05 22:23:42 +01:00

56 lines
1.5 KiB
Go

package dbAccess
import (
"context"
"git.fjla.uk/owlboard/go-types/pkg/database"
)
// Puts an array of Corpus Documents into the database
func PutManyCorpus(corpusData []database.CorpusEntry) error {
collection := MongoClient.Database(databaseName).Collection(CorpusCollection)
documents := convertCorpusToInterfaceSlice(corpusData)
_, err := collection.InsertMany(context.Background(), documents)
if err != nil {
return err
}
SetUpdateTime(CorpusCollection)
return nil
}
// Puts an array of Stations documents into the database
func PutManyStations(stationsData []database.StationEntry) error {
collection := MongoClient.Database(databaseName).Collection(StationsCollection)
documents := convertStationsToInterfaceSlice(stationsData)
_, err := collection.InsertMany(context.Background(), documents)
if err != nil {
return err
}
SetUpdateTime(StationsCollection)
return nil
}
// Converts []database.CorpusEntry types into interface slices required to put them into the database
func convertCorpusToInterfaceSlice(corpusData []database.CorpusEntry) []interface{} {
interfaceSlice := make([]interface{}, len(corpusData))
for i, doc := range corpusData {
interfaceSlice[i] = doc
}
return interfaceSlice
}
// Converts []database.StationEntry types into interface slices required to put them into the database
func convertStationsToInterfaceSlice(stationsData []database.StationEntry) []interface{} {
interfaceSlice := make([]interface{}, len(stationsData))
for i, doc := range stationsData {
interfaceSlice[i] = doc
}
return interfaceSlice
}