pwi-plata-type 0.4.62 → 0.4.65
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/__BUILD__/index.js +3 -1
- package/__BUILD__/index.js.map +1 -1
- package/__BUILD__/libs/router.js +21 -0
- package/__BUILD__/libs/router.js.map +1 -1
- package/__BUILD__/libs/sql.js +157 -0
- package/__BUILD__/libs/sql.js.map +1 -0
- package/package.json +10 -3
- package/src/@types/exported.d.ts +3 -0
- package/src/@types/router.d.ts +4 -0
- package/src/@types/sql.d.ts +35 -0
- package/src/index.ts +2 -0
- package/src/libs/router.ts +28 -0
- package/src/libs/sql.ts +205 -0
- package/src/tests/assets/sql/example.db +0 -0
- package/src/tests/assets/sql/example.sql +38 -0
- package/src/tests/sql.test.ts +267 -0
package/__BUILD__/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.PlataFs = exports.PlataAxiosUnsafe = exports.PlataAxios = exports.PlataTasks = exports.PlataSwagger = exports.PlataModels = exports.PlataTools = exports.PlataRoutes = exports.PlataCluster = void 0;
|
|
26
|
+
exports.PlataFs = exports.PlataSql = exports.PlataAxiosUnsafe = exports.PlataAxios = exports.PlataTasks = exports.PlataSwagger = exports.PlataModels = exports.PlataTools = exports.PlataRoutes = exports.PlataCluster = void 0;
|
|
27
27
|
const PlataCluster = __importStar(require("./libs/cluster"));
|
|
28
28
|
exports.PlataCluster = PlataCluster;
|
|
29
29
|
const PlataRoutes = __importStar(require("./libs/router"));
|
|
@@ -36,6 +36,8 @@ const PlataTasks = __importStar(require("./libs/tasks"));
|
|
|
36
36
|
exports.PlataTasks = PlataTasks;
|
|
37
37
|
const PlataSwagger = __importStar(require("./libs/swagger"));
|
|
38
38
|
exports.PlataSwagger = PlataSwagger;
|
|
39
|
+
const PlataSql = __importStar(require("./libs/sql"));
|
|
40
|
+
exports.PlataSql = PlataSql;
|
|
39
41
|
const fs_1 = require("./libs/fs");
|
|
40
42
|
Object.defineProperty(exports, "PlataFs", { enumerable: true, get: function () { return fs_1.PlataFs; } });
|
|
41
43
|
const axios_1 = require("./libs/axios");
|
package/__BUILD__/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA8C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA8C;AAW1C,oCAAY;AAVhB,2DAA4C;AAWxC,kCAAW;AAVf,yDAA0C;AAWtC,gCAAU;AAVd,0DAA2C;AAWvC,kCAAW;AAVf,yDAA0C;AAYtC,gCAAU;AAXd,6DAA8C;AAU1C,oCAAY;AAThB,qDAAsC;AAalC,4BAAQ;AAZZ,kCAAmC;AAa/B,wFAbK,YAAO,OAaL;AAZX,wCAA2D;AASvD,2FATK,kBAAU,OASL;AACV,iGAViB,wBAAgB,OAUjB"}
|
package/__BUILD__/libs/router.js
CHANGED
|
@@ -45,6 +45,14 @@ var Internals;
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
Internals.buildRouterObject = buildRouterObject;
|
|
48
|
+
Internals.ResolveOnResponseEventQueue = async (aReq, aRes, body, error) => {
|
|
49
|
+
if (aReq._onResponseEvent.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
aReq._onResponseEvent.forEach((r) => {
|
|
53
|
+
Plata.FastPromise(() => r(aReq, aRes, body, error)).catch(() => undefined);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
48
56
|
function buildRequestHandler(r) {
|
|
49
57
|
if (Array.isArray(r)) {
|
|
50
58
|
return r.map(h => buildRequestHandler(h));
|
|
@@ -58,10 +66,23 @@ var Internals;
|
|
|
58
66
|
if (aReq.extras === undefined) {
|
|
59
67
|
aReq.extras = new Object(null);
|
|
60
68
|
}
|
|
69
|
+
if (aReq._onResponseEvent === undefined) {
|
|
70
|
+
aReq._onResponseEvent = [];
|
|
71
|
+
}
|
|
72
|
+
if (aRes.addOnResponseEvent === undefined) {
|
|
73
|
+
aRes.addOnResponseEvent = (callback) => {
|
|
74
|
+
aReq._onResponseEvent.push(callback);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
61
77
|
if (aRes.oldJson === undefined) {
|
|
62
78
|
aRes.oldJson = aRes.json;
|
|
63
79
|
}
|
|
80
|
+
aRes.json = (body) => {
|
|
81
|
+
Plata.FastPromise(async () => { Internals.ResolveOnResponseEventQueue(aReq, aRes, body, undefined); });
|
|
82
|
+
return aRes.oldJson(body);
|
|
83
|
+
};
|
|
64
84
|
aRes.error = error => {
|
|
85
|
+
Plata.FastPromise(async () => { Internals.ResolveOnResponseEventQueue(aReq, aRes, undefined, error); });
|
|
65
86
|
return aRes.oldJson(error);
|
|
66
87
|
};
|
|
67
88
|
return r(aReq, aRes, next);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/libs/router.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,qCAAyC;AAEzC,IAAiB,SAAS,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/libs/router.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAC5B,qCAAyC;AAEzC,IAAiB,SAAS,CAoGzB;AApGD,WAAiB,SAAS;IACtB,SAAgB,iBAAiB;QAC7B,MAAM,MAAM,GAAwB;YAChC,MAAM,EAAE,EAAE;YACV,WAAW,EAAE,KAAK;SACrB,CAAA;QAED,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;YACrB,GAAG,EAAE,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE;gBACxB,IAAI,YA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MAAM,CAAC,CAAC,CAAC,CAAA;YAEvB,IAAI,QAAQ,GAAG,CAAC,CAAC,SAAS,CAAA;YAE1B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;gBAC1B,QAAQ,GAAG,mBAAI,CAAC,SAAS,CAAC,GAAG,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;aAC7E;YAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAEpF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,QAAQ,EAAE,EAAE;gBACZ,WAAW,EAAE,WAAW;aAC3B,CAAC,CAAA;SACL;KACJ;IAED,OAAO,MAAM,CAAA;AACjB,CAAC;AAjCD,gDAiCC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Query = exports.Driver = void 0;
|
|
7
|
+
const knex_1 = __importDefault(require("knex"));
|
|
8
|
+
class Driver {
|
|
9
|
+
config;
|
|
10
|
+
inTransaction;
|
|
11
|
+
conn;
|
|
12
|
+
constructor(config, inTransaction, trx) {
|
|
13
|
+
this.inTransaction = inTransaction;
|
|
14
|
+
this.config = config;
|
|
15
|
+
if (!this.inTransaction) {
|
|
16
|
+
if (config.pool === undefined)
|
|
17
|
+
config.pool = {
|
|
18
|
+
min: 1,
|
|
19
|
+
max: 1
|
|
20
|
+
};
|
|
21
|
+
this.conn = (0, knex_1.default)(config);
|
|
22
|
+
if (Plata.config.ENV === 'debug') {
|
|
23
|
+
this.conn.on('query', console.log);
|
|
24
|
+
this.conn.on('query-error', console.error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.conn = trx;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
select(table, model) {
|
|
32
|
+
return {
|
|
33
|
+
build: (builder) => new Query(builder(this.conn.select(...Object.keys(model.template)).from(table)), model),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async insert(table, model, values) {
|
|
37
|
+
return this.conn(table).insert(values).returning('*').then(r => r, err => Plata.BuildPlataError({
|
|
38
|
+
errorID: 'PLSQL001',
|
|
39
|
+
msg: 'Unexpected error while inserting',
|
|
40
|
+
error: err?.toString(),
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
update(table, model) {
|
|
44
|
+
return {
|
|
45
|
+
build: async (s, set) => Plata.FastPromise(() => s(this.conn(table)).update(set)).then(rows => rows, err => Plata.BuildPlataError({
|
|
46
|
+
errorID: 'PLSQL002',
|
|
47
|
+
msg: 'Unexpected error while update',
|
|
48
|
+
error: err
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
trasation(transaction, config) {
|
|
53
|
+
return this.conn.transaction(async (trx) => {
|
|
54
|
+
const transactionDriver = new Driver(this.config, true, trx);
|
|
55
|
+
return transaction(transactionDriver);
|
|
56
|
+
}, config).then(r => r, err => Plata.BuildPlataError({
|
|
57
|
+
errorID: 'PLSQL003',
|
|
58
|
+
msg: 'Unexpected error in transation',
|
|
59
|
+
error: err,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Driver = Driver;
|
|
64
|
+
class Query {
|
|
65
|
+
query;
|
|
66
|
+
model;
|
|
67
|
+
constructor(query, model) {
|
|
68
|
+
this.query = query;
|
|
69
|
+
this.model = model;
|
|
70
|
+
}
|
|
71
|
+
_handleStream(handler) {
|
|
72
|
+
return new Promise(resolve => {
|
|
73
|
+
let shoudContinue = true;
|
|
74
|
+
const stream = this.query.stream();
|
|
75
|
+
stream.on('close', async () => {
|
|
76
|
+
if (shoudContinue) {
|
|
77
|
+
return resolve(handler.close());
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
stream.on('data', async (row) => {
|
|
81
|
+
if (shoudContinue) {
|
|
82
|
+
shoudContinue = await handler.row(row);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
stream.on('error', async (err) => {
|
|
86
|
+
shoudContinue = false;
|
|
87
|
+
if (handler.error !== undefined)
|
|
88
|
+
await handler.error(err);
|
|
89
|
+
return resolve({
|
|
90
|
+
errorID: 'PLSQLQ001',
|
|
91
|
+
msg: 'Unexpected error in query',
|
|
92
|
+
error: err
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
toListAsync() {
|
|
98
|
+
const promises = [];
|
|
99
|
+
const itens = [];
|
|
100
|
+
const errors = [];
|
|
101
|
+
return this._handleStream({
|
|
102
|
+
row: async (row) => {
|
|
103
|
+
promises.push(Plata.FastPromise(() => this.model.validate(row)
|
|
104
|
+
.then(r => {
|
|
105
|
+
itens.push(r.value);
|
|
106
|
+
errors.push(...(r.errors ?? []));
|
|
107
|
+
})));
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
close: async () => {
|
|
111
|
+
return Promise.all(promises).then(() => {
|
|
112
|
+
return {
|
|
113
|
+
itens,
|
|
114
|
+
errors: errors.length === 0 ? undefined : errors
|
|
115
|
+
};
|
|
116
|
+
}, err => Plata.BuildPlataError({
|
|
117
|
+
errorID: 'PLSQLQ002',
|
|
118
|
+
msg: 'Unexpected error in select',
|
|
119
|
+
error: err
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async eachRowAsync(c) {
|
|
125
|
+
const promises = [];
|
|
126
|
+
let shoudContinue = true;
|
|
127
|
+
let error = undefined;
|
|
128
|
+
return this._handleStream({
|
|
129
|
+
row: async (row) => {
|
|
130
|
+
promises.push(Plata.FastPromise(() => this.model.validate(row))
|
|
131
|
+
.then(lineResult => {
|
|
132
|
+
c(lineResult).then(r => {
|
|
133
|
+
shoudContinue = shoudContinue ? r : shoudContinue;
|
|
134
|
+
});
|
|
135
|
+
})
|
|
136
|
+
.catch(err => {
|
|
137
|
+
shoudContinue = false;
|
|
138
|
+
error = {
|
|
139
|
+
errorID: 'PLSQLQ003',
|
|
140
|
+
msg: 'Unexpected error in callback',
|
|
141
|
+
error: err
|
|
142
|
+
};
|
|
143
|
+
}));
|
|
144
|
+
return shoudContinue;
|
|
145
|
+
},
|
|
146
|
+
close: async () => {
|
|
147
|
+
return Promise.all(promises).then(() => error ?? true, err => Plata.BuildPlataError({
|
|
148
|
+
errorID: 'PLSQLQ004',
|
|
149
|
+
msg: 'Unexpected Error in select',
|
|
150
|
+
error: err
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.Query = Query;
|
|
157
|
+
//# sourceMappingURL=sql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../../src/libs/sql.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAiC;AAGjC,MAAa,MAAM;IACC,MAAM,CAAa;IACnB,aAAa,CAAe;IAC5B,IAAI,CAAsD;IAC1E,YAAY,MAAmB,EAAE,aAA4B,EAAE,GAAsB;QACjF,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACrB,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;gBACzB,MAAM,CAAC,IAAI,GAAG;oBACV,GAAG,EAAE,CAAC;oBACN,GAAG,EAAE,CAAC;iBACT,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,EAAE,WAAW;wBACpB,GAAG,EAAE,8BAA8B;wBACnC,KAAK,EAAE,GAAG;qBACb,CAAA;gBACL,CAAC,CAAC,CACL,CAAA;gBAED,OAAO,aAAa,CAAA;YACxB,CAAC;YACD,KAAK,EAAE,KAAK,IAA2B,EAAE;gBACrC,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC7B,GAAG,EAAE,CAAC,KAAK,IAAI,IAAI,EACnB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC;oBACzB,OAAO,EAAE,WAAW;oBACpB,GAAG,EAAE,4BAA4B;oBACjC,KAAK,EAAE,GAAG;iBACb,CAAC,CACL,CAAA;YACL,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CACJ;AArHD,sBAqHC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwi-plata-type",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.65",
|
|
4
4
|
"main": "__BUILD__/index",
|
|
5
5
|
"types": "src/@types/exported.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"commander": "^9.4.0",
|
|
28
28
|
"express": "^4.18.1",
|
|
29
29
|
"glob": "^8.0.3",
|
|
30
|
+
"knex": "^2.4.2",
|
|
30
31
|
"node-schedule": "^2.1.0",
|
|
31
32
|
"swagger-ui-express": "^4.4.0",
|
|
32
33
|
"tsc-prog": "^2.2.1",
|
|
@@ -34,8 +35,14 @@
|
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"nodemon": "^2.0.20",
|
|
37
|
-
"rimraf": "^3.0.2"
|
|
38
|
+
"rimraf": "^3.0.2",
|
|
39
|
+
"sqlite3": "^5.1.4"
|
|
38
40
|
},
|
|
39
41
|
"description": "",
|
|
40
|
-
"files": [
|
|
42
|
+
"files": [
|
|
43
|
+
"__BUILD__",
|
|
44
|
+
"src",
|
|
45
|
+
"templates",
|
|
46
|
+
"tsconfig.json"
|
|
47
|
+
]
|
|
41
48
|
}
|
package/src/@types/exported.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/// <reference path="cluster.d.ts" />
|
|
4
4
|
/// <reference path="router.d.ts" />
|
|
5
5
|
/// <reference path="fs.d.ts" />
|
|
6
|
+
/// <reference path="sql.d.ts" />
|
|
6
7
|
/// <reference path="../bin/runtime/_types.d.ts" />
|
|
7
8
|
|
|
8
9
|
import * as PlataCluster from '../libs/cluster'
|
|
@@ -11,6 +12,7 @@ import * as PlataTools from '../libs/tools'
|
|
|
11
12
|
import * as PlataModels from '../libs/model'
|
|
12
13
|
import * as PlataTasks from '../libs/tasks'
|
|
13
14
|
import * as PlataSwagger from '../libs/swagger'
|
|
15
|
+
import * as PlataSql from '../libs/sql'
|
|
14
16
|
import { PlataFs } from '../libs/fs'
|
|
15
17
|
import { PlataAxios, PlataAxiosUnsafe } from '../libs/axios'
|
|
16
18
|
|
|
@@ -23,5 +25,6 @@ export {
|
|
|
23
25
|
PlataTasks,
|
|
24
26
|
PlataAxios,
|
|
25
27
|
PlataAxiosUnsafe,
|
|
28
|
+
PlataSql,
|
|
26
29
|
PlataFs
|
|
27
30
|
}
|
package/src/@types/router.d.ts
CHANGED
|
@@ -7,11 +7,13 @@ declare global {
|
|
|
7
7
|
interface Request extends express.Request {
|
|
8
8
|
user: any
|
|
9
9
|
extras: any
|
|
10
|
+
_onResponseEvent: PlataOnResponseEvent[]
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
interface Response extends express.Response {
|
|
13
14
|
oldJson(body?: any): this
|
|
14
15
|
error(error: PlataError | PlataError[]): this
|
|
16
|
+
addOnResponseEvent<T = any>(callback: PlataOnResponseEvent<T>): void
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
type RequestHandler = (req: Request, res: Response, next: express.NextFunction) => Promise<any>
|
|
@@ -71,5 +73,7 @@ declare global {
|
|
|
71
73
|
export interface RequiredRoute extends RequiredInterface<RouterBuilder> {
|
|
72
74
|
httpRoute: string
|
|
73
75
|
}
|
|
76
|
+
|
|
77
|
+
type PlataOnResponseEvent<T = any> = (aReq: Request, aRes?: Response, body?: T, error?: PlataError | PlataError[]) => Promise<any>
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Knex } from 'knex'
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace Sql {
|
|
5
|
+
type ModelQueryBuilder<T extends Model.Template> =
|
|
6
|
+
Knex.QueryBuilder<Model.ExtractTemplateType<T>, Model.ExtractTemplateType<T>[]>
|
|
7
|
+
;
|
|
8
|
+
|
|
9
|
+
type Builder<T extends Model.Template> =
|
|
10
|
+
(s: ModelQueryBuilder<T>) => ModelQueryBuilder<T>
|
|
11
|
+
;
|
|
12
|
+
|
|
13
|
+
interface StreamHandler {
|
|
14
|
+
close: <Y>() => PlataPromise<Y>
|
|
15
|
+
row: <T>(row: T) => Promise<boolean>
|
|
16
|
+
error?: (err) => Promise<void>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ModelList<T extends Model.Template> = PlataPromise<{
|
|
20
|
+
errors: undefined
|
|
21
|
+
itens: Model.ExtractTemplateType<T>[]
|
|
22
|
+
} | {
|
|
23
|
+
errors: PlataError[]
|
|
24
|
+
itens: Model.ExtractTemplateTypeNotValid<T>[]
|
|
25
|
+
}>
|
|
26
|
+
|
|
27
|
+
type EachRowCallBack<T extends Model.Template> =
|
|
28
|
+
(x: Model.ModelValidateReturn<T>) => Promise<boolean>
|
|
29
|
+
;
|
|
30
|
+
|
|
31
|
+
type TimeZoneDate = Date & { __type: 'sql' }
|
|
32
|
+
|
|
33
|
+
type TransactionFunction<T, Y> = (sql: T) => Promise<Y>
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as PlataTools from './libs/tools'
|
|
|
4
4
|
import * as PlataModels from './libs/model'
|
|
5
5
|
import * as PlataTasks from './libs/tasks'
|
|
6
6
|
import * as PlataSwagger from './libs/swagger'
|
|
7
|
+
import * as PlataSql from './libs/sql'
|
|
7
8
|
import { PlataFs } from './libs/fs'
|
|
8
9
|
import { PlataAxios, PlataAxiosUnsafe } from './libs/axios'
|
|
9
10
|
|
|
@@ -16,5 +17,6 @@ export {
|
|
|
16
17
|
PlataTasks,
|
|
17
18
|
PlataAxios,
|
|
18
19
|
PlataAxiosUnsafe,
|
|
20
|
+
PlataSql,
|
|
19
21
|
PlataFs
|
|
20
22
|
}
|
package/src/libs/router.ts
CHANGED
|
@@ -45,6 +45,18 @@ export namespace Internals {
|
|
|
45
45
|
}) as Router.Router
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
export const ResolveOnResponseEventQueue = async(aReq: Router.Request, aRes: Router.Response, body?: any, error?: PlataError | PlataError[]) => {
|
|
49
|
+
if (aReq._onResponseEvent.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
aReq._onResponseEvent.forEach((r) => {
|
|
55
|
+
Plata.FastPromise(() => r(aReq, aRes, body, error)).catch(() => undefined)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
export function buildRequestHandler(r: Router.RequestHandler | Router.RequestHandler[]): express.RequestHandler | express.RequestHandler[] {
|
|
49
61
|
if (Array.isArray(r)) {
|
|
50
62
|
return r.map(h => buildRequestHandler(h)) as express.RequestHandler[]
|
|
@@ -62,11 +74,27 @@ export namespace Internals {
|
|
|
62
74
|
aReq.extras = new Object(null)
|
|
63
75
|
}
|
|
64
76
|
|
|
77
|
+
if (aReq._onResponseEvent === undefined) {
|
|
78
|
+
aReq._onResponseEvent = []
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (aRes.addOnResponseEvent === undefined) {
|
|
82
|
+
aRes.addOnResponseEvent = (callback) => {
|
|
83
|
+
aReq._onResponseEvent.push(callback)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
if (aRes.oldJson === undefined) {
|
|
66
88
|
aRes.oldJson = aRes.json
|
|
67
89
|
}
|
|
68
90
|
|
|
91
|
+
aRes.json = (body?: any) => {
|
|
92
|
+
Plata.FastPromise(async () => { ResolveOnResponseEventQueue(aReq, aRes, body, undefined) })
|
|
93
|
+
return aRes.oldJson(body)
|
|
94
|
+
}
|
|
95
|
+
|
|
69
96
|
aRes.error = error => {
|
|
97
|
+
Plata.FastPromise(async () => { ResolveOnResponseEventQueue(aReq, aRes, undefined, error)})
|
|
70
98
|
return aRes.oldJson(error)
|
|
71
99
|
}
|
|
72
100
|
|
package/src/libs/sql.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import knex, { Knex } from "knex"
|
|
2
|
+
import { ModelTemplate } from "./model"
|
|
3
|
+
|
|
4
|
+
export class Driver<InTransaction extends boolean> {
|
|
5
|
+
public readonly config: Knex.Config
|
|
6
|
+
public readonly inTransaction: InTransaction
|
|
7
|
+
public readonly conn: InTransaction extends true ? Knex.Transaction : Knex
|
|
8
|
+
constructor(config: Knex.Config, inTransaction: InTransaction, trx?: Knex.Transaction) {
|
|
9
|
+
this.inTransaction = inTransaction
|
|
10
|
+
this.config = config
|
|
11
|
+
|
|
12
|
+
if (!this.inTransaction) {
|
|
13
|
+
if (config.pool === undefined)
|
|
14
|
+
config.pool = {
|
|
15
|
+
min: 1,
|
|
16
|
+
max: 1
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
|
|
20
|
+
this.conn = knex(config) as any
|
|
21
|
+
|
|
22
|
+
if (Plata.config.ENV === 'debug') {
|
|
23
|
+
this.conn.on('query', console.log)
|
|
24
|
+
this.conn.on('query-error', console.error)
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
this.conn = trx as any
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public select<T extends Model.Template, C extends Model.Converters<T>>(table: string, model: ModelTemplate<T, C>) {
|
|
32
|
+
return {
|
|
33
|
+
build: (builder: Sql.Builder<T>) =>
|
|
34
|
+
new Query(
|
|
35
|
+
builder(this.conn.select(...Object.keys(model.template)).from(table)),
|
|
36
|
+
model
|
|
37
|
+
)
|
|
38
|
+
,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async insert<T extends Model.Template, C extends Model.Converters<T>>(table: string, model: ModelTemplate<T, C>, values: Model.ParcialTemplateType<T>[]): PlataPromise<Model.ExtractTemplateType<T>[]> {
|
|
43
|
+
return this.conn(table).insert(
|
|
44
|
+
values,
|
|
45
|
+
).returning('*').then(
|
|
46
|
+
r => r,
|
|
47
|
+
err => Plata.BuildPlataError({
|
|
48
|
+
errorID: 'PLSQL001',
|
|
49
|
+
msg: 'Unexpected error while inserting',
|
|
50
|
+
error: err?.toString(),
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public update<T extends Model.Template, C extends Model.Converters<T>>(table: string, model: ModelTemplate<T, C>) {
|
|
56
|
+
return {
|
|
57
|
+
build: async (s: Sql.Builder<T>, set: Model.ParcialTemplateType<T>): PlataPromise<number> =>
|
|
58
|
+
Plata.FastPromise(() =>
|
|
59
|
+
s(this.conn(table)).update(set as any)
|
|
60
|
+
).then(
|
|
61
|
+
rows => rows,
|
|
62
|
+
err => Plata.BuildPlataError({
|
|
63
|
+
errorID: 'PLSQL002',
|
|
64
|
+
msg: 'Unexpected error while update',
|
|
65
|
+
error: err
|
|
66
|
+
})
|
|
67
|
+
)
|
|
68
|
+
,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public trasation<T = any>(transaction: Sql.TransactionFunction<Driver<true>, T>, config?: Knex.TransactionConfig) {
|
|
73
|
+
return this.conn.transaction(async trx => {
|
|
74
|
+
const transactionDriver = new Driver(this.config, true, trx)
|
|
75
|
+
|
|
76
|
+
return transaction(transactionDriver)
|
|
77
|
+
}, config).then(
|
|
78
|
+
r => r,
|
|
79
|
+
err => Plata.BuildPlataError({
|
|
80
|
+
errorID: 'PLSQL003',
|
|
81
|
+
msg: 'Unexpected error in transation',
|
|
82
|
+
error: err,
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class Query<T extends Model.Template, C extends Model.Converters<T>> {
|
|
89
|
+
public query: Sql.ModelQueryBuilder<T>
|
|
90
|
+
public readonly model: ModelTemplate<T, C>
|
|
91
|
+
|
|
92
|
+
constructor (query: Sql.ModelQueryBuilder<T>, model: ModelTemplate<T, C>) {
|
|
93
|
+
this.query = query
|
|
94
|
+
this.model = model
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public _handleStream<Y>(handler: Sql.StreamHandler): PlataPromise<Y> {
|
|
98
|
+
return new Promise(resolve => {
|
|
99
|
+
let shoudContinue = true
|
|
100
|
+
|
|
101
|
+
const stream = this.query.stream()
|
|
102
|
+
|
|
103
|
+
stream.on('close', async () => {
|
|
104
|
+
if (shoudContinue) {
|
|
105
|
+
return resolve(handler.close<Y>())
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
stream.on('data', async row => {
|
|
110
|
+
if (shoudContinue) {
|
|
111
|
+
shoudContinue = await handler.row(row)
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
stream.on('error', async err => {
|
|
116
|
+
shoudContinue = false
|
|
117
|
+
|
|
118
|
+
if (handler.error !== undefined) await handler.error(err)
|
|
119
|
+
|
|
120
|
+
return resolve({
|
|
121
|
+
errorID: 'PLSQLQ001',
|
|
122
|
+
msg: 'Unexpected error in query',
|
|
123
|
+
error: err
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public toListAsync(): Sql.ModelList<T> {
|
|
130
|
+
const promises: Promise<void>[] = []
|
|
131
|
+
const itens: any[] = []
|
|
132
|
+
const errors: PlataError[] = []
|
|
133
|
+
|
|
134
|
+
return this._handleStream({
|
|
135
|
+
row: async (row) => {
|
|
136
|
+
promises.push(Plata.FastPromise(
|
|
137
|
+
() =>
|
|
138
|
+
this.model.validate(row)
|
|
139
|
+
.then(r => {
|
|
140
|
+
itens.push(r.value)
|
|
141
|
+
errors.push(...(r.errors ?? []))
|
|
142
|
+
})
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return true
|
|
147
|
+
},
|
|
148
|
+
close: async (): PlataPromise<Sql.ModelList<T> | MaybePlataError> => {
|
|
149
|
+
return Promise.all(promises).then(
|
|
150
|
+
() => {
|
|
151
|
+
return {
|
|
152
|
+
itens,
|
|
153
|
+
errors: errors.length === 0 ? undefined : errors
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
err => Plata.BuildPlataError({
|
|
157
|
+
errorID: 'PLSQLQ002',
|
|
158
|
+
msg: 'Unexpected error in select',
|
|
159
|
+
error: err
|
|
160
|
+
})
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public async eachRowAsync(c: Sql.EachRowCallBack<T>): PlataPromise<boolean> {
|
|
167
|
+
const promises: Promise<void>[] = []
|
|
168
|
+
let shoudContinue = true
|
|
169
|
+
let error: PlataError | undefined = undefined
|
|
170
|
+
|
|
171
|
+
return this._handleStream<MaybePlataError>({
|
|
172
|
+
row: async row => {
|
|
173
|
+
promises.push(Plata.FastPromise(() => this.model.validate(row))
|
|
174
|
+
.then(
|
|
175
|
+
lineResult => {
|
|
176
|
+
c(lineResult).then(r => {
|
|
177
|
+
shoudContinue = shoudContinue ? r : shoudContinue
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
.catch(err => {
|
|
182
|
+
shoudContinue = false
|
|
183
|
+
error = {
|
|
184
|
+
errorID: 'PLSQLQ003',
|
|
185
|
+
msg: 'Unexpected error in callback',
|
|
186
|
+
error: err
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return shoudContinue
|
|
192
|
+
},
|
|
193
|
+
close: async (): PlataPromise<boolean> => {
|
|
194
|
+
return Promise.all(promises).then(
|
|
195
|
+
() => error ?? true,
|
|
196
|
+
err => Plata.BuildPlataError({
|
|
197
|
+
errorID: 'PLSQLQ004',
|
|
198
|
+
msg: 'Unexpected Error in select',
|
|
199
|
+
error: err
|
|
200
|
+
})
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
CREATE TABLE TB_INSERT (
|
|
2
|
+
PK_ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
3
|
+
VL_PRECO INTEGER NOT NULL,
|
|
4
|
+
DS_OBS TEXT NULL
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
INSERT INTO TB_INSERT (VL_PRECO,DS_OBS) VALUES (1, 'A');
|
|
8
|
+
|
|
9
|
+
CREATE TABLE TB_UPDATE (
|
|
10
|
+
PK_ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11
|
+
VL_PRECO INTEGER NOT NULL,
|
|
12
|
+
DS_OBS TEXT NULL
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
INSERT INTO TB_UPDATE (VL_PRECO,DS_OBS) VALUES (1, 'A');
|
|
16
|
+
INSERT INTO TB_UPDATE (VL_PRECO,DS_OBS) VALUES (2, 'B');
|
|
17
|
+
|
|
18
|
+
CREATE TABLE TB_TRANSACTION_OKAY (
|
|
19
|
+
PK_ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
20
|
+
VL_PRECO INTEGER NOT NULL,
|
|
21
|
+
DS_OBS TEXT NULL
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
INSERT INTO TB_TRANSACTION_OKAY (VL_PRECO,DS_OBS) VALUES (1, 'A');
|
|
25
|
+
|
|
26
|
+
CREATE TABLE TB_TRANSACTION_NOKAY (
|
|
27
|
+
PK_ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
28
|
+
VL_PRECO INTEGER NOT NULL,
|
|
29
|
+
DS_OBS TEXT NULL
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
INSERT INTO TB_TRANSACTION_NOKAY (VL_PRECO,DS_OBS) VALUES (1, 'A');
|
|
33
|
+
|
|
34
|
+
CREATE TABLE TB_MULTIBANCO (
|
|
35
|
+
PK_ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
36
|
+
VL_PRECO INTEGER NOT NULL,
|
|
37
|
+
DS_OBS TEXT NULL
|
|
38
|
+
);
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { describe, it, after, before } from "node:test"
|
|
2
|
+
import assert from "node:assert"
|
|
3
|
+
import path from "node:path"
|
|
4
|
+
import fs from "node:fs"
|
|
5
|
+
import { PlataModels, PlataSql } from ".."
|
|
6
|
+
import { loadRuntimeLibs } from "../bin/runtime/_setupRuntime"
|
|
7
|
+
|
|
8
|
+
describe('PlataSql', () => {
|
|
9
|
+
const originalDatabasePath = path.join(__dirname, 'assets', 'sql', 'example.db')
|
|
10
|
+
const tmpDatabasePath = path.join(__dirname, 'assets', 'sql', 'example.dummy.db')
|
|
11
|
+
const tmpAuxDatabasePath = path.join(__dirname, 'assets', 'sql', 'aux.dummy.db')
|
|
12
|
+
|
|
13
|
+
let sql: PlataSql.Driver<false>
|
|
14
|
+
let aux: PlataSql.Driver<false>
|
|
15
|
+
|
|
16
|
+
fs.rmSync(tmpDatabasePath, {
|
|
17
|
+
force: true,
|
|
18
|
+
recursive: false,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
fs.rmSync(tmpAuxDatabasePath, {
|
|
22
|
+
force: true,
|
|
23
|
+
recursive: false,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const plataPromise = (async () => {
|
|
27
|
+
const g = global as any
|
|
28
|
+
|
|
29
|
+
g.Plata = await loadRuntimeLibs()
|
|
30
|
+
g.Plata.config = new Object(null)
|
|
31
|
+
})()
|
|
32
|
+
|
|
33
|
+
const modelSql = new PlataModels.ModelTemplate({
|
|
34
|
+
PK_ID: [ PlataModels.Required(), PlataModels.Int() ],
|
|
35
|
+
VL_PRECO: [ PlataModels.Required(), PlataModels.Int() ],
|
|
36
|
+
DS_OBS: [ PlataModels.Required(), PlataModels.VarChar(Infinity) ]
|
|
37
|
+
} as const, {} as const)
|
|
38
|
+
|
|
39
|
+
const getSqlite3 = async () => {
|
|
40
|
+
await plataPromise
|
|
41
|
+
if (!fs.existsSync(tmpDatabasePath)) {
|
|
42
|
+
fs.copyFileSync(originalDatabasePath, tmpDatabasePath)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return new PlataSql.Driver({
|
|
46
|
+
client: 'sqlite3',
|
|
47
|
+
connection: {
|
|
48
|
+
filename: tmpDatabasePath
|
|
49
|
+
}
|
|
50
|
+
}, false)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getSqlite3Aux = async () => {
|
|
54
|
+
await plataPromise
|
|
55
|
+
if (!fs.existsSync(tmpAuxDatabasePath)) {
|
|
56
|
+
fs.copyFileSync(originalDatabasePath, tmpAuxDatabasePath)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return new PlataSql.Driver({
|
|
60
|
+
client: 'sqlite3',
|
|
61
|
+
connection: {
|
|
62
|
+
filename: tmpAuxDatabasePath
|
|
63
|
+
}
|
|
64
|
+
}, false)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
before(async () => {
|
|
68
|
+
sql = await getSqlite3()
|
|
69
|
+
aux = await getSqlite3Aux()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('Insert', async () => {
|
|
73
|
+
const tabela = 'TB_INSERT'
|
|
74
|
+
|
|
75
|
+
const antes = await sql.select(tabela, modelSql).build(
|
|
76
|
+
s => s
|
|
77
|
+
).toListAsync()
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(antes.errorID, undefined)
|
|
80
|
+
assert.strictEqual(antes.errors, undefined)
|
|
81
|
+
|
|
82
|
+
const insert = await sql.insert(tabela, modelSql, [{
|
|
83
|
+
VL_PRECO: 2,
|
|
84
|
+
DS_OBS: 'B'
|
|
85
|
+
}])
|
|
86
|
+
|
|
87
|
+
assert.strictEqual(insert.errorID, undefined)
|
|
88
|
+
assert.strictEqual(insert.length, 1)
|
|
89
|
+
|
|
90
|
+
const depois = await sql.select(tabela, modelSql).build(
|
|
91
|
+
s => s
|
|
92
|
+
).toListAsync()
|
|
93
|
+
|
|
94
|
+
assert.strictEqual(depois.errorID, undefined)
|
|
95
|
+
assert.strictEqual(depois.errors, undefined)
|
|
96
|
+
|
|
97
|
+
const esperado = [...antes.itens, ...insert]
|
|
98
|
+
|
|
99
|
+
for (let i = 0; i < depois.itens.length; i++) {
|
|
100
|
+
assert.deepStrictEqual(depois.itens[i], esperado[i])
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('Update', async () => {
|
|
105
|
+
const tabela = 'TB_UPDATE'
|
|
106
|
+
|
|
107
|
+
const antes = await sql.select(tabela, modelSql).build(
|
|
108
|
+
s => s
|
|
109
|
+
).toListAsync()
|
|
110
|
+
|
|
111
|
+
assert.strictEqual(antes.errorID, undefined)
|
|
112
|
+
assert.strictEqual(antes.errors, undefined)
|
|
113
|
+
|
|
114
|
+
const update = await sql.update(tabela, modelSql).build(
|
|
115
|
+
s => s.where('PK_ID', 1), {
|
|
116
|
+
VL_PRECO: 3,
|
|
117
|
+
DS_OBS: 'C'
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
assert.strictEqual(update.errorID, undefined)
|
|
122
|
+
assert.strictEqual(update, 1)
|
|
123
|
+
|
|
124
|
+
const depois = await sql.select(tabela, modelSql).build(
|
|
125
|
+
s => s
|
|
126
|
+
).toListAsync()
|
|
127
|
+
|
|
128
|
+
assert.strictEqual(depois.errorID, undefined)
|
|
129
|
+
assert.strictEqual(depois.errors, undefined)
|
|
130
|
+
|
|
131
|
+
const alterado = depois.itens.filter(d => d.PK_ID === 1)
|
|
132
|
+
|
|
133
|
+
assert.strictEqual(alterado.length, 1)
|
|
134
|
+
|
|
135
|
+
assert.strictEqual(alterado[0].DS_OBS, 'C')
|
|
136
|
+
assert.strictEqual(alterado[0].VL_PRECO, 3)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('Transaction Okay', async () => {
|
|
140
|
+
const tabela = 'TB_TRANSACTION_OKAY'
|
|
141
|
+
|
|
142
|
+
const antes = await sql.select(tabela, modelSql).build(
|
|
143
|
+
s => s
|
|
144
|
+
).toListAsync()
|
|
145
|
+
|
|
146
|
+
assert.strictEqual(antes.errorID, undefined)
|
|
147
|
+
assert.strictEqual(antes.errors, undefined)
|
|
148
|
+
|
|
149
|
+
const error = await sql.trasation(async trx => {
|
|
150
|
+
const insert = await trx.insert(tabela, modelSql, [{
|
|
151
|
+
DS_OBS: 'B',
|
|
152
|
+
VL_PRECO: 2
|
|
153
|
+
}])
|
|
154
|
+
|
|
155
|
+
assert.strictEqual(insert.errorID, undefined)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
assert.strictEqual(error, undefined)
|
|
159
|
+
|
|
160
|
+
const depois = await sql.select(tabela, modelSql).build(
|
|
161
|
+
s => s
|
|
162
|
+
).toListAsync()
|
|
163
|
+
|
|
164
|
+
assert.strictEqual(depois.errorID, undefined)
|
|
165
|
+
assert.strictEqual(depois.errors, undefined)
|
|
166
|
+
|
|
167
|
+
assert.strictEqual(depois.itens.length, antes.itens.length + 1)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('Transaction Não Okay', async () => {
|
|
171
|
+
const tabela = 'TB_TRANSACTION_NOKAY'
|
|
172
|
+
|
|
173
|
+
const antes = await sql.select(tabela, modelSql).build(
|
|
174
|
+
s => s
|
|
175
|
+
).toListAsync()
|
|
176
|
+
|
|
177
|
+
assert.strictEqual(antes.errorID, undefined)
|
|
178
|
+
assert.strictEqual(antes.errors, undefined)
|
|
179
|
+
|
|
180
|
+
const error = await sql.trasation(async trx => {
|
|
181
|
+
const insert = await trx.insert(tabela, modelSql, [{
|
|
182
|
+
DS_OBS: 'B',
|
|
183
|
+
VL_PRECO: 2
|
|
184
|
+
}])
|
|
185
|
+
|
|
186
|
+
assert.strictEqual(insert.errorID, undefined)
|
|
187
|
+
throw Plata.BuildPlataError({
|
|
188
|
+
errorID: 'PTSQLTRX001',
|
|
189
|
+
msg: 'Erro esperado'
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
assert.notStrictEqual(error, undefined)
|
|
194
|
+
|
|
195
|
+
const depois = await sql.select(tabela, modelSql).build(
|
|
196
|
+
s => s
|
|
197
|
+
).toListAsync()
|
|
198
|
+
|
|
199
|
+
assert.strictEqual(depois.errorID, undefined)
|
|
200
|
+
assert.strictEqual(depois.errors, undefined)
|
|
201
|
+
|
|
202
|
+
assert.strictEqual(depois.itens.length, antes.itens.length)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('MultiBanco', async () => {
|
|
206
|
+
const tabela = 'TB_MULTIBANCO'
|
|
207
|
+
|
|
208
|
+
const sqlInsertPromise = Plata.FastPromise(() => sql.insert(tabela, modelSql, [
|
|
209
|
+
{
|
|
210
|
+
VL_PRECO: 1,
|
|
211
|
+
DS_OBS: 'A'
|
|
212
|
+
}
|
|
213
|
+
]))
|
|
214
|
+
|
|
215
|
+
const auxInsertPromise = Plata.FastPromise(() => aux.insert(tabela, modelSql, [
|
|
216
|
+
{
|
|
217
|
+
VL_PRECO: 2,
|
|
218
|
+
DS_OBS: 'B'
|
|
219
|
+
}
|
|
220
|
+
]))
|
|
221
|
+
|
|
222
|
+
const [ sqlResult, auxResult ] = await Promise.all([ sqlInsertPromise, auxInsertPromise ])
|
|
223
|
+
|
|
224
|
+
assert.strictEqual(sqlResult.errorID, undefined)
|
|
225
|
+
assert.strictEqual(auxResult.errorID, undefined)
|
|
226
|
+
|
|
227
|
+
const sqlSelectPromise = sql.select(tabela, modelSql).build(
|
|
228
|
+
s => s
|
|
229
|
+
).toListAsync()
|
|
230
|
+
|
|
231
|
+
const auxSelectPromise = aux.select(tabela, modelSql).build(
|
|
232
|
+
s => s
|
|
233
|
+
).toListAsync()
|
|
234
|
+
|
|
235
|
+
const [ sqlSelect, auxSelect ] = await Promise.all([ sqlSelectPromise , auxSelectPromise ])
|
|
236
|
+
|
|
237
|
+
assert.strictEqual(sqlSelect.errorID, undefined)
|
|
238
|
+
assert.strictEqual(sqlSelect.errors, undefined)
|
|
239
|
+
|
|
240
|
+
assert.strictEqual(auxSelect.errorID, undefined)
|
|
241
|
+
assert.strictEqual(auxSelect.errors, undefined)
|
|
242
|
+
|
|
243
|
+
assert.strictEqual(sqlSelect.itens.length, 1)
|
|
244
|
+
assert.strictEqual(auxSelect.itens.length, 1)
|
|
245
|
+
|
|
246
|
+
assert.strictEqual(sqlSelect.itens[0].VL_PRECO, 1)
|
|
247
|
+
assert.strictEqual(sqlSelect.itens[0].DS_OBS, 'A')
|
|
248
|
+
|
|
249
|
+
assert.strictEqual(auxSelect.itens[0].VL_PRECO, 2)
|
|
250
|
+
assert.strictEqual(auxSelect.itens[0].DS_OBS, 'B')
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
after(async () => { // Requerido para Sqlite3
|
|
254
|
+
const sqlError = await sql.conn.destroy().then(
|
|
255
|
+
() => undefined,
|
|
256
|
+
err => err
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
const auxError = await aux.conn.destroy().then(
|
|
260
|
+
() => undefined,
|
|
261
|
+
err => err
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
assert.strictEqual(sqlError, undefined)
|
|
265
|
+
assert.strictEqual(auxError, undefined)
|
|
266
|
+
})
|
|
267
|
+
})
|