@starbemtech/star-db-query-builder 1.0.0 → 1.0.1

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # star-db-query-builder
package/index.d.ts CHANGED
@@ -1,4 +1,14 @@
1
- import { QueryParams } from './src/default/types'
1
+ import { PoolConfig } from 'pg'
2
+ import { PoolOptions } from 'mysql2'
3
+ import { IDatabaseClient } from './src/db/IDatabaseClient'
4
+ import { DBClients, QueryParams } from './src/default/types'
5
+
6
+ // DB Clients Types
7
+ export declare type PgPoolConfig = PoolConfig
8
+ export declare type MySqlPoolOptions = PoolOptions
9
+
10
+ export declare function initDb<T>(config: { type: DBClients; options: T }): void
11
+ export declare function getDbClient(): IDatabaseClient
2
12
 
3
13
  export declare function findFirst<T>({
4
14
  tableName,
package/index.ts CHANGED
@@ -1,5 +1,12 @@
1
+ import { PoolConfig } from 'pg'
2
+ import { PoolOptions } from 'mysql2'
3
+
1
4
  // Configs
2
5
  export * from './src/db/initDb'
3
6
 
4
7
  // Generic Repository
5
8
  export * from './src/default/genericRepository'
9
+
10
+ // Types Definition
11
+ export type PgPoolConfig = PoolConfig
12
+ export type MySqlPoolOptions = PoolOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starbemtech/star-db-query-builder",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A query builder to be used with mysql or postgres",
5
5
  "author": "Julio Sousa <julio.sousa@starbem.app>",
6
6
  "main": "./dist/index.js",
package/src/db/initDb.ts CHANGED
@@ -3,10 +3,16 @@ import { createPool as createMySqlPool } from 'mysql2/promise'
3
3
  import { createPgClient } from './pgClient'
4
4
  import { createMysqlClient } from './mysqlClient'
5
5
  import { IDatabaseClient } from './IDatabaseClient'
6
+ import { DBClients } from '../default/types'
6
7
 
7
8
  let dbClient: IDatabaseClient | null = null
8
9
 
9
- export const initDb = (config: { type: 'pg' | 'mysql'; options: any }) => {
10
+ export const initDb = <T>(config: { type: DBClients; options: T }): void => {
11
+ if (!config.type)
12
+ throw new Error('Type is required. Accept values: pg | mysql')
13
+
14
+ if (!config.options) throw new Error('Connection options is required')
15
+
10
16
  if (config.type === 'pg') {
11
17
  const pool = new PgPool(config.options)
12
18
  dbClient = createPgClient(pool)
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- npm test