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 +1 -1
- package/src/index.ts +30 -1
- package/src/interfaces.ts +13 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
import {
|
|
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'
|