Posts

Showing posts with the label drizzle

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 ...

Guide to using Pothos GraphQL

Image
Introduction Pothos GraphQL is a GraphQL Schema Builder , which is a library that helps you write/define a GraphQL Schema using TypeScript code (a Code-First API approach). Functions Helps define each Query , Mutation and GraphQL Type using strongly typed TypeScript code, automatically catching errors to ensure 100% Type Safety . Pothos has a built-in plugin to connect with Drizzle (@pothos/plugin-drizzle) . You only need to declare tables in Drizzle corresponding to Objects in GraphQL and Pothos will automatically understand relations, pagination , helping you avoid writing complex SELECT/JOIN statements. Detail bun add @pothos/core @pothos/plugin-drizzle @pothos/plugin-zod Create file src/drizzle-orm/schema/schema.ts import {sql} from 'drizzle-orm' import { check, decimal, integer, pgTable, serial, text, timestamp, unique, varchar, } from 'drizzle-orm/pg-core' export const baseColumns = { id : serial ( 'id' ). primaryKe...