Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • PostgreSQL Documentation40টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Postgres Intro
  • Relational Model
  • Install & Setup
  • Connect psql
  • SELECT basics
  • Data Types
  • Create Table
  • Constraints
  • INSERT / UPDATE / DELETE
  • NULL & COALESCE
  • Schema Design
  • Relationships
  • Joins
  • Joins Advanced
  • Aggregation
  • ORDER / LIMIT
  • String Functions
  • Date Functions
  • Subqueries
  • CTE (WITH)
  • Views
  • Window Functions
  • Transactions
  • Indexes
  • Performance
  • UPSERT
  • JSONB
  • Full-Text Search
  • Triggers
  • Roles & Privileges
  • Backup & Restore
  • Node + PostgreSQL
  • Prisma Intro
  • Prisma Migrations
  • TechShop Schema
  • TechShop Queries
  • TechShop API
  • Best Practices
  • Common Mistakes
  • Interview Questions
  1. Docs
  2. PostgreSQL
  3. node-postgres (pg) — Node.js থেকে query
PostgreSQLIntermediate

node-postgres (pg) — Node.js থেকে query

Node/Express-এ pg Pool — parameterized query দিয়ে নিরাপদ।

5টি অংশবাংলা ভাষায়
terminalbash
bash
npm install pg
db.tsts
ts
import { Pool } from "pg";

export const pool = new Pool({
  host: process.env.PGHOST ?? "localhost",
  port: 5432,
  database: process.env.PGDATABASE ?? "techshop",
  user: process.env.PGUSER ?? "app_user",
  password: process.env.PGPASSWORD ?? "secret",
});
import { pool } from "./db";

export async function findProduct(id: number) {
  const res = await pool.query(
    "SELECT id, name, price FROM products WHERE id = $1",
    [id]
  );
  return res.rows[0];
}
  • Pool — multiple connections, request-ভিত্তিক checkout
  • $1-placeholders + values array — SQL injection নিরাপদ
  • db.query-র আগে await, error catch
  • dotenv / env vars — credentials repository-তে নয়
string interpolation বারণ

SELECT ... WHERE id = ' + id — injection রাস্তা খোলা। সব query-তে $n parameter।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরBackup — pg_dump, pg_restoreপরেরPrisma — schema-driven ORM
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com