@voxpelli/pg-utils 1.1.2 → 2.0.0

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.
@@ -72,7 +72,7 @@ export async function csvFromFolderToDb (connection, path, tablesWithDependencie
72
72
 
73
73
  for (const file of files) {
74
74
  const name = pathModule.basename(file, '.csv');
75
- const dbCopy = client.query(copyFrom(`COPY ${name} FROM STDIN DELIMITER ',' CSV HEADER`));
75
+ const dbCopy = client.query(copyFrom(`COPY ${name} FROM STDIN WITH (FORMAT csv, HEADER MATCH)`));
76
76
 
77
77
  // eslint-disable-next-line security/detect-non-literal-fs-filename
78
78
  const csvContent = createReadStream(file);
@@ -9,7 +9,7 @@ export class PgTestHelpers {
9
9
  export type PgTestHelpersOptions = {
10
10
  connectionString: string;
11
11
  fixtureFolder?: string | URL;
12
- schema: string | URL | import("umzug").Umzug<import("umzeption").UmzeptionContext<"pg", import("umzeption").FastifyPostgresStyleDb>>;
12
+ schema: string | URL | (() => import("umzug").Umzug<import("umzeption").UmzeptionContext<"pg", import("umzeption").FastifyPostgresStyleDb>>);
13
13
  tablesWithDependencies?: Array<string[] | string>;
14
14
  };
15
15
  import type { Pool } from 'pg';
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAoBA;IAaE,qBADY,oBAAoB,EAiC/B;IAnCD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAoEb,cADc,OAAO,CAAC,IAAI,CAAC,CAiB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;;CACF;;sBArHa,MAAM;oBACN,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC;6BAC5H,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAoBA;IAaE,qBADY,oBAAoB,EAiC/B;IAnCD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAoEb,cADc,OAAO,CAAC,IAAI,CAAC,CAiB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;;CACF;;sBArHa,MAAM;oBACN,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC;6BACpI,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
@@ -14,7 +14,7 @@ import { createPgPool, isStringArray, TypeNeverError } from './utils.js';
14
14
  * @typedef PgTestHelpersOptions
15
15
  * @property {string} connectionString
16
16
  * @property {string | URL} [fixtureFolder]
17
- * @property {string | URL | import('umzug').Umzug<import('umzeption').UmzeptionContext<'pg', import('umzeption').FastifyPostgresStyleDb>>} schema
17
+ * @property {string | URL | (() => import('umzug').Umzug<import('umzeption').UmzeptionContext<'pg', import('umzeption').FastifyPostgresStyleDb>>)} schema
18
18
  * @property {Array<string[] | string>} [tablesWithDependencies]
19
19
  */
20
20
 
@@ -49,8 +49,8 @@ export class PgTestHelpers {
49
49
  if (fixtureFolder && typeof fixtureFolder !== 'string' && !(fixtureFolder instanceof URL)) {
50
50
  throw new TypeNeverError(fixtureFolder, 'Invalid fixtureFolder, expected a string');
51
51
  }
52
- if (typeof schema !== 'string' && typeof schema !== 'object') {
53
- throw new TypeNeverError(schema, 'Invalid schema, expected a string or an object');
52
+ if (typeof schema !== 'string' && typeof schema !== 'object' && typeof schema !== 'function') {
53
+ throw new TypeNeverError(schema, 'Invalid schema, expected a string, object or function');
54
54
  }
55
55
  if (tablesWithDependencies && !Array.isArray(tablesWithDependencies)) {
56
56
  throw new TypeNeverError(tablesWithDependencies, 'Invalid tablesWithDependencies, expected an array');
@@ -88,8 +88,8 @@ export class PgTestHelpers {
88
88
  Array.isArray(name)
89
89
  ? this.#removeTablesByName(name)
90
90
  : this.queryPromise('DROP TABLE IF EXISTS ' + name + ' CASCADE').catch(cause => {
91
- throw new Error(`Failed to drop table: ${name}`, { cause });
92
- })
91
+ throw new Error(`Failed to drop table: ${name}`, { cause });
92
+ })
93
93
  );
94
94
  }
95
95
  }
@@ -98,8 +98,8 @@ export class PgTestHelpers {
98
98
  /** @returns {Promise<void>} */
99
99
  async initTables () {
100
100
  try {
101
- if (typeof this.#schema === 'object' && 'up' in this.#schema) {
102
- await this.#schema.up();
101
+ if (typeof this.#schema === 'function') {
102
+ await this.#schema().up();
103
103
  return;
104
104
  }
105
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxpelli/pg-utils",
3
- "version": "1.1.2",
3
+ "version": "2.0.0",
4
4
  "description": " My personal database utils / helpers for Postgres",
5
5
  "homepage": "http://github.com/voxpelli/pg-utils",
6
6
  "repository": {
@@ -47,22 +47,22 @@
47
47
  "@types/chai": "^4.3.20",
48
48
  "@types/chai-as-promised": "^7.1.8",
49
49
  "@types/mocha": "^10.0.10",
50
- "@types/node": "^20.17.9",
50
+ "@types/node": "^20.17.17",
51
51
  "@types/pg-copy-streams": "^1.2.5",
52
52
  "@voxpelli/eslint-config": "^22.2.0",
53
- "@voxpelli/tsconfig": "^15.1.0",
54
- "c8": "^10.1.2",
53
+ "@voxpelli/tsconfig": "^15.1.1",
54
+ "c8": "^10.1.3",
55
55
  "chai": "^4.5.0",
56
56
  "chai-as-promised": "^7.1.2",
57
- "dotenv": "^16.4.6",
58
- "eslint": "^9.16.0",
57
+ "dotenv": "^16.4.7",
58
+ "eslint": "^9.19.0",
59
59
  "husky": "^9.1.7",
60
60
  "installed-check": "^9.3.0",
61
- "knip": "^5.38.4",
62
- "mocha": "^10.8.2",
63
- "npm-run-all2": "^7.0.1",
61
+ "knip": "^5.43.6",
62
+ "mocha": "^11.1.0",
63
+ "npm-run-all2": "^7.0.2",
64
64
  "type-coverage": "^2.29.7",
65
- "typescript": "~5.7.2",
65
+ "typescript": "~5.7.3",
66
66
  "validate-conventional-commit": "^1.0.4"
67
67
  },
68
68
  "dependencies": {