@squiz/db-lib 1.2.1-alpha.99 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,86 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.2.2](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.2) (2022-09-23)
7
+
8
+ **Note:** Version bump only for package @squiz/db-lib
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.2.1](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1) (2022-09-23)
15
+
16
+ **Note:** Version bump only for package @squiz/db-lib
17
+
18
+
19
+
20
+
21
+
22
+ ## [1.2.1-alpha.107](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.107) (2022-09-21)
23
+
24
+ **Note:** Version bump only for package @squiz/db-lib
25
+
26
+
27
+
28
+
29
+
30
+ ## [1.2.1-alpha.106](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.106) (2022-09-02)
31
+
32
+ **Note:** Version bump only for package @squiz/db-lib
33
+
34
+
35
+
36
+
37
+
38
+ ## [1.2.1-alpha.105](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.105) (2022-08-26)
39
+
40
+ **Note:** Version bump only for package @squiz/db-lib
41
+
42
+
43
+
44
+
45
+
46
+ ## [1.2.1-alpha.104](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.104) (2022-08-23)
47
+
48
+ **Note:** Version bump only for package @squiz/db-lib
49
+
50
+
51
+
52
+
53
+
54
+ ## [1.2.1-alpha.103](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.103) (2022-08-23)
55
+
56
+ **Note:** Version bump only for package @squiz/db-lib
57
+
58
+
59
+
60
+
61
+
62
+ ## [1.2.1-alpha.102](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.102) (2022-08-23)
63
+
64
+ **Note:** Version bump only for package @squiz/db-lib
65
+
66
+
67
+
68
+
69
+
70
+ ## [1.2.1-alpha.101](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.101) (2022-08-19)
71
+
72
+ **Note:** Version bump only for package @squiz/db-lib
73
+
74
+
75
+
76
+
77
+
78
+ ## [1.2.1-alpha.100](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.100) (2022-08-18)
79
+
80
+ **Note:** Version bump only for package @squiz/db-lib
81
+
82
+
83
+
84
+
85
+
6
86
  ## [1.2.1-alpha.99](https://gitlab.squiz.net/developer-experience/cmp/compare/v1.2.1-alpha.90...v1.2.1-alpha.99) (2022-08-18)
7
87
 
8
88
  **Note:** Version bump only for package @squiz/db-lib
@@ -10,11 +10,18 @@ export interface Writer<T> {
10
10
  delete(where: Partial<T>): Promise<number>;
11
11
  }
12
12
  export declare type Repository<T> = Reader<T> & Writer<T>;
13
- export declare abstract class AbstractRepository<T> implements Reader<T>, Writer<T> {
13
+ export declare type PageResult<T> = {
14
+ items: T[];
15
+ totalCount: number;
16
+ pageSize: number;
17
+ };
18
+ export declare type SortDirection = 'desc' | 'asc';
19
+ export declare const DEFAULT_PAGE_SIZE = 20;
20
+ export declare abstract class AbstractRepository<T, ObjT extends T> implements Reader<T>, Writer<T> {
14
21
  protected repositories: Repositories;
15
22
  protected pool: Pool;
16
23
  protected classRef: {
17
- new (data?: Record<string, unknown>): T;
24
+ new (data?: Record<string, unknown>): ObjT;
18
25
  };
19
26
  protected tableName: string;
20
27
  /** object where the key is the model property name amd the value is sql column name */
@@ -28,16 +35,19 @@ export declare abstract class AbstractRepository<T> implements Reader<T>, Writer
28
35
  constructor(repositories: Repositories, pool: Pool, tableName: string, mapping: {
29
36
  [key in keyof T]: string;
30
37
  }, classRef: {
31
- new (data?: Record<string, unknown>): T;
38
+ new (data?: Record<string, unknown>): ObjT;
32
39
  });
33
40
  protected getConnection(): Promise<PoolClient>;
34
- create(value: Partial<T>, transactionClient?: PoolClient | null): Promise<T>;
41
+ create(value: ObjT, transactionClient?: PoolClient | null): Promise<T>;
35
42
  update(where: Partial<T>, newValue: Partial<T>, transactionClient?: PoolClient | null): Promise<T[]>;
36
43
  delete(where: Partial<T>, transactionClient?: PoolClient | null): Promise<number>;
37
44
  protected createWhereStringFromPartialModel(values: Partial<T>, initialIndex?: number): string;
45
+ protected executeQueryRaw(query: string, values: any[], transactionClient?: PoolClient | null): Promise<any[]>;
38
46
  protected executeQuery(query: string, values: any[], transactionClient?: PoolClient | null): Promise<T[]>;
39
47
  protected createAndHydrateModel(row: any): T;
40
48
  findOne(item: Partial<T>): Promise<T | undefined>;
41
49
  find(item: Partial<T>): Promise<T[]>;
42
50
  findAll(): Promise<T[]>;
51
+ getCount(item?: Partial<T> | null): Promise<number>;
52
+ getPage(pageNumber: number, sortBy?: (keyof T)[], direction?: SortDirection, pageSize?: number | null, item?: Partial<T> | null): Promise<PageResult<T>>;
43
53
  }
package/lib/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './Migrator';
4
4
  export * from './Repositories';
5
5
  export * from './getConnectionInfo';
6
6
  export * from './PostgresErrorCodes';
7
+ export { Pool } from 'pg';