@snowtop/ent 0.1.23 → 0.1.24

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/core/base.d.ts CHANGED
@@ -70,6 +70,7 @@ export interface SelectBaseDataOptions extends DataOptions {
70
70
  fields: string[];
71
71
  fieldsAlias?: string;
72
72
  disableFieldsAlias?: boolean;
73
+ disableDefaultOrderByAlias?: boolean;
73
74
  }
74
75
  export interface SelectDataOptions extends SelectBaseDataOptions {
75
76
  key: string;
@@ -2,6 +2,7 @@ import { QueryableDataOptions } from "./base";
2
2
  export interface OrderByOption {
3
3
  column: string;
4
4
  direction: "ASC" | "DESC";
5
+ alias?: string;
5
6
  nullsPlacement?: "first" | "last";
6
7
  dateColumn?: boolean;
7
8
  }
@@ -13,7 +13,8 @@ function getOrderByPhrase(orderby, alias) {
13
13
  nullsPlacement = " NULLS LAST";
14
14
  break;
15
15
  }
16
- const col = alias ? `${alias}.${v.column}` : v.column;
16
+ const orderByAlias = v.alias ?? alias;
17
+ const col = orderByAlias ? `${orderByAlias}.${v.column}` : v.column;
17
18
  return `${col} ${v.direction}${nullsPlacement}`;
18
19
  })
19
20
  .join(", ");
@@ -71,7 +72,7 @@ function buildQuery(options) {
71
72
  parts.push(`GROUP BY ${options.groupby}`);
72
73
  }
73
74
  if (options.orderby) {
74
- parts.push(`ORDER BY ${getOrderByPhrase(options.orderby, fieldsAlias)}`);
75
+ parts.push(`ORDER BY ${getOrderByPhrase(options.orderby, options.disableDefaultOrderByAlias ? undefined : fieldsAlias)}`);
75
76
  }
76
77
  if (options.limit) {
77
78
  parts.push(`LIMIT ${options.limit}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",