@dascompany/database 2.1.5 → 3.0.1

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/Table.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import Connection from './Connection';
2
2
  import Query from './query/Query';
3
- import QueryOptionsI from './types/QueryOptionsI';
3
+ import QueryOptions from './query/QueryOptions';
4
4
  export default abstract class Table {
5
5
  private connection;
6
6
  constructor(connection: Connection);
7
- createQuery(queryString: string, options?: QueryOptionsI): Query;
7
+ createQuery(queryString: string, options?: QueryOptions): Query;
8
8
  }
@@ -1,7 +1,7 @@
1
- import QueryOptionsI from "../types/QueryOptionsI";
2
1
  import Query from "./Query";
2
+ import QueryOptions from "./QueryOptions";
3
3
  export default class BindParams {
4
- static bindParams(query: Query, options: QueryOptionsI): void;
4
+ static bindParams(query: Query, options: QueryOptions): void;
5
5
  private static bindWhereParams;
6
6
  private static bindWhereParam;
7
7
  private static bindLimitParams;
@@ -2,10 +2,12 @@ import ParameterType from "../types/parameters/ParameterType";
2
2
  import QueryParamCreator from "./QueryParamCreator";
3
3
  export default class BindParams {
4
4
  static bindParams(query, options) {
5
- if (options?.where)
6
- BindParams.bindWhereParams(query, options.where.parameters);
7
- if (options?.limit)
8
- BindParams.bindLimitParams(query, options.limit);
5
+ const where = options.getWhere();
6
+ const limit = options.getLimit();
7
+ if (where)
8
+ BindParams.bindWhereParams(query, where.parameters);
9
+ if (limit)
10
+ BindParams.bindLimitParams(query, limit);
9
11
  }
10
12
  static bindWhereParams(query, parameters) {
11
13
  parameters.forEach((parameter) => {
@@ -1,6 +1,17 @@
1
1
  import ResultLimitationI from "../types/ResultLimitationI";
2
2
  import OrderByI from "../types/OrderByI";
3
+ import WhereOptionI from "../types/WhereOptionI";
4
+ import ParameterI from "../types/ParameterI";
5
+ import ConnectorE from "../types/ConnectorE";
3
6
  export default class QueryOptions {
4
- static correctingSorting(querySortBy: any): OrderByI[];
5
- static correctingLimitation(queryLimit: any, queryOffset: any): ResultLimitationI;
7
+ private where;
8
+ private orderBy;
9
+ private limit;
10
+ constructor();
11
+ getWhere(): WhereOptionI | null;
12
+ getOrderBy(): OrderByI[] | null;
13
+ getLimit(): ResultLimitationI | null;
14
+ setWhere(parameters: ParameterI[], connector?: ConnectorE): void;
15
+ setOrderBy(orderBy: OrderByI[]): void;
16
+ setLimit(limit: number, offset: number): void;
6
17
  }
@@ -1,23 +1,33 @@
1
- import ParameterType from "../types/parameters/ParameterType";
2
- import Filters from "../utils/Filters";
3
- import Parameters from "../utils/Parameters";
1
+ import ConnectorE from "../types/ConnectorE";
4
2
  export default class QueryOptions {
5
- static correctingSorting(querySortBy) {
6
- const orderBy = Parameters.correct(querySortBy, { type: ParameterType.arrayObject });
7
- const table = [];
8
- if (orderBy[0]) {
9
- orderBy.forEach((element) => {
10
- const key = Parameters.correct(element.key, { type: ParameterType.string, filter: Filters.databaseColumn });
11
- const order = Parameters.correct(element.order, { type: ParameterType.string });
12
- table.push({ key, order });
13
- });
14
- }
15
- return table;
3
+ where;
4
+ orderBy;
5
+ limit;
6
+ constructor() {
7
+ this.where = null;
8
+ this.orderBy = null;
9
+ this.limit = null;
16
10
  }
17
- static correctingLimitation(queryLimit, queryOffset) {
18
- const limit = Parameters.correct(queryLimit, { type: ParameterType.bigint });
19
- const offset = Parameters.correct(queryOffset, { type: ParameterType.bigint });
20
- return {
11
+ getWhere() {
12
+ return this.where;
13
+ }
14
+ getOrderBy() {
15
+ return this.orderBy;
16
+ }
17
+ getLimit() {
18
+ return this.limit;
19
+ }
20
+ setWhere(parameters, connector = ConnectorE.and) {
21
+ this.where = {
22
+ connector,
23
+ parameters
24
+ };
25
+ }
26
+ setOrderBy(orderBy) {
27
+ this.orderBy = orderBy;
28
+ }
29
+ setLimit(limit, offset) {
30
+ this.limit = {
21
31
  limit,
22
32
  offset
23
33
  };
@@ -1,6 +1,6 @@
1
- import QueryOptionsI from '../types/QueryOptionsI';
1
+ import QueryOptions from './QueryOptions';
2
2
  export default class QueryParams {
3
- static createParams(queryString: string, options: QueryOptionsI): string;
3
+ static createParams(queryString: string, options: QueryOptions): string;
4
4
  private static createWhereParams;
5
5
  private static createParamsSql;
6
6
  private static createOrderParams;
@@ -1,19 +1,24 @@
1
1
  import QueryParamsCreator from './QueryParamCreator';
2
2
  export default class QueryParams {
3
3
  static createParams(queryString, options) {
4
- if (options.where)
5
- queryString = QueryParams.createWhereParams(queryString, options.where);
6
- if (options.orderBy)
7
- queryString = QueryParams.createOrderParams(queryString, options.orderBy);
8
- if (options.limit)
9
- queryString += `LIMIT $limit::BIGINT OFFSET $offset::BIGINT`;
4
+ const where = options.getWhere();
5
+ const orderBy = options.getOrderBy();
6
+ const limit = options.getLimit();
7
+ if (where)
8
+ queryString = QueryParams.createWhereParams(queryString, where);
9
+ if (orderBy)
10
+ queryString = QueryParams.createOrderParams(queryString, orderBy);
11
+ if (limit)
12
+ queryString += ` LIMIT $limit::BIGINT OFFSET $offset::BIGINT`;
10
13
  return queryString;
11
14
  }
12
15
  static createWhereParams(sql, where) {
13
16
  const params = this.createParamsSql(where.parameters);
14
17
  const connector = 'WHERE';
15
- const sqlWithParams = `${sql} ${connector} ${params.join(` ${where.connector} `)}`;
16
- return sqlWithParams;
18
+ if (params.length > 0)
19
+ return `${sql} ${connector} ${params.join(` ${where.connector} `)}`;
20
+ else
21
+ return sql;
17
22
  }
18
23
  static createParamsSql(parameters) {
19
24
  let sqlParams = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "2.1.5",
3
+ "version": "3.0.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",