Starting to work with cities

This commit is contained in:
2024-08-09 01:56:19 +03:00
parent 21731dc0ae
commit 2b33fec932
7 changed files with 54042 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import pg from 'pg';
import fs from 'fs';
import { convertMsgType } from './utils.js';
import { convertMsgType, logError } from './utils.js';
import { exec } from 'child_process';
const { Client } = pg;
@@ -16,6 +17,15 @@ const getClient = async () => {
await client.query(fs.readFileSync('./scheme.psql').toString());
if ((await client.query("SELECT * FROM cities")).rowCount < 6079) {
await client.query("DELETE FROM cities");
//Not sure if pg has support for such kind of things, sooooooooo
exec(`psql -h ${process.env.POSTGRES_HOST} -p ${process.env.POSTGRES_PORT} -d ${process.env.POSTGRES_DB} -U ${process.env.POSTGRES_USER} -f ./cities.sql`, (error) => {
if (error) logError(error);
})
}
return client;
};