mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 20:51:25 +03:00
Рефакторинг кода
This commit is contained in:
parent
14b7420557
commit
3cfc494ba6
1 changed files with 11 additions and 3 deletions
|
@ -1,17 +1,25 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const pool = require('./postgresql.js');
|
const pool = require('./postgresql.js');
|
||||||
|
|
||||||
|
const logger = require('../../logger/src/main.js');
|
||||||
|
|
||||||
async function create_table() {
|
async function create_table() {
|
||||||
const schema = fs.readFileSync(
|
const schema = fs.readFileSync(
|
||||||
'../shared/database/data/schema.sql',
|
'../shared/database/data/schema.sql',
|
||||||
'utf8',
|
'utf8',
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let i = 0; i < schema.split(';').length; i++) {
|
const queries = schema
|
||||||
|
.split(';')
|
||||||
|
.map((query) => query.trim())
|
||||||
|
.filter((query) => query);
|
||||||
|
|
||||||
|
for (const query of queries) {
|
||||||
try {
|
try {
|
||||||
await pool.query(schema.split(';')[i]);
|
await pool.query(query);
|
||||||
|
logger.info(`Executed query: ${query}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
continue;
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue