sedentary-pg 0.0.39 → 0.0.40

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/cjs/pgdb.js CHANGED
@@ -86,15 +86,16 @@ class PGDB extends sedentary_1.DB {
86
86
  }
87
87
  load(tableName, attributes, pk, model, table) {
88
88
  const pkFldName = pk.fieldName;
89
- return async (where, order, tx, lock) => {
89
+ return async (where, order, limit, tx, lock) => {
90
90
  const { oid } = table;
91
91
  const ret = [];
92
92
  const client = tx ? tx._client : await this.pool.connect();
93
93
  const oidPK = {};
94
94
  try {
95
95
  const forUpdate = lock ? " FOR UPDATE" : "";
96
- const orderBy = order && order.length ? ` ORDER BY ${order.map(_ => (_.startsWith("-") ? `${_.substring(1)} DESC` : _)).join(",")}` : "";
97
- const query = `SELECT *, tableoid FROM ${tableName}${where ? ` WHERE ${where}` : ""}${orderBy}${forUpdate}`;
96
+ const orderBy = order && order.length ? ` ORDER BY ${(typeof order === "string" ? [order] : order).map(_ => (_.startsWith("-") ? `${_.substring(1)} DESC` : _)).join(",")}` : "";
97
+ const limitTo = typeof limit === "number" ? ` LIMIT ${limit}` : "";
98
+ const query = `SELECT *, tableoid FROM ${tableName}${where ? ` WHERE ${where}` : ""}${orderBy}${limitTo}${forUpdate}`;
98
99
  this.log(query);
99
100
  const res = await client.query(query);
100
101
  for (const row of res.rows) {
package/dist/es/pgdb.js CHANGED
@@ -81,15 +81,16 @@ export class PGDB extends DB {
81
81
  }
82
82
  load(tableName, attributes, pk, model, table) {
83
83
  const pkFldName = pk.fieldName;
84
- return async (where, order, tx, lock) => {
84
+ return async (where, order, limit, tx, lock) => {
85
85
  const { oid } = table;
86
86
  const ret = [];
87
87
  const client = tx ? tx._client : await this.pool.connect();
88
88
  const oidPK = {};
89
89
  try {
90
90
  const forUpdate = lock ? " FOR UPDATE" : "";
91
- const orderBy = order && order.length ? ` ORDER BY ${order.map(_ => (_.startsWith("-") ? `${_.substring(1)} DESC` : _)).join(",")}` : "";
92
- const query = `SELECT *, tableoid FROM ${tableName}${where ? ` WHERE ${where}` : ""}${orderBy}${forUpdate}`;
91
+ const orderBy = order && order.length ? ` ORDER BY ${(typeof order === "string" ? [order] : order).map(_ => (_.startsWith("-") ? `${_.substring(1)} DESC` : _)).join(",")}` : "";
92
+ const limitTo = typeof limit === "number" ? ` LIMIT ${limit}` : "";
93
+ const query = `SELECT *, tableoid FROM ${tableName}${where ? ` WHERE ${where}` : ""}${orderBy}${limitTo}${forUpdate}`;
93
94
  this.log(query);
94
95
  const res = await client.query(query);
95
96
  for (const row of res.rows) {
@@ -15,7 +15,7 @@ export declare class PGDB extends DB<TransactionPG> {
15
15
  client(): Promise<PoolClient>;
16
16
  escape(value: Natural): string;
17
17
  fill(attributes: Record<string, string>, row: Record<string, Natural>, entry: Record<string, Natural>): void;
18
- load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new (from: "load") => EntryBase, table: Table): (where: string, order?: string[], tx?: Transaction) => Promise<EntryBase[]>;
18
+ load(tableName: string, attributes: Record<string, string>, pk: Attribute<Natural, unknown>, model: new (from: "load") => EntryBase, table: Table): (where: string, order?: string | string[], limit?: number, tx?: Transaction) => Promise<EntryBase[]>;
19
19
  remove(tableName: string, pk: Attribute<Natural, unknown>): (this: Record<string, Natural> & {
20
20
  tx?: TransactionPG;
21
21
  }) => Promise<boolean>;
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ collectCoverageFrom: ["index.ts", "pgdb.ts"],
4
+ preset: "ts-jest",
5
+ testEnvironment: "jest-environment-node-single-context",
6
+ testPathIgnorePatterns: ["/node_modules/"],
7
+ testSequencer: "../testSequencer.js"
8
+ };
package/package.json CHANGED
@@ -9,20 +9,21 @@
9
9
  "@types/pg": "8.6.5",
10
10
  "pg": "8.7.3",
11
11
  "pg-format": "1.0.4",
12
- "sedentary": "0.0.39"
12
+ "sedentary": "0.0.40"
13
13
  },
14
14
  "description": "The ORM which never needs to migrate - PostgreSQL",
15
15
  "devDependencies": {
16
- "@types/mocha": "9.1.1",
16
+ "@types/jest": "28.1.3",
17
17
  "@types/node": "18.0.0",
18
18
  "@types/pg-format": "1.0.2",
19
19
  "@types/yamljs": "0.2.31",
20
20
  "@typescript-eslint/eslint-plugin": "5.30.0",
21
21
  "@typescript-eslint/parser": "5.30.0",
22
22
  "eslint": "8.18.0",
23
- "mocha": "10.0.0",
24
- "nyc": "15.1.0",
23
+ "jest": "28.1.1",
24
+ "jest-environment-node-single-context": "28.0.0",
25
25
  "prettier": "2.7.1",
26
+ "ts-jest": "28.0.5",
26
27
  "ts-node": "10.8.1",
27
28
  "typescript": "4.7.4",
28
29
  "yamljs": "0.3.0"
@@ -58,11 +59,11 @@
58
59
  "readmeFilename": "README.md",
59
60
  "repository": "https://github.com/iccicci/sedentary-pg",
60
61
  "scripts": {
61
- "coverage": "nyc -r lcov -r text -r text-summary -r html mocha -r ts-node/register test/*ts",
62
+ "coverage": "jest --coverage --runInBand",
62
63
  "gitignore": "node -r ts-node/register utils.ts gitignore",
63
64
  "npmignore": "node -r ts-node/register utils.ts npmignore",
64
65
  "packagejson": "node -r ts-node/register utils.ts packagejson",
65
- "test": "mocha -r ts-node/register test/*ts",
66
+ "test": "jest --runInBand --verbose",
66
67
  "travis": "node -r ts-node/register utils.ts travis",
67
68
  "tsc": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.es.json && tsc -p tsconfig.types.json",
68
69
  "version": "node -r ts-node/register utils.ts version"
@@ -84,5 +85,5 @@
84
85
  }
85
86
  },
86
87
  "types": "./dist/types/index.d.ts",
87
- "version": "0.0.39"
88
+ "version": "0.0.40"
88
89
  }