Commit 6a0025ce authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

nip

parent ac440720
......@@ -103,7 +103,7 @@ The app can also use `PostgreSqlEngine`.
To make it work, pass environment variables according to the documentation of the LIBPGSQL library. https://www.postgresql.org/docs/9.1/libpq-envars.html
Please remember that protocol and/or transaction id `sequences` will be created in the database if not provided.
Each day a new sequence will be created for protocol needs as `seqyyyyddmm_seq`.
Each day a new sequence will be created for protocol needs as `protyyyymmdd_seq`.
So if you do not need to keep tracking on application, you may need to clean up those sequences from time to time using a cron job.
Look at `FileEngine.ts` and `PostgreSqlEngine.ts` for examples to extend the store to another 'real' database.
......@@ -8,6 +8,7 @@
// auditTransactionDate: varchar(20);
// auditUserIp: varchar(16);
// auditUserId: varchar(255);
// if you do not provide the table name, the engine will create it for you.
//You can use Docker to run PostgreSQL for your tests.
//`docker run -d --name audit-postgres -e POSTGRES_PASSWORD=audit --network host postgres`
......@@ -89,7 +90,7 @@ export class PostgreSqlEngine implements AuditEngine {
try {
let data = {}
const res = this.#client.querySync("SELECT * FROM "+this.#table+" WHERE "+this.#columnNames.auditTransactionId+"='"+auditTransactionId+"';");
data = res.rows[0];
data = res[0];
return data;
} catch (error) {
throw error;
......@@ -123,11 +124,10 @@ export class PostgreSqlEngine implements AuditEngine {
pn(): string {
try {
const protocol_date = new Date().toISOString().split('T')[0];
const seqName = "SEQ"+protocol_date.replace(/-/g, '');
const seqName = "prot"+protocol_date.replace(/-/g, '');
//create sequence for protocol_date if not exists
this.#client.querySync("CREATE SEQUENCE IF NOT EXISTS "+seqName+"_seq START 1");
const res = this.#client.querySync("SELECT nextval('"+seqName+"_seq');");
//TODO delete past protocol_date sequences
return res[0].nextval+"/"+protocol_date;
} catch (error) {
throw error;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment