This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Firstly, import MikroOrmModule in App.module | |
@Module({ | |
imports: [MikroOrmModule.forRoot(), CatsModule], | |
}) | |
// The Database configuration is store in mikro-orm.config.ts | |
const config: Options = { | |
entities: [Cat], | |
dbName: 'postgres', | |
type: 'postgresql', | |
port: 5432, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Firstly, we create a Sequelize instance with an options object | |
export const databaseProviders = [ | |
{ | |
provide: 'SEQUELIZE', | |
useFactory: async () => { | |
const sequelize = new Sequelize({ | |
dialect: 'postgres', | |
host: 'localhost', | |
port: 5432, | |
username: 'postgres', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Firstly, we need a schema file to model the database | |
generator client { | |
provider = "prisma-client-js" | |
} | |
datasource db { | |
provider = "postgresql" | |
url = env("DATABASE_URL") // the DATABASE_URL is stored in .env file | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Firstly, we setup Database Connection | |
@Module({ | |
imports: [ | |
TypeOrmModule.forRoot({ | |
type: 'postgres', | |
host: 'localhost', | |
port: 5432, | |
username: 'postgres', | |
password: 'postgres', | |
database: 'postgres', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IsString, IsInt } from 'class-validator'; | |
export class CreateCatDto { | |
@IsString() | |
name: string; | |
@Length(10) | |
description: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@cacheManagerDecorator() | |
async getHello() { | |
return `Hello - ${new Date().toLocaleString()}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CACHE_MANAGER, Inject } from '@nestjs/common'; | |
export const cacheManagerDecorator = (ttl = 10) => { | |
const injectCache = Inject(CACHE_MANAGER); | |
return function ( | |
target: any, | |
_propertyName: string, | |
descriptor: PropertyDescriptor, | |
) { | |
injectCache(target, 'cache'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const value = await this.cacheManager.get('test-key'); | |
if (!value) { | |
const response = await this.getHello(); | |
this.cacheManager.set( | |
'test-key', | |
response, | |
{ ttl: 0 }, | |
); | |
return response; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const payGrades = { | |
low: "1", | |
average: "2", | |
high: "3" | |
} as const; | |
type t = typeof payGrades; | |
type payGradeType = keyof t; // 'low' | 'average' | 'high' | |
type payValueType = t[keyof t]; // '1' | '2' | '3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"active": true, | |
"author": "N/A", | |
"author_email": "N/A", | |
"complete": true, | |
"deployer": "ZipDeploy", | |
"end_time": "2022-02-27T21:58:45.0863404Z", | |
"id": "b3c4cbb7a470479ebd7a2c6dd17bd70f", | |
"is_readonly": true, | |
"is_temp": false, |