wip: get database credential by single env that also used by prisma

This commit is contained in:
Supan Adit Pratama 2024-11-05 00:11:42 +07:00
parent fb87cc03af
commit ea551f8730
4 changed files with 560 additions and 72 deletions

View File

@ -33,7 +33,7 @@ import {
ISkeletonPaginationController,
ISkeletonReadController,
ISkeletonUpdateController,
} from './interfaces/controller/skeleton-crud.controller.interface';
} from '@aditama-labs/nest-autocrud/skeleton/src/interfaces';
export class SkeletonDetailController implements ISkeletonReadController {
constructor(

595
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -35,12 +35,15 @@
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"@prisma/client": "^5.21.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"esm": "^3.2.25",
"pg": "^8.13.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"typeorm": "^0.3.20"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
@ -92,4 +95,4 @@
"^@aditama-labs/nest-autocrud/prisma(|/.*)$": "<rootDir>/libs/prisma/$1"
}
}
}
}

View File

@ -1,9 +1,35 @@
import { Module } from '@nestjs/common';
import { SimpleModule } from './example/simple/simple.module';
import { CustomModule } from './example/custom/custom.module';
import { TypeOrmModule } from '@nestjs/typeorm';
const getDatabaseCredential = (): any => {
const url = new URL(process.env.DATABASE_URL);
// Extract the necessary components
const username = url.username;
const password = url.password;
const host = url.hostname;
const port = url.port;
const databaseName = url.pathname.substring(1); // Remove the leading slash
return {
type: 'postgres',
host: host,
port: port,
username: username,
password: password,
database: databaseName,
entities: [],
synchronize: true,
};
};
@Module({
imports: [SimpleModule, CustomModule],
imports: [
SimpleModule,
CustomModule,
TypeOrmModule.forRoot(getDatabaseCredential()),
],
controllers: [],
providers: [],
})