ismx-nexo-node-app 0.4.104 → 0.4.106
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/js/repository/Repository.js +42 -0
- package/dist/js/repository/RepositoryDatabasePostgres.js +13 -0
- package/dist/types/repository/Repository.d.ts +16 -0
- package/dist/types/repository/RepositoryDatabase.d.ts +12 -11
- package/dist/types/repository/RepositoryDatabasePostgres.d.ts +14 -13
- package/dist/types/repository/utils/PostgresUtils.d.ts +2 -2
- package/package.json +1 -1
- package/src/main/node/repository/Repository.ts +43 -0
- package/src/main/node/repository/RepositoryDatabase.ts +12 -11
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +23 -12
- package/src/main/node/repository/utils/PostgresUtils.ts +2 -2
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Hash = void 0;
|
|
5
|
+
class Hash {
|
|
6
|
+
constructor(dict) {
|
|
7
|
+
this.size = null;
|
|
8
|
+
this[_a] = "Hash";
|
|
9
|
+
this.dict = dict !== null && dict !== void 0 ? dict : {};
|
|
10
|
+
}
|
|
11
|
+
add(value) {
|
|
12
|
+
this.dict[value] = null;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
clear() {
|
|
16
|
+
this.dict = {};
|
|
17
|
+
}
|
|
18
|
+
delete(value) {
|
|
19
|
+
return delete this.dict[value];
|
|
20
|
+
}
|
|
21
|
+
forEach(callbackfn, thisArg) {
|
|
22
|
+
return Object.keys(this.dict).forEach((v) => callbackfn(v, v, this), thisArg);
|
|
23
|
+
}
|
|
24
|
+
has(value) {
|
|
25
|
+
return !!this.dict[value];
|
|
26
|
+
}
|
|
27
|
+
entries() {
|
|
28
|
+
return Object.entries(this.dict);
|
|
29
|
+
}
|
|
30
|
+
keys() {
|
|
31
|
+
return Object.keys(this.dict).values();
|
|
32
|
+
}
|
|
33
|
+
values() {
|
|
34
|
+
return Object.keys(this.dict).values();
|
|
35
|
+
}
|
|
36
|
+
length() {
|
|
37
|
+
return Object.keys(this.dict).length;
|
|
38
|
+
}
|
|
39
|
+
[Symbol.iterator]() {
|
|
40
|
+
return Object.keys(this.dict)[Symbol.iterator]();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Hash = Hash;
|
|
44
|
+
_a = Symbol.toStringTag;
|
|
3
45
|
class Repository {
|
|
4
46
|
}
|
|
5
47
|
exports.default = Repository;
|
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const PostgresUtils_1 = __importDefault(require("./utils/PostgresUtils"));
|
|
39
39
|
const RepositoryDatabase_1 = __importDefault(require("./RepositoryDatabase"));
|
|
40
|
+
const Repository_1 = require("./Repository");
|
|
40
41
|
class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
41
42
|
constructor() {
|
|
42
43
|
super();
|
|
@@ -220,6 +221,18 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
220
221
|
return this.query(query, values).then((result) => { var _a, _b; return (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : []; });
|
|
221
222
|
});
|
|
222
223
|
}
|
|
224
|
+
selectSet(tableName, select, filters) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
if (!this.tables[tableName])
|
|
227
|
+
throw new Error(`table ${tableName} does not exist`);
|
|
228
|
+
let schema = this.tables[tableName][0].schema;
|
|
229
|
+
let { where, values } = this.toWhere(tableName, filters);
|
|
230
|
+
let query = `
|
|
231
|
+
SELECT json_object_agg(u.${select}, NULL) as list
|
|
232
|
+
FROM ( SELECT DISTINCT u.${select} FROM ${schema}.${tableName} WHERE "user" = ${where} ) t`;
|
|
233
|
+
return this.query(query, values).then((result) => { var _a, _b; return new Repository_1.Hash((_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : {}); });
|
|
234
|
+
});
|
|
235
|
+
}
|
|
223
236
|
toWhere(tableName, filters = {}, alias = "", index = 1) {
|
|
224
237
|
let table = this.tables[tableName];
|
|
225
238
|
let columns = PostgresUtils_1.default.columns(table);
|
|
@@ -3,5 +3,21 @@ export interface Pagination<T> {
|
|
|
3
3
|
elements: T[];
|
|
4
4
|
}
|
|
5
5
|
export type Transient<T> = Omit<T, 'id'>;
|
|
6
|
+
export declare class Hash<T extends string | number | symbol> implements Set<T> {
|
|
7
|
+
dict: Record<T, any>;
|
|
8
|
+
size: number;
|
|
9
|
+
constructor(dict?: Record<T, any>);
|
|
10
|
+
add(value: T): this;
|
|
11
|
+
clear(): void;
|
|
12
|
+
delete(value: T): boolean;
|
|
13
|
+
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
|
|
14
|
+
has(value: T): boolean;
|
|
15
|
+
entries(): SetIterator<[T, T]>;
|
|
16
|
+
keys(): SetIterator<T>;
|
|
17
|
+
values(): SetIterator<T>;
|
|
18
|
+
length(): number;
|
|
19
|
+
[Symbol.iterator](): SetIterator<T>;
|
|
20
|
+
[Symbol.toStringTag]: string;
|
|
21
|
+
}
|
|
6
22
|
export default class Repository {
|
|
7
23
|
}
|
|
@@ -10,7 +10,8 @@ export interface Chain {
|
|
|
10
10
|
password: string;
|
|
11
11
|
database: string;
|
|
12
12
|
}
|
|
13
|
-
export type Primitive = string | number |
|
|
13
|
+
export type Primitive = string | number | symbol;
|
|
14
|
+
export type Valuable = Primitive | Date | null | undefined;
|
|
14
15
|
export default abstract class RepositoryDatabase extends Repository {
|
|
15
16
|
protected connected: boolean;
|
|
16
17
|
protected chain: Chain;
|
|
@@ -27,36 +28,36 @@ export default abstract class RepositoryDatabase extends Repository {
|
|
|
27
28
|
abstract query<E>(query: string, values: any[], options: QueryOptions): Promise<E[]>;
|
|
28
29
|
abstract one<E>(tableName: string, id: string): Promise<E>;
|
|
29
30
|
abstract any<E>(tableName: string, filters: {
|
|
30
|
-
[key: string]:
|
|
31
|
+
[key: string]: Valuable | Array<any>;
|
|
31
32
|
}): Promise<E>;
|
|
32
33
|
abstract find<E>(tableName: string, filters: {
|
|
33
|
-
[key: string]:
|
|
34
|
+
[key: string]: Valuable | Array<any>;
|
|
34
35
|
}): Promise<E[]>;
|
|
35
36
|
abstract group(tableName: string, key: string, value: string, filters: {
|
|
36
|
-
[p: string]:
|
|
37
|
+
[p: string]: Valuable | Array<any>;
|
|
37
38
|
}): Promise<{
|
|
38
39
|
[p: string]: string[];
|
|
39
40
|
}>;
|
|
40
41
|
abstract add<E>(tableName: string, object: {
|
|
41
|
-
[key: string]:
|
|
42
|
+
[key: string]: Valuable;
|
|
42
43
|
} | any, id?: string): Promise<E>;
|
|
43
44
|
abstract addAll<T>(tableName: string, objects: ({
|
|
44
|
-
[key: string]:
|
|
45
|
+
[key: string]: Valuable;
|
|
45
46
|
} | any)[]): Promise<T[]>;
|
|
46
47
|
abstract update<T>(tableName: string, id: string, object: {
|
|
47
|
-
[key: string]:
|
|
48
|
+
[key: string]: Valuable;
|
|
48
49
|
} | any): Promise<T>;
|
|
49
50
|
abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {
|
|
50
|
-
[key: string]:
|
|
51
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
51
52
|
}): Promise<Pagination<T>>;
|
|
52
53
|
abstract exist(tableName: string, filters?: {
|
|
53
|
-
[key: string]:
|
|
54
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
54
55
|
}): Promise<boolean>;
|
|
55
56
|
abstract count(tableName: string, filters?: {
|
|
56
|
-
[key: string]:
|
|
57
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
57
58
|
}): Promise<number>;
|
|
58
59
|
abstract select(tableName: string, select: string, filters?: {
|
|
59
|
-
[key: string]:
|
|
60
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
60
61
|
}): Promise<string[]>;
|
|
61
62
|
abstract delete<T>(tableName: string, id: string): Promise<T>;
|
|
62
63
|
abstract deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import RepositoryDatabase, { Chain,
|
|
2
|
-
import { Pagination } from "./Repository";
|
|
1
|
+
import RepositoryDatabase, { Chain, Valuable, QueryOptions, Primitive } from "./RepositoryDatabase";
|
|
2
|
+
import { Hash, Pagination } from "./Repository";
|
|
3
3
|
export interface Column {
|
|
4
4
|
name: string;
|
|
5
5
|
schema: string;
|
|
@@ -20,42 +20,43 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase {
|
|
|
20
20
|
query<E>(query: string, values?: any[], options?: QueryOptions): Promise<E[]>;
|
|
21
21
|
one<E>(tableName: string, id: string): Promise<E>;
|
|
22
22
|
any<E>(tableName: string, filters?: {
|
|
23
|
-
[key: string]:
|
|
23
|
+
[key: string]: Valuable | Array<any>;
|
|
24
24
|
}): Promise<E>;
|
|
25
25
|
find<T>(tableName: string, filters?: {
|
|
26
|
-
[key: string]:
|
|
26
|
+
[key: string]: Valuable | Array<any>;
|
|
27
27
|
}): Promise<T[]>;
|
|
28
28
|
group(tableName: string, key: string, value: string, filters: {
|
|
29
|
-
[p: string]:
|
|
29
|
+
[p: string]: Valuable | Array<any>;
|
|
30
30
|
}): Promise<{
|
|
31
31
|
[p: string]: any[];
|
|
32
32
|
}>;
|
|
33
33
|
add<E>(tableName: string, object: {
|
|
34
|
-
[key: string]:
|
|
34
|
+
[key: string]: Valuable;
|
|
35
35
|
} | any, id?: string): Promise<E>;
|
|
36
36
|
addAll<T>(tableName: string, objects: ({
|
|
37
|
-
[key: string]:
|
|
37
|
+
[key: string]: Valuable;
|
|
38
38
|
} | any)[]): Promise<T[]>;
|
|
39
39
|
update<T>(tableName: string, id: string, object: Partial<T>): Promise<T>;
|
|
40
40
|
delete<T>(tableName: string, id: string): Promise<T>;
|
|
41
41
|
deleteAll<T>(tableName: string, filters: Partial<T>): Promise<T[]>;
|
|
42
42
|
page<T>(tableName: string, sortKey: string, maxResults?: number, pageNumber?: number, filters?: {
|
|
43
|
-
[key: string]:
|
|
43
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
44
44
|
}): Promise<Pagination<T>>;
|
|
45
45
|
exist(tableName: string, filters?: {
|
|
46
|
-
[p: string]:
|
|
46
|
+
[p: string]: Valuable | Array<Valuable>;
|
|
47
47
|
}): Promise<boolean>;
|
|
48
48
|
count(tableName: string, filters?: {
|
|
49
|
-
[key: string]:
|
|
49
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
50
50
|
}): Promise<number>;
|
|
51
51
|
select(tableName: string, select: string, filters?: {
|
|
52
|
-
[key: string]:
|
|
52
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
53
53
|
}): Promise<string[]>;
|
|
54
|
+
selectSet<T>(tableName: string, select: string, filters: Partial<T>): Promise<Hash<Primitive>>;
|
|
54
55
|
toWhere(tableName: string, filters?: {
|
|
55
|
-
[key: string]:
|
|
56
|
+
[key: string]: Valuable | Array<Valuable>;
|
|
56
57
|
}, alias?: string, index?: number): {
|
|
57
58
|
where: string;
|
|
58
|
-
values: (string | number | Date |
|
|
59
|
+
values: (string | number | symbol | Date | Valuable[])[];
|
|
59
60
|
};
|
|
60
61
|
private introspect;
|
|
61
62
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Column } from "../RepositoryDatabasePostgres";
|
|
2
|
-
import {
|
|
2
|
+
import { Valuable } from "../RepositoryDatabase";
|
|
3
3
|
export default abstract class PostgresUtils {
|
|
4
4
|
static camelToSnake(column: string): string;
|
|
5
5
|
static snakeToCamel(obj: any): any;
|
|
6
6
|
static columns(table: Column[]): string[];
|
|
7
7
|
static isReservedWord(word: string): boolean;
|
|
8
8
|
static bindOrDefault(table: Column[], object: {
|
|
9
|
-
[p: string]:
|
|
9
|
+
[p: string]: Valuable;
|
|
10
10
|
}, startIndex: any): {
|
|
11
11
|
bindings: string[];
|
|
12
12
|
values: any[];
|
package/package.json
CHANGED
|
@@ -5,6 +5,49 @@ export interface Pagination<T> {
|
|
|
5
5
|
|
|
6
6
|
export type Transient<T> = Omit<T, 'id'>
|
|
7
7
|
|
|
8
|
+
export class Hash<T extends string | number | symbol> implements Set<T>
|
|
9
|
+
{
|
|
10
|
+
dict: Record<T, any>
|
|
11
|
+
size: number = null!;
|
|
12
|
+
|
|
13
|
+
constructor(dict?: Record<T, any>) {
|
|
14
|
+
this.dict = dict ?? {} as Record<T, any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
add(value: T): this {
|
|
18
|
+
this.dict[value] = null;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
clear(): void {
|
|
22
|
+
this.dict = {} as Record<T, any>;
|
|
23
|
+
}
|
|
24
|
+
delete(value: T): boolean {
|
|
25
|
+
return delete this.dict[value];
|
|
26
|
+
}
|
|
27
|
+
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void {
|
|
28
|
+
return Object.keys(this.dict).forEach((v) => callbackfn(v as T, v as T, this), thisArg);
|
|
29
|
+
}
|
|
30
|
+
has(value: T): boolean {
|
|
31
|
+
return !!this.dict[value];
|
|
32
|
+
}
|
|
33
|
+
entries(): SetIterator<[T, T]> {
|
|
34
|
+
return Object.entries(this.dict) as unknown as SetIterator<[T, T]>;
|
|
35
|
+
}
|
|
36
|
+
keys(): SetIterator<T> {
|
|
37
|
+
return Object.keys(this.dict).values() as SetIterator<T>;
|
|
38
|
+
}
|
|
39
|
+
values(): SetIterator<T> {
|
|
40
|
+
return Object.keys(this.dict).values() as SetIterator<T>;
|
|
41
|
+
}
|
|
42
|
+
length(): number {
|
|
43
|
+
return Object.keys(this.dict).length;
|
|
44
|
+
}
|
|
45
|
+
[Symbol.iterator](): SetIterator<T> {
|
|
46
|
+
return (Object.keys(this.dict) as T[])[Symbol.iterator]()
|
|
47
|
+
}
|
|
48
|
+
[Symbol.toStringTag]: string = "Hash";
|
|
49
|
+
}
|
|
50
|
+
|
|
8
51
|
export default class Repository {
|
|
9
52
|
|
|
10
53
|
}
|
|
@@ -13,7 +13,8 @@ export interface Chain {
|
|
|
13
13
|
database: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export type Primitive = string | number |
|
|
16
|
+
export type Primitive = string | number | symbol
|
|
17
|
+
export type Valuable = Primitive | Date | null | undefined;
|
|
17
18
|
|
|
18
19
|
export default abstract class RepositoryDatabase extends Repository
|
|
19
20
|
{
|
|
@@ -52,25 +53,25 @@ export default abstract class RepositoryDatabase extends Repository
|
|
|
52
53
|
|
|
53
54
|
abstract one<E>(tableName: string, id: string): Promise<E>;
|
|
54
55
|
|
|
55
|
-
abstract any<E>(tableName: string, filters: { [key: string]:
|
|
56
|
+
abstract any<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }): Promise<E>;
|
|
56
57
|
|
|
57
|
-
abstract find<E>(tableName: string, filters: { [key: string]:
|
|
58
|
+
abstract find<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }): Promise<E[]>;
|
|
58
59
|
|
|
59
|
-
abstract group(tableName: string, key: string, value: string, filters: { [p: string]:
|
|
60
|
+
abstract group(tableName: string, key: string, value: string, filters: { [p: string]: Valuable | Array<any> }): Promise<{ [p: string]: string[] }>
|
|
60
61
|
|
|
61
|
-
abstract add<E>(tableName: string, object: {[key:string]:
|
|
62
|
+
abstract add<E>(tableName: string, object: {[key:string]:Valuable}|any, id?: string): Promise<E>;
|
|
62
63
|
|
|
63
|
-
abstract addAll<T>(tableName: string, objects: ({[key:string]:
|
|
64
|
+
abstract addAll<T>(tableName: string, objects: ({[key:string]:Valuable }|any)[]): Promise<T[]>;
|
|
64
65
|
|
|
65
|
-
abstract update<T>(tableName: string, id: string, object: {[key:string]:
|
|
66
|
+
abstract update<T>(tableName: string, id: string, object: {[key:string]:Valuable}|any): Promise<T>;
|
|
66
67
|
|
|
67
|
-
abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {[key:string]:
|
|
68
|
+
abstract page<T>(tableName: string, sortKey: string, maxResults: number, pageNumber: number, filters?: {[key:string]:Valuable|Array<Valuable>}): Promise<Pagination<T>>;
|
|
68
69
|
|
|
69
|
-
abstract exist(tableName: string, filters?: { [key: string]:
|
|
70
|
+
abstract exist(tableName: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<boolean>;
|
|
70
71
|
|
|
71
|
-
abstract count(tableName: string, filters?: { [key: string]:
|
|
72
|
+
abstract count(tableName: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<number>;
|
|
72
73
|
|
|
73
|
-
abstract select(tableName: string, select: string, filters?: { [key: string]:
|
|
74
|
+
abstract select(tableName: string, select: string, filters?: { [key: string]: Valuable | Array<Valuable> }): Promise<string[]>;
|
|
74
75
|
|
|
75
76
|
abstract delete<T>(tableName: string, id: string): Promise<T>;
|
|
76
77
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PostgresUtils from "./utils/PostgresUtils";
|
|
2
|
-
import RepositoryDatabase, {Chain,
|
|
3
|
-
import {Pagination} from "./Repository";
|
|
2
|
+
import RepositoryDatabase, {Chain, Valuable, QueryOptions, Primitive} from "./RepositoryDatabase";
|
|
3
|
+
import {Hash, Pagination} from "./Repository";
|
|
4
4
|
|
|
5
5
|
export interface Column {
|
|
6
6
|
name: string
|
|
@@ -66,12 +66,12 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
66
66
|
return this.any<E>(tableName, { id });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
async any<E>(tableName: string, filters: { [key: string]:
|
|
69
|
+
async any<E>(tableName: string, filters: { [key: string]: Valuable | Array<any> }={}): Promise<E>
|
|
70
70
|
{
|
|
71
71
|
return await this.find<E>(tableName, filters).then((rows) => rows[0]);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
async find<T>(tableName: string, filters: { [key: string]:
|
|
74
|
+
async find<T>(tableName: string, filters: { [key: string]: Valuable | Array<any> }={}): Promise<T[]>
|
|
75
75
|
{
|
|
76
76
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
77
77
|
let schema = this.tables[tableName][0].schema;
|
|
@@ -80,7 +80,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
80
80
|
return this.query<T>(query, values);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
async group(tableName: string, key: string, value: string, filters: { [p: string]:
|
|
83
|
+
async group(tableName: string, key: string, value: string, filters: { [p: string]: Valuable | Array<any> }): Promise<{ [p: string]: any[] }> {
|
|
84
84
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
85
85
|
let schema = this.tables[tableName][0].schema;
|
|
86
86
|
let { where, values } = this.toWhere(tableName, filters);
|
|
@@ -94,12 +94,12 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
async add<E>(tableName: string, object: {[key:string]:
|
|
97
|
+
async add<E>(tableName: string, object: {[key:string]:Valuable}|any, id?: string): Promise<E>
|
|
98
98
|
{
|
|
99
99
|
return this.addAll<E>(tableName, [ { id: id, ...object } ]).then((rows) => rows[0]);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
async addAll<T>(tableName: string, objects: ({[key:string]:
|
|
102
|
+
async addAll<T>(tableName: string, objects: ({[key:string]:Valuable }|any)[]): Promise<T[]>
|
|
103
103
|
{
|
|
104
104
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
105
105
|
let table = this.tables[tableName];
|
|
@@ -153,7 +153,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
153
153
|
return this.query<T>(query, values);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:
|
|
156
|
+
async page<T>(tableName: string, sortKey: string, maxResults: number = 50, pageNumber: number = 0, filters: {[key:string]:Valuable|Array<Valuable>}={}): Promise<Pagination<T>>
|
|
157
157
|
{
|
|
158
158
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
159
159
|
let table = this.tables[tableName];
|
|
@@ -171,11 +171,11 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
async exist(tableName: string, filters: { [p: string]:
|
|
174
|
+
async exist(tableName: string, filters: { [p: string]: Valuable | Array<Valuable> }={}): Promise<boolean> {
|
|
175
175
|
return (await this.count(tableName, filters)) > 0;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
async count(tableName: string, filters: { [key: string]:
|
|
178
|
+
async count(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<number>
|
|
179
179
|
{
|
|
180
180
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
181
181
|
let schema = this.tables[tableName][0].schema;
|
|
@@ -184,7 +184,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
184
184
|
return this.query<{count:string}>(query, values).then((result) => Number.parseInt(result[0]?.count ?? "0"));
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
async select(tableName: string, select: string, filters: { [key: string]:
|
|
187
|
+
async select(tableName: string, select: string, filters: { [key: string]: Valuable | Array<Valuable> }={}): Promise<string[]>
|
|
188
188
|
{
|
|
189
189
|
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
190
190
|
let schema = this.tables[tableName][0].schema;
|
|
@@ -193,7 +193,18 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
193
193
|
return this.query<{list:string[]}>(query, values).then((result) => result[0]?.list ?? []);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
async selectSet<T>(tableName: string, select: string, filters: Partial<T>): Promise<Hash<Primitive>>
|
|
197
|
+
{
|
|
198
|
+
if (!this.tables[tableName]) throw new Error(`table ${tableName} does not exist`);
|
|
199
|
+
let schema = this.tables[tableName][0].schema;
|
|
200
|
+
let { where, values } = this.toWhere(tableName, filters as any);
|
|
201
|
+
let query = `
|
|
202
|
+
SELECT json_object_agg(u.${select}, NULL) as list
|
|
203
|
+
FROM ( SELECT DISTINCT u.${select} FROM ${schema}.${tableName} WHERE "user" = ${where} ) t`;
|
|
204
|
+
return this.query<{list:Record<Primitive, null>}>(query, values).then((result) => new Hash(result[0]?.list ?? {}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
toWhere(tableName: string, filters: { [key: string]: Valuable | Array<Valuable> }={}, alias:string = "", index=1)
|
|
197
208
|
{
|
|
198
209
|
let table = this.tables[tableName];
|
|
199
210
|
let columns = PostgresUtils.columns(table);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Column} from "../RepositoryDatabasePostgres";
|
|
2
|
-
import {
|
|
2
|
+
import {Valuable} from "../RepositoryDatabase";
|
|
3
3
|
|
|
4
4
|
export default abstract class PostgresUtils
|
|
5
5
|
{
|
|
@@ -41,7 +41,7 @@ export default abstract class PostgresUtils
|
|
|
41
41
|
return reservedWords.has(word.toLowerCase());
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
static bindOrDefault(table: Column[], object: { [p: string]:
|
|
44
|
+
static bindOrDefault(table: Column[], object: { [p: string]: Valuable }, startIndex: any): { bindings: string[], values: any[] } {
|
|
45
45
|
|
|
46
46
|
let index = startIndex;
|
|
47
47
|
let bindings: string[] = [];
|