emilsoftware-utilities 1.2.4 → 1.2.5
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/autobind.js +1 -1
- package/orm.d.ts +1 -0
- package/orm.js +27 -11
- package/package.json +1 -1
- package/src/autobind.ts +0 -1
- package/src/log-execution-time.ts +0 -2
- package/src/orm.ts +36 -10
package/autobind.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// DECORATOR
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.boundClass = exports.boundMethod = void 0;
|
|
4
|
+
// DECORATOR
|
|
5
5
|
/**
|
|
6
6
|
* Return a descriptor removing the value and returning a getter
|
|
7
7
|
* The getter will return a .bind version of the function
|
package/orm.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface Orm {
|
|
|
9
9
|
startTransaction: (db: Database) => Promise<any>;
|
|
10
10
|
executeQueries: (transaction: Transaction, queries: string[], params: any[]) => any;
|
|
11
11
|
commitTransaction: (transaction: Transaction) => Promise<any>;
|
|
12
|
+
rollbackTransaction: (transaction: Transaction) => Promise<any>;
|
|
12
13
|
}
|
|
13
14
|
export declare const Orm: Orm;
|
|
14
15
|
export {};
|
package/orm.js
CHANGED
|
@@ -27,6 +27,7 @@ exports.Orm = void 0;
|
|
|
27
27
|
// @ts-ignore
|
|
28
28
|
var Firebird = __importStar(require("es-node-firebird"));
|
|
29
29
|
var logger_1 = require("./logger");
|
|
30
|
+
var utilities_1 = require("./utilities");
|
|
30
31
|
var quote = function (value) {
|
|
31
32
|
return "\"" + value + "\"";
|
|
32
33
|
};
|
|
@@ -47,13 +48,17 @@ var testConnection = function (options) {
|
|
|
47
48
|
};
|
|
48
49
|
var query = function (options, query, parameters) {
|
|
49
50
|
if (parameters === void 0) { parameters = []; }
|
|
51
|
+
var logger = new logger_1.Logger(__filename);
|
|
50
52
|
return new Promise(function (resolve, reject) {
|
|
51
53
|
Firebird.attach(options, function (err, db) {
|
|
52
54
|
if (err) {
|
|
55
|
+
logger.error(err);
|
|
53
56
|
return reject(err);
|
|
54
57
|
}
|
|
58
|
+
logger.info(utilities_1.Utilities.printQueryWithParams(query, parameters));
|
|
55
59
|
db.query(query, parameters, function (error, result) {
|
|
56
60
|
if (error) {
|
|
61
|
+
logger.error(error);
|
|
57
62
|
db.detach();
|
|
58
63
|
return reject(error);
|
|
59
64
|
}
|
|
@@ -107,6 +112,26 @@ var startTransaction = function (db) {
|
|
|
107
112
|
});
|
|
108
113
|
});
|
|
109
114
|
};
|
|
115
|
+
var commitTransaction = function (transaction) {
|
|
116
|
+
return new Promise(function (resolve, reject) {
|
|
117
|
+
transaction.commit(function (err) {
|
|
118
|
+
if (err)
|
|
119
|
+
return reject(err);
|
|
120
|
+
else
|
|
121
|
+
return resolve('Transaction committed successfully.');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
var rollbackTransaction = function (transaction) {
|
|
126
|
+
return new Promise(function (resolve, reject) {
|
|
127
|
+
transaction.rollback(function (err) {
|
|
128
|
+
if (err)
|
|
129
|
+
return reject(err);
|
|
130
|
+
else
|
|
131
|
+
return resolve('Transaction rolled back successfully.');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
110
135
|
var executeQueries = function (transaction, queries, params) {
|
|
111
136
|
return queries.reduce(function (promiseChain, currentQuery, index) {
|
|
112
137
|
return promiseChain.then(function () { return new Promise(function (resolve, reject) {
|
|
@@ -119,16 +144,6 @@ var executeQueries = function (transaction, queries, params) {
|
|
|
119
144
|
}); });
|
|
120
145
|
}, Promise.resolve());
|
|
121
146
|
};
|
|
122
|
-
var commitTransaction = function (transaction) {
|
|
123
|
-
return new Promise(function (resolve, reject) {
|
|
124
|
-
transaction.commit(function (err) {
|
|
125
|
-
if (err)
|
|
126
|
-
return reject(err);
|
|
127
|
-
else
|
|
128
|
-
return resolve('Transaction committed successfully.');
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
147
|
exports.Orm = {
|
|
133
148
|
quote: quote,
|
|
134
149
|
testConnection: testConnection,
|
|
@@ -138,5 +153,6 @@ exports.Orm = {
|
|
|
138
153
|
connect: connect,
|
|
139
154
|
startTransaction: startTransaction,
|
|
140
155
|
executeQueries: executeQueries,
|
|
141
|
-
commitTransaction: commitTransaction
|
|
156
|
+
commitTransaction: commitTransaction,
|
|
157
|
+
rollbackTransaction: rollbackTransaction
|
|
142
158
|
};
|
package/package.json
CHANGED
package/src/autobind.ts
CHANGED
package/src/orm.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as Firebird from "es-node-firebird";
|
|
3
3
|
import {Logger} from "./logger";
|
|
4
4
|
import {Database, Options, Transaction} from "node-firebird";
|
|
5
|
+
import {Utilities} from "./utilities";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const quote = (value: string): string => {
|
|
@@ -23,15 +24,20 @@ const testConnection = (options: Options): Promise<any> => {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const query = (options: Options, query: string, parameters: any[] = []): Promise<any> => {
|
|
27
|
+
const logger: Logger = new Logger(__filename);
|
|
26
28
|
return new Promise((resolve, reject): void => {
|
|
27
29
|
Firebird.attach(options, (err: any, db: {
|
|
28
30
|
query: (arg0: any, arg1: any[], arg2: (err: any, result: any) => void) => void; detach: () => void;
|
|
29
31
|
}) => {
|
|
30
32
|
if (err) {
|
|
33
|
+
logger.error(err);
|
|
31
34
|
return reject(err);
|
|
32
35
|
}
|
|
36
|
+
|
|
37
|
+
logger.info(Utilities.printQueryWithParams(query, parameters));
|
|
33
38
|
db.query(query, parameters, (error: any, result: any) => {
|
|
34
39
|
if (error) {
|
|
40
|
+
logger.error(error);
|
|
35
41
|
db.detach();
|
|
36
42
|
return reject(error);
|
|
37
43
|
}
|
|
@@ -49,7 +55,6 @@ const execute = (options: Options, query: string, parameters: any = []): Promise
|
|
|
49
55
|
if (err) {
|
|
50
56
|
return reject(err);
|
|
51
57
|
}
|
|
52
|
-
|
|
53
58
|
db.execute(query, parameters, (error, result): void => {
|
|
54
59
|
if (error) {
|
|
55
60
|
db.detach();
|
|
@@ -84,6 +89,24 @@ const startTransaction = (db: Database): Promise<any> => {
|
|
|
84
89
|
});
|
|
85
90
|
});
|
|
86
91
|
}
|
|
92
|
+
|
|
93
|
+
const commitTransaction = (transaction: Transaction): Promise<any> => {
|
|
94
|
+
return new Promise((resolve, reject): void => {
|
|
95
|
+
transaction.commit((err: any): void => {
|
|
96
|
+
if (err) return reject(err); else return resolve('Transaction committed successfully.');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const rollbackTransaction = (transaction: Transaction): Promise<any> => {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
transaction.rollback(err => {
|
|
104
|
+
if (err) return reject(err); else return resolve('Transaction rolled back successfully.');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
87
110
|
const executeQueries = (transaction: Transaction, queries: string[], params: any[]) => {
|
|
88
111
|
return queries.reduce((promiseChain: any, currentQuery: any, index: any) => {
|
|
89
112
|
return promiseChain.then(() => new Promise((resolve, reject): void => {
|
|
@@ -94,13 +117,6 @@ const executeQueries = (transaction: Transaction, queries: string[], params: any
|
|
|
94
117
|
}, Promise.resolve());
|
|
95
118
|
}
|
|
96
119
|
|
|
97
|
-
const commitTransaction = (transaction: Transaction): Promise<any> => {
|
|
98
|
-
return new Promise((resolve, reject): void => {
|
|
99
|
-
transaction.commit((err: any): void => {
|
|
100
|
-
if (err) return reject(err); else return resolve('Transaction committed successfully.');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
120
|
|
|
105
121
|
interface Orm {
|
|
106
122
|
quote: (value: string) => string,
|
|
@@ -111,11 +127,21 @@ interface Orm {
|
|
|
111
127
|
connect: (options: Options) => Promise<any>,
|
|
112
128
|
startTransaction: (db: Database) => Promise<any>,
|
|
113
129
|
executeQueries: (transaction: Transaction, queries: string[], params: any[]) => any,
|
|
114
|
-
commitTransaction: (transaction: Transaction) => Promise<any
|
|
130
|
+
commitTransaction: (transaction: Transaction) => Promise<any>,
|
|
131
|
+
rollbackTransaction: (transaction: Transaction) => Promise<any>
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
export const Orm: Orm = {
|
|
118
|
-
quote,
|
|
135
|
+
quote,
|
|
136
|
+
testConnection,
|
|
137
|
+
query,
|
|
138
|
+
execute,
|
|
139
|
+
trimParam,
|
|
140
|
+
connect,
|
|
141
|
+
startTransaction,
|
|
142
|
+
executeQueries,
|
|
143
|
+
commitTransaction,
|
|
144
|
+
rollbackTransaction
|
|
119
145
|
}
|
|
120
146
|
|
|
121
147
|
|