@restura/core 0.1.0-alpha.12 → 0.1.0-alpha.13
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/index.js +15 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1528,7 +1528,7 @@ var filterPsqlParser_default = filterPsqlParser;
|
|
|
1528
1528
|
// src/restura/sql/PsqlEngine.ts
|
|
1529
1529
|
import getDiff from "@wmfs/pg-diff-sync";
|
|
1530
1530
|
import pgInfo from "@wmfs/pg-info";
|
|
1531
|
-
|
|
1531
|
+
var { Client } = "pg";
|
|
1532
1532
|
var systemUser = {
|
|
1533
1533
|
role: "",
|
|
1534
1534
|
host: "",
|
|
@@ -1785,22 +1785,20 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1785
1785
|
);
|
|
1786
1786
|
} else if (routeData.type === "PAGED") {
|
|
1787
1787
|
const data = req.data;
|
|
1788
|
-
const
|
|
1789
|
-
`${selectStatement}${sqlStatement}${groupByOrderByStatement} LIMIT
|
|
1790
|
-
|
|
1791
|
-
[
|
|
1792
|
-
...sqlParams,
|
|
1793
|
-
data.perPage || DEFAULT_PAGED_PER_PAGE_NUMBER,
|
|
1794
|
-
(data.page - 1) * data.perPage || DEFAULT_PAGED_PAGE_NUMBER,
|
|
1795
|
-
...sqlParams
|
|
1796
|
-
],
|
|
1788
|
+
const pagePromise = this.psqlConnectionPool.runQuery(
|
|
1789
|
+
`${selectStatement}${sqlStatement}${groupByOrderByStatement}` + SQL`LIMIT ${data.perPage || DEFAULT_PAGED_PER_PAGE_NUMBER} OFFSET ${(data.page - 1) * data.perPage || DEFAULT_PAGED_PAGE_NUMBER};`,
|
|
1790
|
+
sqlParams,
|
|
1797
1791
|
req.requesterDetails
|
|
1798
1792
|
);
|
|
1793
|
+
const totalQuery = `SELECT COUNT(${routeData.groupBy ? `DISTINCT ${routeData.groupBy.tableName}.${routeData.groupBy.columnName}` : "*"}) AS total
|
|
1794
|
+
${sqlStatement};`;
|
|
1795
|
+
const totalPromise = await this.psqlConnectionPool.runQuery(totalQuery, sqlParams, req.requesterDetails);
|
|
1796
|
+
const [pageResults, totalResponse] = await Promise.all([pagePromise, totalPromise]);
|
|
1799
1797
|
let total = 0;
|
|
1800
|
-
if (ObjectUtils4.isArrayWithData(
|
|
1801
|
-
total =
|
|
1798
|
+
if (ObjectUtils4.isArrayWithData(totalResponse)) {
|
|
1799
|
+
total = totalResponse[0].total;
|
|
1802
1800
|
}
|
|
1803
|
-
return { data: pageResults
|
|
1801
|
+
return { data: pageResults, total };
|
|
1804
1802
|
} else {
|
|
1805
1803
|
throw new RsError("UNKNOWN_ERROR", "Unknown route type.");
|
|
1806
1804
|
}
|