Course Content
Data Structures & Algorithms
Low Level System Design
LLD Topics
High Level Design
DSA, High & Low Level System Designs
About Lesson
Class Diagram: SQL Query Builder

Classes:

  1. QueryBuilder
  2. User
  3. DatabaseConnection
  4. Query
  5. Table
  6. Column
  7. Filter
  8. Join
  9. ExportService
  10. AuthenticationService

 
Explanation of the Classes:

QueryBuilder:

 

  • Central class responsible for building the SQL query.
  • Manages tables, filters, and joins.
  • Methods include:
      • buildQuery(): Generates the SQL query.

      • addTable(), addFilter(), addJoin(): Add tables, filters, or joins to the query.

      • executeQuery(): Executes the generated SQL query.

 

User:

 

  • Represents a user of the SQL Query Builder system.
  • Contains username, password, and role (e.g., admin, analyst).
  • User authentication is handled by the AuthenticationService.

 

AuthenticationService:

 

  • Handles user login and role-based authentication.
  • Method: authenticate(), which checks the user’s credentials.

 

DatabaseConnection:

 

  • Represents the connection to the database where the query will be executed.
  • This class would typically manage the connection pool and handle database interactions.

 

Query:

 

  • Represents the generated SQL query.
  • Contains the raw queryText and the result returned after execution.
  • Method: execute(), which executes the query on the database.

 

Table:

 

  • Represents a database table in the SQL query.
  • Contains tableName and a list of columns.
  • Method: addColumn(), which adds columns to the table.

 

Column:

 

  • Represents a column in a table.
  • Contains columnName and dataType.
  • Provides a method to return the column name (getColumnName()).

 

Filter:

 

  • Represents a filter or condition in the WHERE clause of the SQL query.
  • Contains the condition as a string (e.g., “age > 30”).
  • Method: apply(), which applies the filter to the query.

 

Join:

 

  • Represents a JOIN operation in SQL (e.g., INNER JOIN, LEFT JOIN).
  • Contains joinType (INNER, LEFT, etc.) and joinCondition.
  • Method: applyJoin(), which adds the join to the SQL query.

 

ExportService:

 

  • Responsible for exporting the query results into different formats (e.g., CSV, Excel).
  • Method: export(), which exports the results in the specified format.


How to Explain to Your Students:

Start with the Core Class – QueryBuilder:

  • This is the class that brings everything together. It builds and executes SQL queries based on user input.

 

Explain Relationships:

  • QueryBuilder has relationships with Table, Filter, and Join classes to build SQL components like SELECT, WHERE, and JOIN clauses.
  • The Query class holds the final query text and handles its execution.

 

Highlight the Role of User & Authentication:

  • Users interact with the QueryBuilder. Their roles are managed by the AuthenticationService.

 

Show Interaction with Database:

  • After building the query, the Query class handles its execution via the DatabaseConnection class.

 

Discuss Exporting Results:

  • After executing the query, the ExportService allows exporting results in various formats.
0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.