test-entity-library-asm 1.2.4 → 1.2.5

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 CHANGED
@@ -1,2 +1,7 @@
1
1
  # test-entity-library-asm
2
+
2
3
  Test de librería para probar las entidades de la base de datos asumano
4
+
5
+ # Crear una nueva migración
6
+
7
+ Para crear una nueva migración hay qué ejecutar el comando `typeorm migration:create ./src/migrations/nueva`
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { DataSource } from 'typeorm';
2
- import { IDataBaseSource, IShowEntity } from './interfaces';
3
- export declare function createDataBaseSource({ type, host, port, username, password, database, synchronize, entitiesRoute, }: IDataBaseSource): DataSource;
2
+ import { IShowEntity } from './interfaces';
3
+ export declare function createDataBaseSource(): DataSource;
4
4
  export declare function showEntity({ entityName, connection }: IShowEntity): any;
package/dist/index.js CHANGED
@@ -1,23 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.showEntity = exports.createDataBaseSource = void 0;
4
+ var dotenv_1 = require("dotenv");
5
+ var path_1 = require("path");
4
6
  var typeorm_1 = require("typeorm");
5
7
  // DOCUMENTATION: Función para crear la conexión de la base de datos
6
8
  // AUTHOR: jgomezp97@gmail.com
7
- function createDataBaseSource(_a) {
8
- var type = _a.type, host = _a.host, port = _a.port, username = _a.username, password = _a.password, database = _a.database, synchronize = _a.synchronize, entitiesRoute = _a.entitiesRoute;
9
+ function createDataBaseSource() {
10
+ var _a;
11
+ (0, dotenv_1.config)({ path: (0, path_1.resolve)(process.cwd(), '.env') });
9
12
  return new typeorm_1.DataSource({
10
- type: type !== null && type !== void 0 ? type : 'mysql',
11
- host: host,
12
- port: port,
13
- username: username,
14
- password: password,
15
- database: database,
16
- synchronize: synchronize,
17
- // logging: true,
13
+ type: process.env.DB_TYPE,
14
+ host: process.env.DB_HOST,
15
+ port: parseInt((_a = process.env.DB_PORT) !== null && _a !== void 0 ? _a : ''),
16
+ username: process.env.DB_USERNAME,
17
+ password: process.env.DB_PASSWORD,
18
+ database: process.env.DB_DATABASE,
19
+ synchronize: process.env.DB_SYNCHRONIZE === 'true',
18
20
  entities: [
19
21
  __dirname +
20
- "/entities".concat(entitiesRoute ? "/".concat(entitiesRoute) : '', "/*{.js,.ts}"),
22
+ "/entities".concat(process.env.DB_ENTITIES_ROUTE
23
+ ? "/".concat(process.env.DB_ENTITIES_ROUTE)
24
+ : '', "/*{.js,.ts}"),
21
25
  ],
22
26
  subscribers: [],
23
27
  migrations: [],
package/ormconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "type": "${DB_TYPE}",
3
+ "migrations": [
4
+ "src/migrations/*.ts"
5
+ ],
6
+ "cli": {
7
+ "entitiesDir": "src/entities",
8
+ "migrationsDir": "src/migrations"
9
+ },
10
+ "driver": "mysql2"
11
+ }
12
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,6 +11,7 @@
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
+ "dotenv": "^16.4.5",
14
15
  "typeorm": "^0.3.20"
15
16
  },
16
17
  "devDependencies": {
package/src/index.ts CHANGED
@@ -1,30 +1,27 @@
1
+ import { config } from 'dotenv'
2
+ import { resolve } from 'path'
1
3
  import { DataSource } from 'typeorm'
2
- import { IDataBaseSource, IShowEntity } from './interfaces'
4
+ import { IShowEntity, IType } from './interfaces'
3
5
 
4
6
  // DOCUMENTATION: Función para crear la conexión de la base de datos
5
7
  // 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 {
8
+ export function createDataBaseSource(): DataSource {
9
+ config({ path: resolve(process.cwd(), '.env') })
16
10
  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,
11
+ type: process.env.DB_TYPE as unknown as IType,
12
+ host: process.env.DB_HOST,
13
+ port: parseInt(process.env.DB_PORT ?? ''),
14
+ username: process.env.DB_USERNAME,
15
+ password: process.env.DB_PASSWORD,
16
+ database: process.env.DB_DATABASE,
17
+ synchronize: process.env.DB_SYNCHRONIZE === 'true',
25
18
  entities: [
26
19
  __dirname +
27
- `/entities${entitiesRoute ? `/${entitiesRoute}` : ''}/*{.js,.ts}`,
20
+ `/entities${
21
+ process.env.DB_ENTITIES_ROUTE
22
+ ? `/${process.env.DB_ENTITIES_ROUTE}`
23
+ : ''
24
+ }/*{.js,.ts}`,
28
25
  ],
29
26
  subscribers: [],
30
27
  migrations: [],