21 lines
608 B
JavaScript
21 lines
608 B
JavaScript
|
const { Pool } = require('pg');
|
||
|
require('dotenv').config();
|
||
|
const moment = require('moment');
|
||
|
|
||
|
// Datenbankverbindung
|
||
|
const pool = new Pool({
|
||
|
connectionString: process.env.DATABASE_URL
|
||
|
});
|
||
|
|
||
|
async function writeKW() {
|
||
|
const resultTrainings = await pool.query('SELECT * FROM trainings');
|
||
|
const trainings = resultTrainings.rows;
|
||
|
for (const training of trainings) {
|
||
|
const jahr = moment(training.datum).year();
|
||
|
const kw = moment(training.datum).isoWeek();
|
||
|
await pool.query('UPDATE trainings SET kw = $1, jahr = $2 WHERE id = $3', [kw, jahr, training.id])
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
writeKW();
|