This document lists all the SQL queries used in the application after removing TypeORM.
INSERT INTO users (email, password, "firstName", "lastName")
VALUES ($1, $2, $3, $4)
RETURNING id, email, password, "firstName", "lastName", "isVerified", "createdAt", "updatedAt"Parameters:
- $1: email (string)
- $2: hashed password (string)
- $3: firstName (string)
- $4: lastName (string)
Returns: Full user object
Usage: UsersService.create(email, password, firstName, lastName)
SELECT id, email, password, "firstName", "lastName", "isVerified", "createdAt", "updatedAt"
FROM users
WHERE email = $1Parameters:
- $1: email (string)
Returns: User object or throws NotFoundException
Usage: UsersService.findByEmail(email)
SELECT id, email, password, "firstName", "lastName", "isVerified", "createdAt", "updatedAt"
FROM users
WHERE id = $1Parameters:
- $1: id (UUID string)
Returns: User object or throws NotFoundException
Usage: UsersService.findById(id)
CREATE INDEX idx_users_email ON users(email)Purpose: Optimizes findByEmail() queries for faster lookups
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
"firstName" VARCHAR(255) NOT NULL,
"lastName" VARCHAR(255) NOT NULL,
"isVerified" BOOLEAN DEFAULT false,
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)All queries use parameterized statements ($1, $2, etc.) which:
- Prevent SQL injection attacks
- Are handled by the pg library
- Automatically escape special characters
All queries are executed through DatabaseService.query(text, params):
const result = await this.databaseService.query(queryText, [param1, param2, ...]);
// result.rows contains the returned rows
// result.rowCount contains the number of affected rowsFor operations requiring transactions:
await this.databaseService.transaction(async (client) => {
// Execute multiple queries within the transaction
await client.query(queryText1, params1);
await client.query(queryText2, params2);
// Automatically commits on success or rolls back on error
});