@dascompany/database 4.2.2 → 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.
@@ -10,6 +10,7 @@ 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) {
@@ -28,7 +29,6 @@ export default class Connection {
28
29
  this.activeTransaction = false;
29
30
  }
30
31
  release() {
31
- if (this.poolClient)
32
- this.poolClient.release();
32
+ this.poolClient.release();
33
33
  }
34
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
  }
@@ -2,4 +2,6 @@ declare enum ConnectorE {
2
2
  or = "OR ",
3
3
  and = "AND "
4
4
  }
5
+ declare function getFromValue(value: string): ConnectorE;
5
6
  export default ConnectorE;
7
+ export { getFromValue };
@@ -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 {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "4.2.2",
3
+ "version": "4.2.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {