pg-functions 1.0.0 → 1.1.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/LICENSE +20 -20
- package/README.md +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -1
- package/dist/functions/PgFunctionBase.d.ts.map +1 -1
- package/dist/functions/PgFunctionBase.js +3 -1
- package/dist/functions/PgFunctionBase.js.map +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License Copyright (c) 2025 mauricio.basta
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free
|
|
4
|
-
of charge, to any person obtaining a copy of this software and associated
|
|
5
|
-
documentation files (the "Software"), to deal in the Software without
|
|
6
|
-
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
-
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
-
following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice
|
|
12
|
-
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
-
portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
-
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
-
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
1
|
+
MIT License Copyright (c) 2025 mauricio.basta
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free
|
|
4
|
+
of charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
21
|
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -76,3 +76,4 @@ setLogger(pino({ level: 'info' }));
|
|
|
76
76
|
| `PgConnection` | Wrapper de `PoolClient` con manejo de transacciones y logs |
|
|
77
77
|
| `registerPool()` | Registra el `Pool` global del proyecto |
|
|
78
78
|
| `setLogger()` | Define un logger personalizado |
|
|
79
|
+
| `setSchema()` | Define el nombre del schema a utilizar de la base de datos |
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Pool } from 'pg';
|
|
2
2
|
export declare function registerPool(pool: Pool): void;
|
|
3
3
|
export declare function getPool(): Pool;
|
|
4
|
+
export declare function setSchema(name: string): void;
|
|
5
|
+
export declare function getSchema(): string | undefined;
|
|
4
6
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK/B,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAK7C;AAED,wBAAgB,OAAO,IAAI,IAAI,CAK9B;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C"}
|
package/dist/context.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerPool = registerPool;
|
|
4
4
|
exports.getPool = getPool;
|
|
5
|
+
exports.setSchema = setSchema;
|
|
6
|
+
exports.getSchema = getSchema;
|
|
5
7
|
let appPool;
|
|
8
|
+
let schemaName;
|
|
6
9
|
function registerPool(pool) {
|
|
7
10
|
if (appPool) {
|
|
8
11
|
throw new Error('pg-functions: Ya existe un pool registrado. Solo se permite un pool por aplicación.');
|
|
@@ -15,4 +18,10 @@ function getPool() {
|
|
|
15
18
|
}
|
|
16
19
|
return appPool;
|
|
17
20
|
}
|
|
21
|
+
function setSchema(name) {
|
|
22
|
+
schemaName = name;
|
|
23
|
+
}
|
|
24
|
+
function getSchema() {
|
|
25
|
+
return schemaName;
|
|
26
|
+
}
|
|
18
27
|
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;AAKA,oCAKC;AAED,0BAKC;AAED,8BAEC;AAED,8BAEC;AAvBD,IAAI,OAAyB,CAAC;AAC9B,IAAI,UAA8B,CAAC;AAEnC,SAAgB,YAAY,CAAC,IAAU;IACrC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,qFAAqF,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AAED,SAAgB,OAAO;IACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sGAAsG,CAAC,CAAC;IAC1H,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,SAAS,CAAC,IAAY;IACpC,UAAU,GAAG,IAAI,CAAC;AACpB,CAAC;AAED,SAAgB,SAAS;IACvB,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgFunctionBase.d.ts","sourceRoot":"","sources":["../../src/functions/PgFunctionBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PgFunctionBase.d.ts","sourceRoot":"","sources":["../../src/functions/PgFunctionBase.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAEzC,8BAAsB,cAAe,YAAW,IAAI;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAO;gBAExB,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE;IAKrD,GAAG,CAAC,IAAI,GAAE,OAAyB,GAAG,MAAM;IAO5C,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM,EAAE;CAG9B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PgFunctionBase = void 0;
|
|
4
|
+
const context_1 = require("../context");
|
|
4
5
|
const SqlMode_enum_1 = require("../enum/SqlMode.enum");
|
|
5
6
|
class PgFunctionBase {
|
|
6
7
|
constructor(functionName, functionArgs) {
|
|
@@ -10,7 +11,8 @@ class PgFunctionBase {
|
|
|
10
11
|
sql(mode = SqlMode_enum_1.SqlMode.DEFAULT) {
|
|
11
12
|
const prefix = mode === SqlMode_enum_1.SqlMode.SCALAR ? 'SELECT' : 'SELECT * FROM';
|
|
12
13
|
const suffix = mode === SqlMode_enum_1.SqlMode.SCALAR ? ' AS result' : '';
|
|
13
|
-
|
|
14
|
+
const schema = (0, context_1.getSchema)() ? `${(0, context_1.getSchema)()}.` : '';
|
|
15
|
+
return `${prefix} ${schema}${this.functionName}(${this.getPlaceHolders()})${suffix};`;
|
|
14
16
|
}
|
|
15
17
|
getPlaceHolders() {
|
|
16
18
|
return this.functionArgs.length ? this.functionArgs.map((_, i) => `$${i + 1}`).join(', ') : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgFunctionBase.js","sourceRoot":"","sources":["../../src/functions/PgFunctionBase.ts"],"names":[],"mappings":";;;AAAA,uDAA8C;AAG9C,MAAsB,cAAc;IAIhC,YAAY,YAAoB,EAAE,YAAmB;QACjD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IACpC,CAAC;IAED,GAAG,CAAC,OAAgB,sBAAO,CAAC,OAAO;QAC/B,MAAM,MAAM,GAAG,IAAI,KAAK,sBAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,C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