Skip to content

Instantly share code, notes, and snippets.

// 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,
//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',
// 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
}
// Firstly, we setup Database Connection
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'postgres',
import { IsString, IsInt } from 'class-validator';
export class CreateCatDto {
@IsString()
name: string;
@Length(10)
description: string;
}
@cacheManagerDecorator()
async getHello() {
return `Hello - ${new Date().toLocaleString()}`;
}
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');
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;
}
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'
{
"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,