heath impl
This commit is contained in:
51
src/core/configs/dist/typeorm.oracle.config.js
vendored
Normal file
51
src/core/configs/dist/typeorm.oracle.config.js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.createOracleConfig = void 0;
|
||||
var oracledb = require("oracledb");
|
||||
// Inicializar o cliente Oracle
|
||||
oracledb.initOracleClient({ libDir: "C:\\oracle" });
|
||||
// Definir a estratégia de pool padrão para Oracle
|
||||
oracledb.poolTimeout = 60; // timeout do pool em segundos
|
||||
oracledb.queueTimeout = 60000; // timeout da fila em milissegundos
|
||||
oracledb.poolIncrement = 1; // incremental de conexões
|
||||
function createOracleConfig(config) {
|
||||
// Obter configurações de ambiente ou usar valores padrão
|
||||
var poolMin = parseInt(config.get('ORACLE_POOL_MIN', '5'));
|
||||
var poolMax = parseInt(config.get('ORACLE_POOL_MAX', '20'));
|
||||
var poolIncrement = parseInt(config.get('ORACLE_POOL_INCREMENT', '5'));
|
||||
var poolTimeout = parseInt(config.get('ORACLE_POOL_TIMEOUT', '30000'));
|
||||
var idleTimeout = parseInt(config.get('ORACLE_POOL_IDLE_TIMEOUT', '300000'));
|
||||
// Validação de valores mínimos
|
||||
var validPoolMin = Math.max(1, poolMin);
|
||||
var validPoolMax = Math.max(validPoolMin + 1, poolMax);
|
||||
var validPoolIncrement = Math.max(1, poolIncrement);
|
||||
// Certifique-se de que poolMax é maior que poolMin
|
||||
if (validPoolMax <= validPoolMin) {
|
||||
console.warn('Warning: poolMax deve ser maior que poolMin. Ajustando poolMax para poolMin + 1');
|
||||
}
|
||||
var options = {
|
||||
type: 'oracle',
|
||||
connectString: config.get('ORACLE_CONNECT_STRING'),
|
||||
username: config.get('ORACLE_USER'),
|
||||
password: config.get('ORACLE_PASSWORD'),
|
||||
synchronize: false,
|
||||
logging: config.get('NODE_ENV') === 'development',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
extra: {
|
||||
// Configurações de pool
|
||||
poolMin: validPoolMin,
|
||||
poolMax: validPoolMax,
|
||||
poolIncrement: validPoolIncrement,
|
||||
poolTimeout: Math.floor(poolTimeout / 1000),
|
||||
queueTimeout: 60000,
|
||||
enableStats: true,
|
||||
homogeneous: true,
|
||||
poolPingInterval: 60,
|
||||
stmtCacheSize: 30,
|
||||
connectionClass: 'PORTALJURU',
|
||||
idleTimeout: Math.floor(idleTimeout / 1000)
|
||||
}
|
||||
};
|
||||
return options;
|
||||
}
|
||||
exports.createOracleConfig = createOracleConfig;
|
||||
45
src/core/configs/dist/typeorm.postgres.config.js
vendored
Normal file
45
src/core/configs/dist/typeorm.postgres.config.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.createPostgresConfig = void 0;
|
||||
function createPostgresConfig(config) {
|
||||
// Obter configurações de ambiente ou usar valores padrão
|
||||
var poolMin = parseInt(config.get('POSTGRES_POOL_MIN', '5'));
|
||||
var poolMax = parseInt(config.get('POSTGRES_POOL_MAX', '20'));
|
||||
var idleTimeout = parseInt(config.get('POSTGRES_POOL_IDLE_TIMEOUT', '30000'));
|
||||
var connectionTimeout = parseInt(config.get('POSTGRES_POOL_CONNECTION_TIMEOUT', '5000'));
|
||||
var acquireTimeout = parseInt(config.get('POSTGRES_POOL_ACQUIRE_TIMEOUT', '60000'));
|
||||
// Validação de valores mínimos
|
||||
var validPoolMin = Math.max(1, poolMin);
|
||||
var validPoolMax = Math.max(validPoolMin + 1, poolMax);
|
||||
var validIdleTimeout = Math.max(1000, idleTimeout);
|
||||
var validConnectionTimeout = Math.max(1000, connectionTimeout);
|
||||
var validAcquireTimeout = Math.max(1000, acquireTimeout);
|
||||
var options = {
|
||||
type: 'postgres',
|
||||
host: config.get('POSTGRES_HOST'),
|
||||
port: parseInt(config.get('POSTGRES_PORT', '5432')),
|
||||
username: config.get('POSTGRES_USER'),
|
||||
password: config.get('POSTGRES_PASSWORD'),
|
||||
database: config.get('POSTGRES_DB'),
|
||||
synchronize: config.get('NODE_ENV') === 'development',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
ssl: config.get('NODE_ENV') === 'production' ? { rejectUnauthorized: false } : false,
|
||||
logging: config.get('NODE_ENV') === 'development',
|
||||
poolSize: validPoolMax,
|
||||
extra: {
|
||||
// Configuração de pool do PostgreSQL
|
||||
min: validPoolMin,
|
||||
max: validPoolMax,
|
||||
idleTimeoutMillis: validIdleTimeout,
|
||||
connectionTimeoutMillis: validConnectionTimeout,
|
||||
acquireTimeoutMillis: validAcquireTimeout,
|
||||
statement_timeout: 10000,
|
||||
query_timeout: 10000
|
||||
},
|
||||
cache: {
|
||||
duration: 60000
|
||||
}
|
||||
};
|
||||
return options;
|
||||
}
|
||||
exports.createPostgresConfig = createPostgresConfig;
|
||||
@@ -1,14 +1,56 @@
|
||||
import { DataSourceOptions } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as oracledb from 'oracledb';
|
||||
|
||||
// Inicializar o cliente Oracle
|
||||
oracledb.initOracleClient({ libDir: "C:\\oracle" });
|
||||
|
||||
// Definir a estratégia de pool padrão para Oracle
|
||||
oracledb.poolTimeout = 60; // timeout do pool em segundos
|
||||
oracledb.queueTimeout = 60000; // timeout da fila em milissegundos
|
||||
oracledb.poolIncrement = 1; // incremental de conexões
|
||||
|
||||
export function createOracleConfig(config: ConfigService): DataSourceOptions {
|
||||
return {
|
||||
// Obter configurações de ambiente ou usar valores padrão
|
||||
const poolMin = parseInt(config.get('ORACLE_POOL_MIN', '5'));
|
||||
const poolMax = parseInt(config.get('ORACLE_POOL_MAX', '20'));
|
||||
const poolIncrement = parseInt(config.get('ORACLE_POOL_INCREMENT', '5'));
|
||||
const poolTimeout = parseInt(config.get('ORACLE_POOL_TIMEOUT', '30000'));
|
||||
const idleTimeout = parseInt(config.get('ORACLE_POOL_IDLE_TIMEOUT', '300000'));
|
||||
|
||||
// Validação de valores mínimos
|
||||
const validPoolMin = Math.max(1, poolMin);
|
||||
const validPoolMax = Math.max(validPoolMin + 1, poolMax);
|
||||
const validPoolIncrement = Math.max(1, poolIncrement);
|
||||
|
||||
// Certifique-se de que poolMax é maior que poolMin
|
||||
if (validPoolMax <= validPoolMin) {
|
||||
console.warn('Warning: poolMax deve ser maior que poolMin. Ajustando poolMax para poolMin + 1');
|
||||
}
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
type: 'oracle',
|
||||
connectString: config.get('ORACLE_CONNECT_STRING'),
|
||||
username: config.get('ORACLE_USER'),
|
||||
password: config.get('ORACLE_PASSWORD'),
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
logging: config.get('NODE_ENV') === 'development',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
extra: {
|
||||
// Configurações de pool
|
||||
poolMin: validPoolMin,
|
||||
poolMax: validPoolMax,
|
||||
poolIncrement: validPoolIncrement,
|
||||
poolTimeout: Math.floor(poolTimeout / 1000), // convertido para segundos (oracledb usa segundos)
|
||||
queueTimeout: 60000, // tempo máximo para esperar na fila
|
||||
enableStats: true, // habilita estatísticas do pool
|
||||
homogeneous: true, // todas as conexões usam o mesmo usuário
|
||||
poolPingInterval: 60, // intervalo de ping em segundos
|
||||
stmtCacheSize: 30, // tamanho do cache de statements
|
||||
connectionClass: 'PORTALJURU', // classe de conexão para identificação
|
||||
idleTimeout: Math.floor(idleTimeout / 1000), // tempo de idle em segundos
|
||||
},
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,46 @@ import { DataSourceOptions } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
export function createPostgresConfig(config: ConfigService): DataSourceOptions {
|
||||
return {
|
||||
// Obter configurações de ambiente ou usar valores padrão
|
||||
const poolMin = parseInt(config.get('POSTGRES_POOL_MIN', '5'));
|
||||
const poolMax = parseInt(config.get('POSTGRES_POOL_MAX', '20'));
|
||||
const idleTimeout = parseInt(config.get('POSTGRES_POOL_IDLE_TIMEOUT', '30000'));
|
||||
const connectionTimeout = parseInt(config.get('POSTGRES_POOL_CONNECTION_TIMEOUT', '5000'));
|
||||
const acquireTimeout = parseInt(config.get('POSTGRES_POOL_ACQUIRE_TIMEOUT', '60000'));
|
||||
|
||||
// Validação de valores mínimos
|
||||
const validPoolMin = Math.max(1, poolMin);
|
||||
const validPoolMax = Math.max(validPoolMin + 1, poolMax);
|
||||
const validIdleTimeout = Math.max(1000, idleTimeout);
|
||||
const validConnectionTimeout = Math.max(1000, connectionTimeout);
|
||||
const validAcquireTimeout = Math.max(1000, acquireTimeout);
|
||||
|
||||
const options: DataSourceOptions = {
|
||||
type: 'postgres',
|
||||
host: config.get('POSTGRES_HOST'),
|
||||
port: config.get('POSTGRES_PORT'),
|
||||
port: parseInt(config.get('POSTGRES_PORT', '5432')),
|
||||
username: config.get('POSTGRES_USER'),
|
||||
password: config.get('POSTGRES_PASSWORD'),
|
||||
database: config.get('POSTGRES_DB'),
|
||||
synchronize: true,
|
||||
synchronize: config.get('NODE_ENV') === 'development',
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
ssl: config.get('NODE_ENV') === 'production' ? { rejectUnauthorized: false } : false,
|
||||
logging: config.get('NODE_ENV') === 'development',
|
||||
poolSize: validPoolMax, // máximo de conexões no pool
|
||||
extra: {
|
||||
// Configuração de pool do PostgreSQL
|
||||
min: validPoolMin, // mínimo de conexões no pool
|
||||
max: validPoolMax, // máximo de conexões no pool
|
||||
idleTimeoutMillis: validIdleTimeout, // tempo máximo de inatividade antes de fechar
|
||||
connectionTimeoutMillis: validConnectionTimeout, // tempo máximo para conectar
|
||||
acquireTimeoutMillis: validAcquireTimeout, // tempo máximo para adquirir uma conexão
|
||||
statement_timeout: 10000, // tempo máximo para executar uma query (10 segundos)
|
||||
query_timeout: 10000, // tempo máximo para executar uma query (10 segundos)
|
||||
},
|
||||
cache: {
|
||||
duration: 60000, // cache de consultas por 1 minuto
|
||||
},
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
82
src/core/database/dist/database.module.js
vendored
82
src/core/database/dist/database.module.js
vendored
@@ -1,82 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.DatabaseModule = void 0;
|
||||
var common_1 = require("@nestjs/common");
|
||||
var config_1 = require("@nestjs/config");
|
||||
var typeorm_1 = require("typeorm");
|
||||
var constants_1 = require("../constants");
|
||||
var typeorm_oracle_config_1 = require("../configs/typeorm.oracle.config");
|
||||
var DatabaseModule = /** @class */ (function () {
|
||||
function DatabaseModule() {
|
||||
}
|
||||
DatabaseModule = __decorate([
|
||||
common_1.Global(),
|
||||
common_1.Module({
|
||||
imports: [config_1.ConfigModule],
|
||||
providers: [
|
||||
{
|
||||
provide: constants_1.DATA_SOURCE,
|
||||
useFactory: function (configService) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var dataSource;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
dataSource = new typeorm_1.DataSource(typeorm_oracle_config_1.createOracleConfig(configService));
|
||||
return [4 /*yield*/, dataSource.initialize()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, dataSource];
|
||||
}
|
||||
});
|
||||
}); },
|
||||
inject: [config_1.ConfigService]
|
||||
},
|
||||
],
|
||||
exports: [constants_1.DATA_SOURCE]
|
||||
})
|
||||
], DatabaseModule);
|
||||
return DatabaseModule;
|
||||
}());
|
||||
exports.DatabaseModule = DatabaseModule;
|
||||
Reference in New Issue
Block a user