Posts

Showing posts with the label postgres

READ-THROUGH

Image
Introduction This article will guide you on implementing READ-THROUGH in NestJS with Redis and Postgres I will also use @nestjs/cache-manager to create an Abstraction layer That is a Cache Interceptor acting as the single source of truth where the app only needs to retrieve data from it. If the cache is unavailable, it will query the Database to fetch data and save it into the cache Regarding the theoretical content, you can review the previous article where I covered it Detail Please install the following packages bun add cache-manager cache-manager-redis-yet @nestjs/cache-manager Create file module/cache-manager.module.ts to create CacheManagerModule connecting to Redis . The app will view this as the data source and only fetch data from here import { CacheModule } from '@nestjs/cache-manager' import { Module } from '@nestjs/common' import { ConfigModule , ConfigService } from '@nestjs/config' import {redisStore} from 'cach...

REFRESH-AHEAD

Image
Introduction This article will guide you on how to implement REFRESH-AHEAD on NestJS with Redis and Postgres . We will need to use @nestjs/cache-manager to create a service that handles keys about to expire. We will also use @nestjs/bullmq for background processing to query the database and update the cache. For theoretical details, you can review the previous article where I covered this topic. Detail Create the file constant/index.ts with Queue, Job and Function as follows: export enum QueueName { CACHE_REFRESH = 'cache-refresh' , } export enum JobName { REFRESH_KEY = 'refresh-key' , } export enum FunctionName { PRODUCT_DETAIL = 'product-detail' , TRENDING_PRODUCT = 'trending-product' , } Create file module/bullmq.module.ts import { BullModule } from '@nestjs/bullmq' import { Module } from '@nestjs/common' import { ConfigModule , ConfigService } from '@nestjs/config' import { QueueName } f...

Implement GraphQL with Drizzle

Image
Introduction In the previous article, I guided you on how to use Drizzle to connect with Postgres . Now, we will continue using it to implement GraphQL . Next, we need to combine it with the following tools: drizzle-graphql This is the official library developed by the Drizzle ORM team itself to automatically generate a GraphQL Schema (including full Queries and Mutations ) from your Drizzle Schema . GraphQL Yoga Serves as an extremely lightweight and modern GraphQL Server Framework (replacing the older/heavier Apollo Server ). Functions: Listens for HTTP connections from the client (for example at port 4000/graphql ). Receives GraphQL (Query/Mutation) queries sent via POST requests. Executes handler functions ( Resolvers ) and returns JSON data to the client. Provides a built-in GraphiQL interface on the browser for you to test queries. Detail In this article, I will guide you on how to implement a simple CRUD GraphQL system. You only need to define the Schema and connect ...