generated from technologiestiftung/template-repo-citylab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.js
50 lines (43 loc) · 1.17 KB
/
import.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
/* eslint n/prefer-global/process: [error] */
import {readFile} from 'node:fs/promises';
import postgres from 'postgres';
export async function main() {
let sql;
try {
if (process.env.DATABASE_URL === undefined) {
throw new Error('DATABASE_URL is not set');
}
// This file needs to be generate from the Gesamtübersicht von SenASGIVA Abteilung III.xlsx
const content = await readFile('./general_overview.json', 'utf8');
/**
* @type {Array<{
thema: string;
typ: string;
datensatz_titel: string;
beschreibung: string;
raeumlicher_bezug: string;
verantwortlichkeit_bezirksebene: string;
ansprechperson_bezirksebene: string;
verantwortlichkeit_landesebene: string;
ansprechperson_landesebene: string;
datenhoheit_bei: string;
it_fachverfahren: string;
dateiformat: string;
datenqualitaet: string;
}>}
*/
const json = JSON.parse(content);
sql = postgres(process.env.DATABASE_URL);
const result = await sql`insert into general_overview ${sql(json)}`;
console.log(result);
await sql.end();
} catch (error) {
throw error;
} finally {
if (sql !== undefined) {
await sql.end();
}
}
}
await main();