import {
Version,
IVersion,
DbSettings,
Helper,
Plst } from 'rik-database';
const config = {
client: 'pg',
connection:
{
host: 'your host',
user: 'user',
password: 'password',
database: 'databaseName',
port: '5432'
}
};
DbSettings.setConfig(config);
export class Db {
public async getDataVersion(): Promise<void> {
let data = await Version.query().orderBy('id', 'desc').first();
console.log('\n+------- Versions -------+');
if(data){ console.log(data); }
else{ console.log('Table is empty.'); }
}
public async addNewVersion(version: IVersion): Promise<void> {
let newVersion = await Version.query().insert(version);
console.log('\nNew version has been added. Version: ', newVersion);
}
public async updateVersion(id: number, version: IVersion): Promise<void> {
let updateVersion = await Version.query().patchAndFetchById(id, version);
console.log('\nVersion has been updated. Version: ', updateVersion);
}
public async deleteVersionBy(id: number): Promise<void> {
let deletedVersion = await Version.query().deleteById(id);
console.log('\nVesions has been deleted, numbers: ', deletedVersion);
}
public async getTfzu(req: number): Promise<void> {
let task = Plst.query().skipUndefined()
.select('ECO1','PNUM', 'STZW', 'STPA', 'KLAR', 'a.ATTE as FZ_TFZU_1')
.leftOuterJoin('ATST as a', Helper.raw('cast("PLST"."FZ_TFZU_1" as int)'), 'a.ATNU')
.where('PLST.PNUM', '=', req)
.andWhere('PLST.GPR1', '>', 0)
.andWhere('PLST.WALO', '=', 0);
console.log('[SQL]: ', task.toSql());
let data = await task;
console.log(data);
}
}
(async () => {
try {
let db = new Db();
let version = { current_version: '2.2.2.4', description: 'fdfdfdfdf' }
//await == db.addNewVersion(version);
await db.getTfzu(1);
} catch (error) { console.error(error); } })()