feat: Add Oracle database integration with TypeORM and client initialization for the NestJS application.
This commit is contained in:
parent
c60a7925cc
commit
f2e46a602e
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { DataSource } from 'typeorm';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
|
||||||
|
export const AppDataSource = new DataSource({
|
||||||
|
type: 'oracle',
|
||||||
|
username: process.env.DB_USERNAME || 'teste',
|
||||||
|
password: process.env.DB_PASSWORD || 'teste',
|
||||||
|
connectString:
|
||||||
|
process.env.DB_CONNECT_STRING ||
|
||||||
|
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.1.241)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=BDTESTE)))',
|
||||||
|
synchronize: false,
|
||||||
|
logging: true,
|
||||||
|
entities: [__dirname + '/../**/*.{entity,view}.{js,ts}'],
|
||||||
|
subscribers: [process.env.DB_SUBSCRIBERS_PATH || 'dist/subscriber/*.js'],
|
||||||
|
extra: {
|
||||||
|
poolSize: parseInt(process.env.DB_POOL_SIZE || '10', 10),
|
||||||
|
maxRows: parseInt(process.env.DB_MAX_ROWS || '1000', 10),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as oracledb from 'oracledb';
|
||||||
|
|
||||||
|
export function initializeOracleClient(): void {
|
||||||
|
try {
|
||||||
|
const oracleClientPath = process.env.ORACLE_CLIENT_PATH;
|
||||||
|
const libDir =
|
||||||
|
oracleClientPath && fs.existsSync(path.normalize(oracleClientPath))
|
||||||
|
? path.normalize(oracleClientPath)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
oracledb.initOracleClient(libDir ? { libDir } : undefined);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||||
|
console.warn(
|
||||||
|
'Oracle Client Thick mode initialization failed:',
|
||||||
|
errorMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { initializeOracleClient } from './helpers/oracle.helper';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
|
initializeOracleClient();
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue