test-entity-library-asm 1.2.8 → 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/dist/index.d.ts +1 -2
- package/dist/index.js +26 -21
- package/package.json +1 -1
- package/src/index.ts +30 -22
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { DataSource } from 'typeorm';
|
|
2
|
-
import { IShowEntity } from './interfaces';
|
|
3
2
|
export declare function createDataBaseSource(): DataSource;
|
|
4
|
-
export declare function showEntity(
|
|
3
|
+
export declare function showEntity(entityName: string): any;
|
package/dist/index.js
CHANGED
|
@@ -4,35 +4,40 @@ exports.showEntity = exports.createDataBaseSource = void 0;
|
|
|
4
4
|
var dotenv_1 = require("dotenv");
|
|
5
5
|
var path_1 = require("path");
|
|
6
6
|
var typeorm_1 = require("typeorm");
|
|
7
|
+
var connection = null;
|
|
7
8
|
// DOCUMENTATION: Función para crear la conexión de la base de datos
|
|
8
9
|
// AUTHOR: jgomezp97@gmail.com
|
|
9
10
|
function createDataBaseSource() {
|
|
10
11
|
var _a, _b;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
if (!connection) {
|
|
13
|
+
(0, dotenv_1.config)({ path: (0, path_1.resolve)(process.cwd(), '.env') });
|
|
14
|
+
connection = new typeorm_1.DataSource({
|
|
15
|
+
type: process.env.DB_TYPE,
|
|
16
|
+
host: process.env.DB_HOST,
|
|
17
|
+
port: parseInt((_a = process.env.DB_PORT) !== null && _a !== void 0 ? _a : ''),
|
|
18
|
+
username: process.env.DB_USERNAME,
|
|
19
|
+
password: (_b = process.env.DB_PASSWORD) !== null && _b !== void 0 ? _b : '',
|
|
20
|
+
database: process.env.DB_DATABASE,
|
|
21
|
+
synchronize: process.env.DB_SYNCHRONIZE === 'true',
|
|
22
|
+
entities: [
|
|
23
|
+
__dirname +
|
|
24
|
+
"/entities".concat(process.env.DB_ENTITIES_ROUTE
|
|
25
|
+
? "/".concat(process.env.DB_ENTITIES_ROUTE)
|
|
26
|
+
: '', "/*{.js,.ts}"),
|
|
27
|
+
],
|
|
28
|
+
subscribers: [],
|
|
29
|
+
migrations: [],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return connection;
|
|
30
33
|
}
|
|
31
34
|
exports.createDataBaseSource = createDataBaseSource;
|
|
32
35
|
// DOCUMENTATION: Función para retornar la entidad de una base de datos en específico por medio de un DataSource
|
|
33
36
|
// AUTHOR: jgomezp97@gmail.com
|
|
34
|
-
function showEntity(
|
|
35
|
-
|
|
37
|
+
function showEntity(entityName) {
|
|
38
|
+
if (!connection) {
|
|
39
|
+
connection = createDataBaseSource();
|
|
40
|
+
}
|
|
36
41
|
return connection.getRepository(entityName);
|
|
37
42
|
}
|
|
38
43
|
exports.showEntity = showEntity;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,34 +3,42 @@ import { resolve } from 'path'
|
|
|
3
3
|
import { DataSource } from 'typeorm'
|
|
4
4
|
import { IShowEntity, IType } from './interfaces'
|
|
5
5
|
|
|
6
|
+
let connection: DataSource | null = null
|
|
7
|
+
|
|
6
8
|
// DOCUMENTATION: Función para crear la conexión de la base de datos
|
|
7
9
|
// AUTHOR: jgomezp97@gmail.com
|
|
8
10
|
export function createDataBaseSource(): DataSource {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
if (!connection) {
|
|
12
|
+
config({ path: resolve(process.cwd(), '.env') })
|
|
13
|
+
connection = new DataSource({
|
|
14
|
+
type: process.env.DB_TYPE as unknown as IType,
|
|
15
|
+
host: process.env.DB_HOST,
|
|
16
|
+
port: parseInt(process.env.DB_PORT ?? ''),
|
|
17
|
+
username: process.env.DB_USERNAME,
|
|
18
|
+
password: process.env.DB_PASSWORD ?? '',
|
|
19
|
+
database: process.env.DB_DATABASE,
|
|
20
|
+
synchronize: process.env.DB_SYNCHRONIZE === 'true',
|
|
21
|
+
entities: [
|
|
22
|
+
__dirname +
|
|
23
|
+
`/entities${
|
|
24
|
+
process.env.DB_ENTITIES_ROUTE
|
|
25
|
+
? `/${process.env.DB_ENTITIES_ROUTE}`
|
|
26
|
+
: ''
|
|
27
|
+
}/*{.js,.ts}`,
|
|
28
|
+
],
|
|
29
|
+
subscribers: [],
|
|
30
|
+
migrations: [],
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
return connection
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
// DOCUMENTATION: Función para retornar la entidad de una base de datos en específico por medio de un DataSource
|
|
33
37
|
// AUTHOR: jgomezp97@gmail.com
|
|
34
|
-
export function showEntity(
|
|
38
|
+
export function showEntity(entityName: string): any {
|
|
39
|
+
if (!connection) {
|
|
40
|
+
connection = createDataBaseSource()
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
return connection.getRepository(entityName)
|
|
36
44
|
}
|