test-entity-library-asm 1.0.0 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,35 @@
1
- import { IShowEntity } from './interfaces'
1
+ import { DataSource } from 'typeorm'
2
+ import { IDataBaseSource, IShowEntity } from './interfaces'
3
+
4
+ // DOCUMENTATION: Función para crear la conexión de la base de datos
5
+ // AUTHOR: jgomezp97@gmail.com
6
+ export function createDataBaseSource({
7
+ type,
8
+ host,
9
+ port,
10
+ username,
11
+ password,
12
+ database,
13
+ synchronize,
14
+ entitiesRoute,
15
+ }: IDataBaseSource): DataSource {
16
+ return new DataSource({
17
+ type: type ?? 'mysql',
18
+ host: host,
19
+ port: port,
20
+ username: username,
21
+ password: password,
22
+ database: database,
23
+ synchronize: synchronize,
24
+ logging: true,
25
+ entities: [__dirname + `/entities/${entitiesRoute}/*{.js,.ts}`],
26
+ subscribers: [],
27
+ migrations: [],
28
+ })
29
+ }
2
30
 
3
31
  // DOCUMENTATION: Función para retornar la entidad de una base de datos en específico por medio de un DataSource
32
+ // AUTHOR: jgomezp97@gmail.com
4
33
  export function showEntity({ entityName, connection }: IShowEntity): any {
5
34
  return connection.getRepository(entityName)
6
35
  }
package/src/interfaces.ts CHANGED
@@ -4,3 +4,16 @@ export interface IShowEntity {
4
4
  entityName: string
5
5
  connection: DataSource
6
6
  }
7
+
8
+ export interface IDataBaseSource {
9
+ type?: IType
10
+ host: string
11
+ port: number
12
+ username: string
13
+ password: string
14
+ database: string
15
+ synchronize: boolean
16
+ entitiesRoute: string
17
+ }
18
+
19
+ export type IType = 'mysql' | 'mariadb'