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