@starbemtech/star-db-query-builder 1.1.0 → 1.3.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.
- package/.github/workflows/publish.yml +118 -0
- package/ARCHITECTURE.md +313 -0
- package/CHANGELOG.md +67 -0
- package/README.md +1275 -210
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/mysqlClient.ts.html +685 -0
- package/coverage/lcov-report/pgClient.ts.html +823 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +533 -0
- package/coverage/mysqlClient.ts.html +685 -0
- package/coverage/pgClient.ts.html +823 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/core/repository.d.ts +374 -0
- package/dist/src/core/repository.js +677 -0
- package/dist/src/core/repository.js.map +1 -0
- package/dist/src/{default → core}/types.d.ts +8 -0
- package/dist/src/{default → core}/types.js.map +1 -1
- package/dist/src/core/utils.d.ts +133 -0
- package/dist/src/{default → core}/utils.js +167 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/db/IDatabaseClient.d.ts +10 -1
- package/dist/src/db/initDb.d.ts +120 -1
- package/dist/src/db/initDb.js +119 -0
- package/dist/src/db/initDb.js.map +1 -1
- package/dist/src/db/mysqlClient.d.ts +23 -1
- package/dist/src/db/mysqlClient.js +115 -0
- package/dist/src/db/mysqlClient.js.map +1 -1
- package/dist/src/db/pgClient.d.ts +22 -1
- package/dist/src/db/pgClient.js +127 -0
- package/dist/src/db/pgClient.js.map +1 -1
- package/dist/src/monitor/monitor.d.ts +6 -1
- package/dist/src/monitor/monitor.js +5 -0
- package/dist/src/monitor/monitor.js.map +1 -1
- package/dist/src/setupTests.d.ts +26 -0
- package/dist/src/setupTests.js +43 -0
- package/dist/src/setupTests.js.map +1 -0
- package/docs/INDEX.md +145 -0
- package/docs/methods/findFirst.md +394 -0
- package/docs/methods/findMany.md +587 -0
- package/docs/methods/insert.md +536 -0
- package/docs/methods/insertMany.md +627 -0
- package/docs/methods/joins.md +781 -0
- package/docs/methods/rawQuery.md +284 -0
- package/docs/methods/transactions.md +737 -0
- package/eslint.config.mjs +77 -0
- package/index.ts +5 -4
- package/jest.config.ts +23 -28
- package/package.json +53 -30
- package/scripts/release.sh +123 -0
- package/src/core/repository.ts +865 -0
- package/src/{default → core}/types.ts +10 -1
- package/src/{default → core}/utils.ts +168 -0
- package/src/db/IDatabaseClient.ts +11 -1
- package/src/db/__tests__/mysqlClient.test.ts +262 -0
- package/src/db/__tests__/pgClient.test.ts +260 -0
- package/src/db/initDb.ts +120 -1
- package/src/db/mysqlClient.ts +119 -3
- package/src/db/pgClient.ts +131 -3
- package/src/monitor/monitor.ts +5 -0
- package/src/setupTests.ts +45 -0
- package/tsconfig.test.json +21 -0
- package/.eslintignore +0 -4
- package/.eslintrc.json +0 -32
- package/dist/.eslintrc.json +0 -32
- package/dist/src/default/genericRepository.d.ts +0 -28
- package/dist/src/default/genericRepository.js +0 -284
- package/dist/src/default/genericRepository.js.map +0 -1
- package/dist/src/default/utils.d.ts +0 -9
- package/dist/src/default/utils.js.map +0 -1
- package/index.d.ts +0 -60
- package/src/default/genericRepository.ts +0 -461
- /package/dist/src/{default → core}/types.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/core/rep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;;;;;;;;;GA4BG;AACI,MAAM,gBAAgB,GAAG,KAAK,EACnC,QAAa,EACgB,EAAE;IAC/B,OAAO,QAAQ,CAAC,gBAAgB,EAAE,CAAA;AACpC,CAAC,CAAA;AAJY,QAAA,gBAAgB,oBAI5B"}
|
|
@@ -59,4 +59,12 @@ export interface QueryBuilder {
|
|
|
59
59
|
limit?: string;
|
|
60
60
|
offset?: string;
|
|
61
61
|
}
|
|
62
|
+
export interface RawQueryParams {
|
|
63
|
+
dbClient: IDatabaseClient;
|
|
64
|
+
sql: string;
|
|
65
|
+
params?: any[];
|
|
66
|
+
}
|
|
67
|
+
export interface TransactionParams {
|
|
68
|
+
dbClient: IDatabaseClient;
|
|
69
|
+
}
|
|
62
70
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Conditions, OrderBy, DBClients } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a SELECT clause for a query
|
|
4
|
+
*
|
|
5
|
+
* This function creates a SELECT clause for a query. It takes an array of fields
|
|
6
|
+
* and a database client type and returns a string with the fields separated by commas.
|
|
7
|
+
*
|
|
8
|
+
* @param fields - The array of fields to select
|
|
9
|
+
* @param clientType - The type of database client
|
|
10
|
+
* @returns A string with the fields separated by commas
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const fields = ['id', 'name', 'email']
|
|
14
|
+
* const clientType = 'pg'
|
|
15
|
+
* const result = createSelectFields(fields, clientType)
|
|
16
|
+
* // result will be: "id, name, email"
|
|
17
|
+
*/
|
|
18
|
+
export declare const createSelectFields: (fields: string[] | undefined, clientType: DBClients) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Generates placeholders for a query
|
|
21
|
+
*
|
|
22
|
+
* This function generates placeholders for a query. It takes an array of keys
|
|
23
|
+
* and a database client type and returns a string with the placeholders separated by commas.
|
|
24
|
+
*
|
|
25
|
+
* @param keys - The array of keys to generate placeholders for
|
|
26
|
+
* @param clientType - The type of database client
|
|
27
|
+
* @returns A string with the placeholders separated by commas
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const keys = ['id', 'name', 'email']
|
|
31
|
+
* const clientType = 'pg'
|
|
32
|
+
* const result = generatePlaceholders(keys, clientType)
|
|
33
|
+
* // result will be: $1, $2, $3
|
|
34
|
+
*/
|
|
35
|
+
export declare const generatePlaceholders: (keys: any[], clientType: DBClients) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Generates a SET clause for a query
|
|
38
|
+
*
|
|
39
|
+
* This function generates a SET clause for a query. It takes an array of keys
|
|
40
|
+
* and a database client type and returns a string with the keys and placeholders separated by commas.
|
|
41
|
+
*
|
|
42
|
+
* @param keys - The array of keys to generate SET clause for
|
|
43
|
+
* @param clientType - The type of database client
|
|
44
|
+
* @returns A string with the keys and placeholders separated by commas
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const keys = ['id', 'name', 'email']
|
|
48
|
+
* const clientType = 'pg'
|
|
49
|
+
* const result = generateSetClause(keys, clientType)
|
|
50
|
+
* // result will be: "id = $1, name = $2, email = $3"
|
|
51
|
+
*/
|
|
52
|
+
export declare const generateSetClause: (keys: any[], clientType: DBClients) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a WHERE clause for a query
|
|
55
|
+
*
|
|
56
|
+
* This function creates a WHERE clause for a query. It takes an array of conditions
|
|
57
|
+
* and a database client type and returns a string with the conditions separated by AND.
|
|
58
|
+
*
|
|
59
|
+
* @param conditions - The array of conditions to create WHERE clause for
|
|
60
|
+
* @param startIndex - The index of the first parameter
|
|
61
|
+
* @param clientType - The type of database client
|
|
62
|
+
* @param unaccent - Whether to use unaccent function
|
|
63
|
+
* @returns A string with the conditions separated by AND
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const conditions = [{ field: 'name', operator: '=', value: 'John Doe' }]
|
|
67
|
+
* const startIndex = 1
|
|
68
|
+
* const clientType = 'pg'
|
|
69
|
+
* const unaccent = true
|
|
70
|
+
* const result = createWhereClause(conditions, startIndex, clientType, unaccent)
|
|
71
|
+
* // result will be: "name = $1"
|
|
72
|
+
*/
|
|
73
|
+
export declare const createWhereClause: <T>(conditions: Conditions<T> | undefined, startIndex: number | undefined, clientType: DBClients, unaccent?: boolean) => [string, any[], number];
|
|
74
|
+
/**
|
|
75
|
+
* Creates an ORDER BY clause for a query
|
|
76
|
+
*
|
|
77
|
+
* This function creates an ORDER BY clause for a query. It takes an array of
|
|
78
|
+
* order by fields and returns a string with the fields separated by commas.
|
|
79
|
+
*
|
|
80
|
+
* @param orderBy - The array of order by fields
|
|
81
|
+
* @returns A string with the fields separated by commas
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* const orderBy = [{ field: 'created_at', direction: 'DESC' }]
|
|
85
|
+
* const result = createOrderByClause(orderBy)
|
|
86
|
+
* // result will be: "ORDER BY created_at DESC"
|
|
87
|
+
*/
|
|
88
|
+
export declare const createOrderByClause: (orderBy?: OrderBy) => string;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a GROUP BY clause for a query
|
|
91
|
+
*
|
|
92
|
+
* This function creates a GROUP BY clause for a query. It takes an array of
|
|
93
|
+
* group by fields and returns a string with the fields separated by commas.
|
|
94
|
+
*
|
|
95
|
+
* @param groupBy - The array of group by fields
|
|
96
|
+
* @returns A string with the fields separated by commas
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const groupBy = ['status']
|
|
100
|
+
* const result = createGroupByClause(groupBy)
|
|
101
|
+
* // result will be: "GROUP BY status"
|
|
102
|
+
*/
|
|
103
|
+
export declare const createGroupByClause: (groupBy?: string[]) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a LIMIT clause for a query
|
|
106
|
+
*
|
|
107
|
+
* This function creates a LIMIT clause for a query. It takes a limit number
|
|
108
|
+
* and returns a string with the limit.
|
|
109
|
+
*
|
|
110
|
+
* @param limit - The limit number
|
|
111
|
+
* @returns A string with the limit
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const limit = 10
|
|
115
|
+
* const result = createLimitClause(limit)
|
|
116
|
+
* // result will be: "LIMIT 10"
|
|
117
|
+
*/
|
|
118
|
+
export declare const createLimitClause: (limit?: number) => string;
|
|
119
|
+
/**
|
|
120
|
+
* Creates an OFFSET clause for a query
|
|
121
|
+
*
|
|
122
|
+
* This function creates an OFFSET clause for a query. It takes an offset number
|
|
123
|
+
* and returns a string with the offset.
|
|
124
|
+
*
|
|
125
|
+
* @param offset - The offset number
|
|
126
|
+
* @returns A string with the offset
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* const offset = 10
|
|
130
|
+
* const result = createOffsetClause(offset)
|
|
131
|
+
* // result will be: "OFFSET 10"
|
|
132
|
+
*/
|
|
133
|
+
export declare const createOffsetClause: (offset?: number) => string;
|
|
@@ -1,30 +1,141 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOffsetClause = exports.createLimitClause = exports.createGroupByClause = exports.createOrderByClause = exports.createWhereClause = exports.generateSetClause = exports.generatePlaceholders = exports.createSelectFields = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts an array of strings to a comma-separated string with quotes
|
|
6
|
+
*
|
|
7
|
+
* This function takes an array of strings and converts it to a comma-separated string
|
|
8
|
+
* with quotes. It handles the differences between PostgreSQL and MySQL syntax for
|
|
9
|
+
* string arrays.
|
|
10
|
+
*
|
|
11
|
+
* @param items - The array of strings to convert
|
|
12
|
+
* @param clientType - The type of database client
|
|
13
|
+
* @returns A comma-separated string with quotes
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const items = ['item1', 'item2', 'item3']
|
|
17
|
+
* const clientType = 'pg'
|
|
18
|
+
* const result = arrayToStringWithQuotes(items, clientType)
|
|
19
|
+
* // result will be: 'item1', 'item2', 'item3'
|
|
20
|
+
*/
|
|
4
21
|
const arrayToStringWithQuotes = (items, clientType) => {
|
|
5
22
|
const itemsWithQuotes = items.map((item) => clientType === 'pg' ? `${item}` : `${item}`);
|
|
6
23
|
return itemsWithQuotes.join(', ');
|
|
7
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Generates a PostgreSQL placeholder for a parameter
|
|
27
|
+
*
|
|
28
|
+
* This function generates a PostgreSQL placeholder for a parameter. It returns
|
|
29
|
+
* a string with a dollar sign and the index of the parameter.
|
|
30
|
+
*
|
|
31
|
+
* @param index - The index of the parameter
|
|
32
|
+
* @returns A PostgreSQL placeholder
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const index = 1
|
|
36
|
+
* const placeholder = pgPlaceholderGenerator(index)
|
|
37
|
+
* // placeholder will be: $1
|
|
38
|
+
*/
|
|
8
39
|
const pgPlaceholderGenerator = (index) => `$${index}`;
|
|
40
|
+
/**
|
|
41
|
+
* Generates a MySQL placeholder for a parameter
|
|
42
|
+
*
|
|
43
|
+
* This function generates a MySQL placeholder for a parameter. It returns
|
|
44
|
+
* a string with a question mark.
|
|
45
|
+
*
|
|
46
|
+
* @returns A MySQL placeholder
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const placeholder = mysqlPlaceholderGenerator()
|
|
50
|
+
* // placeholder will be: ?
|
|
51
|
+
*/
|
|
9
52
|
const mysqlPlaceholderGenerator = () => `?`;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a SELECT clause for a query
|
|
55
|
+
*
|
|
56
|
+
* This function creates a SELECT clause for a query. It takes an array of fields
|
|
57
|
+
* and a database client type and returns a string with the fields separated by commas.
|
|
58
|
+
*
|
|
59
|
+
* @param fields - The array of fields to select
|
|
60
|
+
* @param clientType - The type of database client
|
|
61
|
+
* @returns A string with the fields separated by commas
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const fields = ['id', 'name', 'email']
|
|
65
|
+
* const clientType = 'pg'
|
|
66
|
+
* const result = createSelectFields(fields, clientType)
|
|
67
|
+
* // result will be: "id, name, email"
|
|
68
|
+
*/
|
|
10
69
|
const createSelectFields = (fields = [], clientType) => {
|
|
11
70
|
return fields && fields.length > 0
|
|
12
71
|
? arrayToStringWithQuotes(fields, clientType)
|
|
13
72
|
: '*';
|
|
14
73
|
};
|
|
15
74
|
exports.createSelectFields = createSelectFields;
|
|
75
|
+
/**
|
|
76
|
+
* Generates placeholders for a query
|
|
77
|
+
*
|
|
78
|
+
* This function generates placeholders for a query. It takes an array of keys
|
|
79
|
+
* and a database client type and returns a string with the placeholders separated by commas.
|
|
80
|
+
*
|
|
81
|
+
* @param keys - The array of keys to generate placeholders for
|
|
82
|
+
* @param clientType - The type of database client
|
|
83
|
+
* @returns A string with the placeholders separated by commas
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const keys = ['id', 'name', 'email']
|
|
87
|
+
* const clientType = 'pg'
|
|
88
|
+
* const result = generatePlaceholders(keys, clientType)
|
|
89
|
+
* // result will be: $1, $2, $3
|
|
90
|
+
*/
|
|
16
91
|
const generatePlaceholders = (keys, clientType) => {
|
|
17
92
|
return keys
|
|
18
93
|
.map((_, index) => (clientType === 'pg' ? `$${index + 1}` : '?'))
|
|
19
94
|
.join(', ');
|
|
20
95
|
};
|
|
21
96
|
exports.generatePlaceholders = generatePlaceholders;
|
|
97
|
+
/**
|
|
98
|
+
* Generates a SET clause for a query
|
|
99
|
+
*
|
|
100
|
+
* This function generates a SET clause for a query. It takes an array of keys
|
|
101
|
+
* and a database client type and returns a string with the keys and placeholders separated by commas.
|
|
102
|
+
*
|
|
103
|
+
* @param keys - The array of keys to generate SET clause for
|
|
104
|
+
* @param clientType - The type of database client
|
|
105
|
+
* @returns A string with the keys and placeholders separated by commas
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const keys = ['id', 'name', 'email']
|
|
109
|
+
* const clientType = 'pg'
|
|
110
|
+
* const result = generateSetClause(keys, clientType)
|
|
111
|
+
* // result will be: "id = $1, name = $2, email = $3"
|
|
112
|
+
*/
|
|
22
113
|
const generateSetClause = (keys, clientType) => {
|
|
23
114
|
return keys
|
|
24
115
|
.map((key, index) => clientType === 'pg' ? `${key} = $${index + 1}` : `${key} = ?`)
|
|
25
116
|
.join(', ');
|
|
26
117
|
};
|
|
27
118
|
exports.generateSetClause = generateSetClause;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a WHERE clause for a query
|
|
121
|
+
*
|
|
122
|
+
* This function creates a WHERE clause for a query. It takes an array of conditions
|
|
123
|
+
* and a database client type and returns a string with the conditions separated by AND.
|
|
124
|
+
*
|
|
125
|
+
* @param conditions - The array of conditions to create WHERE clause for
|
|
126
|
+
* @param startIndex - The index of the first parameter
|
|
127
|
+
* @param clientType - The type of database client
|
|
128
|
+
* @param unaccent - Whether to use unaccent function
|
|
129
|
+
* @returns A string with the conditions separated by AND
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* const conditions = [{ field: 'name', operator: '=', value: 'John Doe' }]
|
|
133
|
+
* const startIndex = 1
|
|
134
|
+
* const clientType = 'pg'
|
|
135
|
+
* const unaccent = true
|
|
136
|
+
* const result = createWhereClause(conditions, startIndex, clientType, unaccent)
|
|
137
|
+
* // result will be: "name = $1"
|
|
138
|
+
*/
|
|
28
139
|
const createWhereClause = (conditions = {}, startIndex = 1, clientType, unaccent) => {
|
|
29
140
|
let index = startIndex;
|
|
30
141
|
const whereParts = [];
|
|
@@ -124,6 +235,20 @@ const createWhereClause = (conditions = {}, startIndex = 1, clientType, unaccent
|
|
|
124
235
|
return [whereClause, values, index];
|
|
125
236
|
};
|
|
126
237
|
exports.createWhereClause = createWhereClause;
|
|
238
|
+
/**
|
|
239
|
+
* Creates an ORDER BY clause for a query
|
|
240
|
+
*
|
|
241
|
+
* This function creates an ORDER BY clause for a query. It takes an array of
|
|
242
|
+
* order by fields and returns a string with the fields separated by commas.
|
|
243
|
+
*
|
|
244
|
+
* @param orderBy - The array of order by fields
|
|
245
|
+
* @returns A string with the fields separated by commas
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const orderBy = [{ field: 'created_at', direction: 'DESC' }]
|
|
249
|
+
* const result = createOrderByClause(orderBy)
|
|
250
|
+
* // result will be: "ORDER BY created_at DESC"
|
|
251
|
+
*/
|
|
127
252
|
const createOrderByClause = (orderBy) => {
|
|
128
253
|
if (!orderBy || orderBy.length === 0)
|
|
129
254
|
return '';
|
|
@@ -131,18 +256,60 @@ const createOrderByClause = (orderBy) => {
|
|
|
131
256
|
return ` ORDER BY ${clause}`;
|
|
132
257
|
};
|
|
133
258
|
exports.createOrderByClause = createOrderByClause;
|
|
259
|
+
/**
|
|
260
|
+
* Creates a GROUP BY clause for a query
|
|
261
|
+
*
|
|
262
|
+
* This function creates a GROUP BY clause for a query. It takes an array of
|
|
263
|
+
* group by fields and returns a string with the fields separated by commas.
|
|
264
|
+
*
|
|
265
|
+
* @param groupBy - The array of group by fields
|
|
266
|
+
* @returns A string with the fields separated by commas
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* const groupBy = ['status']
|
|
270
|
+
* const result = createGroupByClause(groupBy)
|
|
271
|
+
* // result will be: "GROUP BY status"
|
|
272
|
+
*/
|
|
134
273
|
const createGroupByClause = (groupBy) => {
|
|
135
274
|
if (!groupBy || groupBy.length === 0)
|
|
136
275
|
return '';
|
|
137
276
|
return ` GROUP BY ${groupBy.join(', ')}`;
|
|
138
277
|
};
|
|
139
278
|
exports.createGroupByClause = createGroupByClause;
|
|
279
|
+
/**
|
|
280
|
+
* Creates a LIMIT clause for a query
|
|
281
|
+
*
|
|
282
|
+
* This function creates a LIMIT clause for a query. It takes a limit number
|
|
283
|
+
* and returns a string with the limit.
|
|
284
|
+
*
|
|
285
|
+
* @param limit - The limit number
|
|
286
|
+
* @returns A string with the limit
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* const limit = 10
|
|
290
|
+
* const result = createLimitClause(limit)
|
|
291
|
+
* // result will be: "LIMIT 10"
|
|
292
|
+
*/
|
|
140
293
|
const createLimitClause = (limit) => {
|
|
141
294
|
if (!limit)
|
|
142
295
|
return '';
|
|
143
296
|
return ` LIMIT ${limit}`;
|
|
144
297
|
};
|
|
145
298
|
exports.createLimitClause = createLimitClause;
|
|
299
|
+
/**
|
|
300
|
+
* Creates an OFFSET clause for a query
|
|
301
|
+
*
|
|
302
|
+
* This function creates an OFFSET clause for a query. It takes an offset number
|
|
303
|
+
* and returns a string with the offset.
|
|
304
|
+
*
|
|
305
|
+
* @param offset - The offset number
|
|
306
|
+
* @returns A string with the offset
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* const offset = 10
|
|
310
|
+
* const result = createOffsetClause(offset)
|
|
311
|
+
* // result will be: "OFFSET 10"
|
|
312
|
+
*/
|
|
146
313
|
const createOffsetClause = (offset) => {
|
|
147
314
|
if (!offset)
|
|
148
315
|
return '';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,uBAAuB,GAAG,CAC9B,KAAe,EACf,UAAqB,EACb,EAAE;IACV,MAAM,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACzC,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAC5C,CAAA;IACD,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAA;AAE7D;;;;;;;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E,OAAO,aAAa,MAAM,EAAE,CAAA;AAC9B,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B;AAED;;;;;;;;;;;;;GAaG;AACI,MAAM,mBAAmB,GAAG,CAAC,OAAkB,EAAE,EAAE;IACxD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAC/C,OAAO,aAAa,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1C,CAAC,CAAA;AAHY,QAAA,mBAAmB,uBAG/B;AAED;;;;;;;;;;;;;GAaG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAE,EAAE;IAClD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IACrB,OAAO,UAAU,KAAK,EAAE,CAAA;AAC1B,CAAC,CAAA;AAHY,QAAA,iBAAiB,qBAG7B;AAED;;;;;;;;;;;;;GAaG;AACI,MAAM,kBAAkB,GAAG,CAAC,MAAe,EAAE,EAAE;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAA;IACtB,OAAO,WAAW,MAAM,EAAE,CAAA;AAC5B,CAAC,CAAA;AAHY,QAAA,kBAAkB,sBAG9B"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { DBClients } from '../
|
|
1
|
+
import { DBClients } from '../core/types';
|
|
2
|
+
export interface ITransactionClient {
|
|
3
|
+
query: <T>(sql: string, params?: any[]) => Promise<T>;
|
|
4
|
+
commit: () => Promise<void>;
|
|
5
|
+
rollback: () => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Database client interface
|
|
9
|
+
*/
|
|
2
10
|
export type IDatabaseClient = {
|
|
3
11
|
clientType: DBClients;
|
|
4
12
|
query: <T>(sql: string, params?: any[]) => Promise<T>;
|
|
13
|
+
beginTransaction: () => Promise<ITransactionClient>;
|
|
5
14
|
};
|
package/dist/src/db/initDb.d.ts
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
import { IDatabaseClient } from './IDatabaseClient';
|
|
2
|
-
import { DBClients, RetryOptions } from '../
|
|
2
|
+
import { DBClients, RetryOptions } from '../core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize a database client with the specified configuration
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of connection options (PoolConfig for PostgreSQL or PoolOptions for MySQL)
|
|
7
|
+
* @param config - Configuration object for database initialization
|
|
8
|
+
* @param config.name - Optional name for the database client (defaults to 'default')
|
|
9
|
+
* @param config.type - Database type ('pg' for PostgreSQL or 'mysql' for MySQL)
|
|
10
|
+
* @param config.options - Connection options specific to the database type
|
|
11
|
+
* @param config.retryOptions - Optional retry configuration for failed queries
|
|
12
|
+
* @param config.installUnaccentExtension - Optional flag to install unaccent extension (PostgreSQL only)
|
|
13
|
+
* @returns Promise<void> - Resolves when the database client is successfully initialized
|
|
14
|
+
*
|
|
15
|
+
* @throws {Error} When type is not provided or is invalid
|
|
16
|
+
* @throws {Error} When connection options are not provided
|
|
17
|
+
* @throws {Error} When an unsupported database type is specified
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Initialize PostgreSQL client
|
|
21
|
+
* await initDb({
|
|
22
|
+
* name: 'myPostgresDb',
|
|
23
|
+
* type: 'pg',
|
|
24
|
+
* options: {
|
|
25
|
+
* host: 'localhost',
|
|
26
|
+
* port: 5432,
|
|
27
|
+
* database: 'mydb',
|
|
28
|
+
* user: 'user',
|
|
29
|
+
* password: 'password'
|
|
30
|
+
* },
|
|
31
|
+
* retryOptions: { maxRetries: 3, delay: 1000 },
|
|
32
|
+
* installUnaccentExtension: true
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Initialize MySQL client
|
|
37
|
+
* await initDb({
|
|
38
|
+
* name: 'myMysqlDb',
|
|
39
|
+
* type: 'mysql',
|
|
40
|
+
* options: {
|
|
41
|
+
* host: 'localhost',
|
|
42
|
+
* port: 3306,
|
|
43
|
+
* database: 'mydb',
|
|
44
|
+
* user: 'user',
|
|
45
|
+
* password: 'password'
|
|
46
|
+
* },
|
|
47
|
+
* retryOptions: { maxRetries: 3, delay: 1000 }
|
|
48
|
+
* });
|
|
49
|
+
*/
|
|
3
50
|
export declare const initDb: <T>(config: {
|
|
4
51
|
name?: string;
|
|
5
52
|
type: DBClients;
|
|
@@ -7,5 +54,77 @@ export declare const initDb: <T>(config: {
|
|
|
7
54
|
retryOptions?: RetryOptions;
|
|
8
55
|
installUnaccentExtension?: boolean;
|
|
9
56
|
}) => Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Initialize a database client with the specified configuration
|
|
59
|
+
*
|
|
60
|
+
* @template T - The type of connection options (PoolConfig for PostgreSQL or PoolOptions for MySQL)
|
|
61
|
+
* @param config - Configuration object for database initialization
|
|
62
|
+
* @param config.name - Optional name for the database client (defaults to 'default')
|
|
63
|
+
* @param config.type - Database type ('pg' for PostgreSQL or 'mysql' for MySQL)
|
|
64
|
+
* @param config.options - Connection options specific to the database type
|
|
65
|
+
* @param config.retryOptions - Optional retry configuration for failed queries
|
|
66
|
+
* @param config.installUnaccentExtension - Optional flag to install unaccent extension (PostgreSQL only)
|
|
67
|
+
* @returns Promise<void> - Resolves when the database client is successfully initialized
|
|
68
|
+
*
|
|
69
|
+
* @throws {Error} When database type is not provided or is invalid
|
|
70
|
+
* @throws {Error} When connection options are not provided
|
|
71
|
+
* @throws {Error} When an unsupported database type is specified
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Initialize PostgreSQL client
|
|
75
|
+
* await initDb({
|
|
76
|
+
* name: 'myPostgresDb',
|
|
77
|
+
* type: 'pg',
|
|
78
|
+
* options: {
|
|
79
|
+
* host: 'localhost',
|
|
80
|
+
* port: 5432,
|
|
81
|
+
* database: 'mydb',
|
|
82
|
+
* user: 'user',
|
|
83
|
+
* password: 'password'
|
|
84
|
+
* },
|
|
85
|
+
* retryOptions: { maxRetries: 3, delay: 1000 },
|
|
86
|
+
* installUnaccentExtension: true
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* // Initialize MySQL client
|
|
91
|
+
* await initDb({
|
|
92
|
+
* name: 'myMysqlDb',
|
|
93
|
+
* type: 'mysql',
|
|
94
|
+
* options: {
|
|
95
|
+
* host: 'localhost',
|
|
96
|
+
* port: 3306,
|
|
97
|
+
* database: 'mydb',
|
|
98
|
+
* user: 'user',
|
|
99
|
+
* password: 'password'
|
|
100
|
+
* },
|
|
101
|
+
* retryOptions: { maxRetries: 3, delay: 1000 }
|
|
102
|
+
* });
|
|
103
|
+
*/
|
|
10
104
|
export declare const getDbClient: (name?: string) => IDatabaseClient;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a specific database client by name
|
|
107
|
+
*
|
|
108
|
+
* @param name - Optional name of the database client to retrieve. If not provided, returns the default client
|
|
109
|
+
* @returns IDatabaseClient - The requested database client instance
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} When the specified database client name is not found or not initialized
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Get default database client
|
|
115
|
+
* const defaultClient = getDbClient();
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // Get specific database client by name
|
|
119
|
+
* const postgresClient = getDbClient('myPostgresDb');
|
|
120
|
+
* const mysqlClient = getDbClient('myMysqlDb');
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Handle error when client is not found
|
|
124
|
+
* try {
|
|
125
|
+
* const client = getDbClient('nonExistentDb');
|
|
126
|
+
* } catch (error) {
|
|
127
|
+
* console.error('Database client not found:', error.message);
|
|
128
|
+
* }
|
|
129
|
+
*/
|
|
11
130
|
export declare const getAllDbClients: () => Record<string, IDatabaseClient>;
|