Posts

Showing posts with the label validation

NestJS Controller and Swagger Guide

Image
Introduction NestJS is a progressive Node.js framework built with TypeScript, facilitating the development of efficient and scalable server-side applications. By default, NestJS uses Express as its core HTTP processing library. Key advantages include a tight modular architecture inspired by Angular and strong TypeScript support to reduce code errors. Controllers serve as the layer for processing incoming requests and returning responses to the client side. Their primary responsibility is to receive HTTP requests, route data to business logic services, and coordinate the returned result in the correct format. Swagger is a powerful suite of tools used for designing, building, and documenting RESTful APIs developed based on the OpenAPI data format specification. In NestJS, it helps automatically generate an intuitive UI interface for testing endpoints, enabling developers and stakeholders to understand the API structure without directly reading the source code. Detail After creating the N...

Using TypeORM in a NestJS Project

Image
Introduction TypeORM is a powerful ORM (Object-Relational Mapper) library for the Node.js ecosystem, written in TypeScript. It allows developers to interact with databases using classes and objects instead of writing complex raw SQL queries. Key Advantages Excellent TypeScript support: Fully leverages decorators and type-checking, helping detect errors during development instead of at runtime. Supports multiple databases: Compatible with popular database management systems such as MySQL, PostgreSQL, SQLite, etc. Flexible patterns (Data Mapper & Active Record): Lets you choose the appropriate implementation style depending on project size (Data Mapper for large, complex projects; Active Record for smaller, quick projects). Migration management: Provides powerful tools to manage database schema changes systematically, helping synchronize changes across development teams. Query Builder: In addition to object-based operations, TypeORM provides a Query Builder for constructing complex q...

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