@starbemtech/star-db-query-builder 1.0.35 → 1.0.36
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/coverage/clover.xml +2 -2
- package/coverage/lcov-report/index.html +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/db/initDb.ts +12 -6
package/coverage/clover.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<coverage generated="
|
|
3
|
-
<project timestamp="
|
|
2
|
+
<coverage generated="1745450914749" clover="3.2.0">
|
|
3
|
+
<project timestamp="1745450914749" name="All files">
|
|
4
4
|
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
|
|
5
5
|
</project>
|
|
6
6
|
</coverage>
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
87
87
|
Code coverage generated by
|
|
88
88
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
89
|
-
at 2025-04-23T23:
|
|
89
|
+
at 2025-04-23T23:28:34.744Z
|
|
90
90
|
</div>
|
|
91
91
|
<script src="prettify.js"></script>
|
|
92
92
|
<script>
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { IDatabaseClient } from './src/db/IDatabaseClient'
|
|
|
2
2
|
import { DBClients, QueryParams } from './src/default/types'
|
|
3
3
|
|
|
4
4
|
export declare function initDb<T>(config: { type: DBClients; options: T }): void
|
|
5
|
-
export declare function getDbClient(): IDatabaseClient
|
|
5
|
+
export declare function getDbClient(name?: string): IDatabaseClient
|
|
6
6
|
|
|
7
7
|
// Generic Methods
|
|
8
8
|
export declare function findFirst<T>({
|
package/package.json
CHANGED
package/src/db/initDb.ts
CHANGED
|
@@ -6,12 +6,14 @@ import { IDatabaseClient } from './IDatabaseClient'
|
|
|
6
6
|
import { DBClients, RetryOptions } from '../default/types'
|
|
7
7
|
|
|
8
8
|
const dbClients: Record<string, IDatabaseClient> = {}
|
|
9
|
+
const defaultName = 'default'
|
|
9
10
|
|
|
10
11
|
export const initDb = async <T>(config: {
|
|
11
|
-
name
|
|
12
|
+
name?: string
|
|
12
13
|
type: DBClients
|
|
13
14
|
options: T
|
|
14
15
|
retryOptions?: RetryOptions
|
|
16
|
+
installUnaccentExtension?: boolean
|
|
15
17
|
}): Promise<void> => {
|
|
16
18
|
if (!config.type)
|
|
17
19
|
throw new Error('Type is required. Accept values: pg | mysql')
|
|
@@ -21,10 +23,11 @@ export const initDb = async <T>(config: {
|
|
|
21
23
|
if (config.type === 'pg') {
|
|
22
24
|
const poolConfig = config.options as unknown as PoolConfig
|
|
23
25
|
const pool = new Pool(config.options)
|
|
24
|
-
dbClients[config.name] = await createPgClient(
|
|
26
|
+
dbClients[config.name || defaultName] = await createPgClient(
|
|
25
27
|
pool,
|
|
26
28
|
config.retryOptions,
|
|
27
|
-
poolConfig
|
|
29
|
+
poolConfig,
|
|
30
|
+
config.installUnaccentExtension
|
|
28
31
|
)
|
|
29
32
|
|
|
30
33
|
console.log(
|
|
@@ -32,7 +35,10 @@ export const initDb = async <T>(config: {
|
|
|
32
35
|
)
|
|
33
36
|
} else if (config.type === 'mysql') {
|
|
34
37
|
const pool = createMySqlPool(config.options)
|
|
35
|
-
dbClients[config.name] = createMysqlClient(
|
|
38
|
+
dbClients[config.name || defaultName] = createMysqlClient(
|
|
39
|
+
pool,
|
|
40
|
+
config.retryOptions
|
|
41
|
+
)
|
|
36
42
|
|
|
37
43
|
console.info(
|
|
38
44
|
`@starbemtech/star-db-query-builder: Postgres db client "${config.name}" created successfully`
|
|
@@ -42,8 +48,8 @@ export const initDb = async <T>(config: {
|
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
export const getDbClient = (name
|
|
46
|
-
const client = dbClients[name]
|
|
51
|
+
export const getDbClient = (name?: string): IDatabaseClient => {
|
|
52
|
+
const client = dbClients[name || defaultName]
|
|
47
53
|
if (!client) {
|
|
48
54
|
throw new Error(`Database client "${name}" is not initialized`)
|
|
49
55
|
}
|