Skip to content

Backend: PDO models base class and query helpers #35

@Manak-hash

Description

@Manak-hash

Description

Build a lightweight base Model class using PDO to standardize database queries across all controllers. This avoids repeating boilerplate PDO code in every controller and makes the backend easier to maintain.

Tasks

  • Create models/Model.php — base class with:
    • Static db() method returning the PDO instance from config/database.php
    • findById($table, $id) helper
    • findAll($table, $conditions, $params) helper
    • insert($table, $data) — returns last insert ID
    • update($table, $data, $where, $params) helper
    • delete($table, $where, $params) helper
    • All queries use prepared statements
  • Create individual model classes that extend base:
    • models/User.php
    • models/Project.php
    • models/Application.php
    • models/Skill.php
    • models/Notification.php
    • models/Bookmark.php
  • Each model has domain-specific methods (e.g. Project::findBySlug(), User::findByEmail())
  • Create helpers/Validator.php with reusable validation helpers:
    • required($fields, $data)
    • email($value)
    • minLength($value, $min)
    • inArray($value, $allowed)

Acceptance Criteria

  • All models extend base Model
  • No raw SQL strings outside of model files
  • All queries use prepared statements (no string interpolation)
  • Validator helpers work correctly for common field types

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions