@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.js
CHANGED
|
@@ -258,7 +258,7 @@ var import_crypto = require("crypto");
|
|
|
258
258
|
var express = __toESM(require("express"));
|
|
259
259
|
var import_fs3 = __toESM(require("fs"));
|
|
260
260
|
var import_path3 = __toESM(require("path"));
|
|
261
|
-
var
|
|
261
|
+
var import_pg2 = __toESM(require("pg"));
|
|
262
262
|
var prettier3 = __toESM(require("prettier"));
|
|
263
263
|
|
|
264
264
|
// src/restura/sql/SqlUtils.ts
|
|
@@ -1570,7 +1570,7 @@ var filterPsqlParser_default = filterPsqlParser;
|
|
|
1570
1570
|
// src/restura/sql/PsqlEngine.ts
|
|
1571
1571
|
var import_pg_diff_sync = __toESM(require("@wmfs/pg-diff-sync"));
|
|
1572
1572
|
var import_pg_info = __toESM(require("@wmfs/pg-info"));
|
|
1573
|
-
var
|
|
1573
|
+
var { Client } = "pg";
|
|
1574
1574
|
var systemUser = {
|
|
1575
1575
|
role: "",
|
|
1576
1576
|
host: "",
|
|
@@ -1688,14 +1688,14 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1688
1688
|
async diffDatabaseToSchema(schema) {
|
|
1689
1689
|
const scratchPool = await this.getScratchPool();
|
|
1690
1690
|
await this.createDatabaseFromSchema(schema, scratchPool);
|
|
1691
|
-
const originalClient = new
|
|
1691
|
+
const originalClient = new Client({
|
|
1692
1692
|
database: this.psqlConnectionPool.poolConfig.database,
|
|
1693
1693
|
user: this.psqlConnectionPool.poolConfig.user,
|
|
1694
1694
|
password: this.psqlConnectionPool.poolConfig.password,
|
|
1695
1695
|
host: this.psqlConnectionPool.poolConfig.host,
|
|
1696
1696
|
port: this.psqlConnectionPool.poolConfig.port
|
|
1697
1697
|
});
|
|
1698
|
-
const scratchClient = new
|
|
1698
|
+
const scratchClient = new Client({
|
|
1699
1699
|
database: this.psqlConnectionPool.poolConfig.database + "_scratch",
|
|
1700
1700
|
user: this.psqlConnectionPool.poolConfig.user,
|
|
1701
1701
|
password: this.psqlConnectionPool.poolConfig.password,
|
|
@@ -1827,22 +1827,20 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1827
1827
|
);
|
|
1828
1828
|
} else if (routeData.type === "PAGED") {
|
|
1829
1829
|
const data = req.data;
|
|
1830
|
-
const
|
|
1831
|
-
`${selectStatement}${sqlStatement}${groupByOrderByStatement} LIMIT
|
|
1832
|
-
|
|
1833
|
-
[
|
|
1834
|
-
...sqlParams,
|
|
1835
|
-
data.perPage || DEFAULT_PAGED_PER_PAGE_NUMBER,
|
|
1836
|
-
(data.page - 1) * data.perPage || DEFAULT_PAGED_PAGE_NUMBER,
|
|
1837
|
-
...sqlParams
|
|
1838
|
-
],
|
|
1830
|
+
const pagePromise = this.psqlConnectionPool.runQuery(
|
|
1831
|
+
`${selectStatement}${sqlStatement}${groupByOrderByStatement}` + SQL`LIMIT ${data.perPage || DEFAULT_PAGED_PER_PAGE_NUMBER} OFFSET ${(data.page - 1) * data.perPage || DEFAULT_PAGED_PAGE_NUMBER};`,
|
|
1832
|
+
sqlParams,
|
|
1839
1833
|
req.requesterDetails
|
|
1840
1834
|
);
|
|
1835
|
+
const totalQuery = `SELECT COUNT(${routeData.groupBy ? `DISTINCT ${routeData.groupBy.tableName}.${routeData.groupBy.columnName}` : "*"}) AS total
|
|
1836
|
+
${sqlStatement};`;
|
|
1837
|
+
const totalPromise = await this.psqlConnectionPool.runQuery(totalQuery, sqlParams, req.requesterDetails);
|
|
1838
|
+
const [pageResults, totalResponse] = await Promise.all([pagePromise, totalPromise]);
|
|
1841
1839
|
let total = 0;
|
|
1842
|
-
if (import_core_utils5.ObjectUtils.isArrayWithData(
|
|
1843
|
-
total =
|
|
1840
|
+
if (import_core_utils5.ObjectUtils.isArrayWithData(totalResponse)) {
|
|
1841
|
+
total = totalResponse[0].total;
|
|
1844
1842
|
}
|
|
1845
|
-
return { data: pageResults
|
|
1843
|
+
return { data: pageResults, total };
|
|
1846
1844
|
} else {
|
|
1847
1845
|
throw new RsError("UNKNOWN_ERROR", "Unknown route type.");
|
|
1848
1846
|
}
|
|
@@ -2001,7 +1999,7 @@ var schemaToPsqlType = (column, tableName) => {
|
|
|
2001
1999
|
};
|
|
2002
2000
|
|
|
2003
2001
|
// src/restura/restura.ts
|
|
2004
|
-
var { types } =
|
|
2002
|
+
var { types } = import_pg2.default;
|
|
2005
2003
|
var ResturaEngine = class {
|
|
2006
2004
|
constructor() {
|
|
2007
2005
|
this.publicEndpoints = {
|