pg-triggers 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,10 +5,6 @@ Triggers for postgres
5
5
  ![extending](https://img.shields.io/badge/stability-extending-orange.svg)
6
6
  [![npm-version](https://img.shields.io/npm/v/pg-triggers.svg)](https://npmjs.org/package/pg-triggers)
7
7
  [![downloads](https://img.shields.io/npm/dm/pg-triggers.svg)](https://npmjs.org/package/pg-triggers)
8
- [![build](https://img.shields.io/travis/emilioplatzer/pg-triggers/master.svg)](https://travis-ci.org/emilioplatzer/pg-triggers)
9
- [![coverage](https://img.shields.io/coveralls/emilioplatzer/pg-triggers/master.svg)](https://coveralls.io/r/emilioplatzer/pg-triggers)
10
- [![dependencies](https://img.shields.io/david/emilioplatzer/pg-triggers.svg)](https://david-dm.org/emilioplatzer/pg-triggers)
11
-
12
8
 
13
9
 
14
10
  language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
@@ -28,12 +24,11 @@ $ psql < lib/enance.sql
28
24
  $ psql -c "select enance_table('state','country,state')"
29
25
  ```
30
26
  You must call enance_table(table_name, primary_key_fields) for each table that you want to audit changes on each time you create a table or alter the primary key.
31
- By default the function will audit inserts, updates and deletes. But exists a third parameter **method** (optional). If this param receives the 'ud' value won't audit inserts
32
- (only will listen for updates and deletes)
33
27
 
34
28
  # Devel
35
29
  ```sh
36
- $ npm install pg-triggers
30
+ $ npm install
31
+ $ psql --file install/create_db.sql
37
32
  $ npm test
38
33
  ```
39
34
 
@@ -0,0 +1,5 @@
1
+ declare module "pg-triggers"{
2
+
3
+ function table_name_max_id_trg(tableName:string, idName:string): Promise<string>;
4
+
5
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference path="./pg-triggers.d.ts" />
2
+ "use strict";
3
+
4
+ var fs = require("fs/promises");
5
+
6
+ var pgTriggers = {}
7
+
8
+ pgTriggers.table_name_max_id_trg = async function table_name_max_id_trg (tableName, idName) {
9
+ var content = await fs.readFile(__dirname + "/table-max-id-trg.sql", "utf8");
10
+ var sql = content.replace(/table_name/g, tableName).replace(/id_name/g, idName);
11
+ return sql;
12
+ };
13
+
14
+ module.exports = pgTriggers;
@@ -0,0 +1,20 @@
1
+ create or replace function table_name_max_id_trg() returns trigger
2
+ language plpgsql
3
+ as
4
+ $body$
5
+ declare
6
+ curr_max bigint;
7
+ begin
8
+ if new.id_name is null then
9
+ select max(id_name) into curr_max
10
+ from table_name;
11
+ new.id_name := coalesce(curr_max + 1, 1);
12
+ end if;
13
+ return new;
14
+ end;
15
+ $body$;
16
+
17
+ create trigger table_name_max_id_trg
18
+ before insert
19
+ on table_name
20
+ for each row execute function table_name_max_id_trg();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pg-triggers",
3
3
  "description": "Triggers for postgres",
4
- "version": "0.3.2",
4
+ "version": "0.4.0",
5
5
  "author": "Emilio Platzer <emilioplatzer@gmail.com>",
6
6
  "repository": "emilioplatzer/pg-triggers",
7
7
  "license": "MIT",
@@ -11,15 +11,15 @@
11
11
  ],
12
12
  "dependencies": {},
13
13
  "devDependencies": {
14
- "mocha": "~8.4.0",
15
- "nyc": "~15.1.0",
16
- "best-globals": "~0.10.32",
17
- "discrepances": "~0.2.6",
18
- "mini-tools": "~1.11.1",
19
- "pg-promise-strict": "~1.2.4"
14
+ "mocha": "^11.7.0",
15
+ "nyc": "^17.1.0",
16
+ "best-globals": "^2.0.1",
17
+ "discrepances": "^0.2.8",
18
+ "mini-tools": "^1.13.2",
19
+ "pg-promise-strict": "^1.4.2"
20
20
  },
21
21
  "engines": {
22
- "node": ">= 6"
22
+ "node": ">= 16"
23
23
  },
24
24
  "scripts": {
25
25
  "start": "node example/server.js",