@dascompany/database 4.2.1 → 4.2.3
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/dist/Connection.d.ts +1 -0
- package/dist/Connection.js +6 -2
- package/dist/query/QueryOptions.d.ts +2 -0
- package/dist/query/QueryOptions.js +15 -1
- package/dist/types/ConnectorE.d.ts +2 -0
- package/dist/types/ConnectorE.js +10 -0
- package/dist/types/QueryOptionsConfig.d.ts +13 -0
- package/dist/types/QueryOptionsConfig.js +1 -0
- package/package.json +1 -1
package/dist/Connection.d.ts
CHANGED
package/dist/Connection.js
CHANGED
|
@@ -10,13 +10,14 @@ export default class Connection {
|
|
|
10
10
|
}
|
|
11
11
|
async beginTransaction() {
|
|
12
12
|
await this.poolClient.query('BEGIN');
|
|
13
|
+
this.activeTransaction = true;
|
|
13
14
|
}
|
|
14
15
|
async commitTransaction() {
|
|
15
16
|
if (!this.activeTransaction) {
|
|
16
17
|
throw new Error('No active transaction to commit');
|
|
17
18
|
}
|
|
18
19
|
await this.poolClient.query('COMMIT');
|
|
19
|
-
this.
|
|
20
|
+
this.release();
|
|
20
21
|
this.activeTransaction = false;
|
|
21
22
|
}
|
|
22
23
|
async rollBackTransaction() {
|
|
@@ -24,7 +25,10 @@ export default class Connection {
|
|
|
24
25
|
throw new Error('No active transaction to roll back');
|
|
25
26
|
}
|
|
26
27
|
await this.poolClient.query('ROLLBACK');
|
|
27
|
-
this.
|
|
28
|
+
this.release();
|
|
28
29
|
this.activeTransaction = false;
|
|
29
30
|
}
|
|
31
|
+
release() {
|
|
32
|
+
this.poolClient.release();
|
|
33
|
+
}
|
|
30
34
|
}
|
|
@@ -3,11 +3,13 @@ import OrderByI from "../types/OrderByI";
|
|
|
3
3
|
import WhereOptionI from "../types/WhereOptionI";
|
|
4
4
|
import ParameterI from "../types/ParameterI";
|
|
5
5
|
import ConnectorE from "../types/ConnectorE";
|
|
6
|
+
import QueryOptionsI from "../types/QueryOptionsI";
|
|
6
7
|
export default class QueryOptions {
|
|
7
8
|
private where;
|
|
8
9
|
private orderBy;
|
|
9
10
|
private limit;
|
|
10
11
|
constructor();
|
|
12
|
+
static create(data: QueryOptionsI): QueryOptions;
|
|
11
13
|
getWhere(): WhereOptionI | null;
|
|
12
14
|
getOrderBy(): OrderByI[] | null;
|
|
13
15
|
getLimit(): ResultLimitationI | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ConnectorE from "../types/ConnectorE";
|
|
1
|
+
import ConnectorE, { getFromValue } from "../types/ConnectorE";
|
|
2
2
|
export default class QueryOptions {
|
|
3
3
|
where;
|
|
4
4
|
orderBy;
|
|
@@ -8,6 +8,20 @@ export default class QueryOptions {
|
|
|
8
8
|
this.orderBy = null;
|
|
9
9
|
this.limit = null;
|
|
10
10
|
}
|
|
11
|
+
static create(data) {
|
|
12
|
+
const queryOptions = new QueryOptions();
|
|
13
|
+
if (data.where) {
|
|
14
|
+
const connector = data.where.connector ? getFromValue(data.where.connector) : ConnectorE.and;
|
|
15
|
+
queryOptions.setWhere(data.where.parameters, connector);
|
|
16
|
+
}
|
|
17
|
+
if (data.orderBy) {
|
|
18
|
+
queryOptions.setOrderBy(data.orderBy);
|
|
19
|
+
}
|
|
20
|
+
if (data.limit) {
|
|
21
|
+
queryOptions.setLimit(data.limit.limit, data.limit.offset);
|
|
22
|
+
}
|
|
23
|
+
return queryOptions;
|
|
24
|
+
}
|
|
11
25
|
getWhere() {
|
|
12
26
|
return this.where;
|
|
13
27
|
}
|
package/dist/types/ConnectorE.js
CHANGED
|
@@ -3,4 +3,14 @@ var ConnectorE;
|
|
|
3
3
|
ConnectorE["or"] = "OR ";
|
|
4
4
|
ConnectorE["and"] = "AND ";
|
|
5
5
|
})(ConnectorE || (ConnectorE = {}));
|
|
6
|
+
function getFromValue(value) {
|
|
7
|
+
switch (value) {
|
|
8
|
+
case "OR ":
|
|
9
|
+
return ConnectorE.or;
|
|
10
|
+
case "AND ":
|
|
11
|
+
default:
|
|
12
|
+
return ConnectorE.and;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
6
15
|
export default ConnectorE;
|
|
16
|
+
export { getFromValue };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import OrderByI from "./OrderByI";
|
|
2
|
+
import ParameterI from "./ParameterI";
|
|
3
|
+
export default interface QueryOptionsConfig {
|
|
4
|
+
where: {
|
|
5
|
+
connector: string;
|
|
6
|
+
parameters: ParameterI[];
|
|
7
|
+
};
|
|
8
|
+
orderBy: OrderByI[];
|
|
9
|
+
limit: {
|
|
10
|
+
limit: number;
|
|
11
|
+
offset: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|