This project is a custom-built mini-ORM utility for managing database operations in a Node.js/TypeScript application. It includes features like query building, pagination, joins, and CRUD operations.
-
src/backend/persistence/: Contains the core persistence logic.persistence.repository.ts: Implements thePersistentRepositoryclass for database operations.persistence-contracts.ts: Defines interfaces and types for persistence operations.persistence-utils.ts: Utility functions for building SQL queries.persistence-where-operator.ts: Helper functions for buildingWHEREclauses.database-drivers/pg.client.ts: PostgreSQL database driver implementation.
-
src/backend/persistence-repositories.ts: Exports repository instances for specific database tables.
-
Dynamic Query Building:
- Supports
WHERE,ORDER BY,JOIN, and pagination. - Utility functions like
buildWhereClause,buildOrderByClause, andbuildJoinClause.
- Supports
-
CRUD Operations:
findRows,findRowCount,createOne,createMany,updateOne,deleteRows.
-
Error Handling:
- Custom error classes like
PersistenceDriverError.
- Custom error classes like
-
Database Driver:
- Uses PostgreSQL (
pgpackage) for database interactions.
- Uses PostgreSQL (
- Tests are written using Jest.
- Mocking is used for the database driver (
IPersistentDriver). - Test cases cover all repository methods and utility functions.
-
How to test a specific method?
- Provide the method name and its file path. Example:
findRowsinpersistence.repository.ts.
- Provide the method name and its file path. Example:
-
How to add a new feature?
- Specify the feature and its purpose. Example: Add support for
GROUP BYin queries.
- Specify the feature and its purpose. Example: Add support for
-
How to debug an issue?
- Provide the error message and the relevant file or method.
-
How to write migrations?
- Specify the table and column changes. Example: Add a new column to the
userstable.
- Specify the table and column changes. Example: Add a new column to the
- "Can you check the
findRowsmethod inpersistence.repository.ts?" - "Can you write test cases for the
updateOnemethod?" - "How can I add a
GROUP BYclause to the query builder?" - "Can you help me debug this error:
Failed to initialize database connection?"
- Always use parameterized queries to prevent SQL injection.
- Follow TypeScript best practices for type safety.
- Use environment variables for database configuration.