CodeBlanks Logo Icon CodeBlanks

Summary - SQL database

Combine Pool, parameterized queries and transactions to write a sales API.

Summary - SQL database

In this group you learned PostgreSQL and Node.js: the pg module, connection pooling with Pool, security with parameterized queries, integrity with transactions, and ORM with Sequelize.

Raw SQL (pg) gives control; an ORM (Sequelize) gives speed. Small projects often use pg; large ones often use Sequelize. Both rely on parameterized queries and transactions as core tools. Security is never optional: always keep user data separate.

pg vs Sequelize

pg lets you write raw SQL; full control but more code. Sequelize generates SQL for you; less code but less control. The two can be used together.

The choice: pg for small or performance-critical projects; Sequelize for large teams and rapid development. If the ORM falls short on complex queries you can drop to raw SQL with sq.query(). The key point: whichever you pick, use parameterized queries.

Practice Log the type of Pool

Import the Pool class from pg. Log typeof Pool.

Starter code

index.js
// import the module, get the Pool class

// log its type

Sample solution

index.js
const { Pool } = require("pg");
console.log(typeof Pool);

Expected output

function

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the foundation of SQL database security?

  • Network acceleration
  • File compression
  • Updating CSS
  • Parametreli sorgu Correct answer

Explanation: Parameterized queries prevent SQL injection.

2 Match each piece to its role

Term Meaning
pg PostgreSQL client
Pool Connection pool
parameterized query Security
Sequelize ORM

All lessons in Advanced