remove location table
This commit is contained in:
@@ -23,11 +23,9 @@ func NewPGXRepo(pool *pgxpool.Pool) Repository {
|
||||
}
|
||||
}
|
||||
|
||||
const insertAcceptedMeteoData = `insert into public.meteo_data (location_id, max_temp, min_temp, rainfall, cloudiness, created_at) values ($1, $2, $3, $4, $5, $6) returning id`
|
||||
const insertAcceptedMeteoData = `insert into public.meteo_data (location_name, max_temp, min_temp, rainfall, cloudiness, created_at) values ($1, $2, $3, $4, $5, $6) returning id`
|
||||
|
||||
func (pgx *pgxRepo) InsertAcceptedMeteoData(ctx context.Context, data []MeteoData) (int, error) {
|
||||
// TODO pass context
|
||||
// TODO improve transaction
|
||||
tx, err := pgx.Begin(ctx)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error starting transaction: %w", err)
|
||||
@@ -37,8 +35,7 @@ func (pgx *pgxRepo) InsertAcceptedMeteoData(ctx context.Context, data []MeteoDat
|
||||
batch := &b.Batch{}
|
||||
|
||||
for _, d := range data {
|
||||
// TODO get city id before insert!
|
||||
batch.Queue(insertAcceptedMeteoData, 1, d.MaxTemp, d.MinTemp, d.Rainfall, d.Cloudiness, d.Timestamp)
|
||||
batch.Queue(insertAcceptedMeteoData, d.Location, d.MaxTemp, d.MinTemp, d.Rainfall, d.Cloudiness, d.Timestamp)
|
||||
}
|
||||
|
||||
results := tx.SendBatch(ctx, batch)
|
||||
|
||||
Reference in New Issue
Block a user