Frequently Asked Questions (FAQ)
Frequently Asked Questions (FAQ)
This section provides answers to commonly asked questions about DataForge, helping you troubleshoot and maximize its potential.
General
1. What is DataForge?
DataForge is a query-based Laravel library designed to streamline backend development by offering reusable SQL queries, dynamic entities, and task workflows. It provides a lightweight alternative to traditional ORM models, focusing on performance and scalability.
2. How does DataForge differ from Laravel Eloquent?
- DataForge focuses on query-first architecture, giving developers full control over SQL queries.
- It avoids ORM-related performance bottlenecks by directly working with queries.
- Offers modular classes (SQL, Entity, Task) for better code organization and reusability.
Installation & Setup
3. What are the prerequisites for using DataForge?
- PHP 8.0 or higher
- Laravel 8.x or higher
- Composer
4. How do I install DataForge?
Run the following Composer command:
composer require astra-techno/data-forge
Refer to the Installation Guide for detailed steps.
SQL Class
5. Can I define multiple queries in a single SQL class?
Yes. Each SQL class can have multiple methods, each defining a unique query. Use the select
method to specify query variations (e.g., list
, item
, total
).
6. How do I apply optional filters in SQL queries?
Use the filterOptional
method. For example:
$query->filterOptional('column_name = {request.param}');
7. How do I handle complex conditions?
Use the filterAnyOneRequired
method to ensure at least one condition is applied:
$query->filterAnyOneRequired('GroupName', [
'condition1 = {request.param1}',
'condition2 = {request.param2}'
]);
Entity Class
8. What is the purpose of the init
method in an Entity class?
The init
method is mandatory for loading an entity's base properties. It queries the database and binds the data to the entity instance.
9. Can I define relationships between entities?
Yes. Use methods in your entity class to load related entities. For example:
function getRelatedEntity() {
return DataForge::getEntityName($this->related_id);
}
10. What is lazy loading in Entity classes?
Lazy loading ensures that attributes or related entities are only loaded when accessed, improving performance.
Task Class
11. What are Task classes used for?
Task classes handle custom workflows that combine SQL queries and Entity methods. They are ideal for actions like saving, updating, or complex data preparation.
12. How do I expose a Task method as an API endpoint?
DataForge automatically maps Task methods to the api/Task
endpoint. For example, the detail
method in InvoiceTask
can be accessed via:
/api/Task/InvoiceTask/detail
13. How do I handle unauthenticated access?
Use GuestTask
methods. These methods must have a guest
prefix and are mapped to the api/GuestTask
endpoint.
API Endpoints
14. How many endpoints does DataForge provide?
DataForge offers 7 API endpoints:
api/list
api/all
api/item
api/field
api/entity
api/Task
api/GuestTask
Refer to the API Endpoints Guide for details.
15. Can I customize the API responses?
Yes. Use SQL, Entity, and Task classes to structure the data and control the response format.
Troubleshooting
16. Why is my entity not instantiating?
Ensure that:
- The
init
method in the entity class returns data. - Required parameters are passed to the
init
method. - Access checks in the
access
method (if implemented) returntrue
.
17. How do I debug SQL errors?
- Name your query using the
Query
function for easier identification. - Use Laravelās logging mechanism to log query errors.
18. What if a Task method returns an error?
Check:
- Whether required parameters are passed to the Task method.
- Error messages set using
$this->setError()
. - The logic in SQL and Entity methods called within the Task.
Advanced
19. Does DataForge support multiple database connections?
Currently, DataForge uses the default Laravel database connection. Future updates aim to include support for multiple connections.
20. Can I extend DataForge classes?
Yes. You can extend SQL, Entity, and Task classes to include additional methods or override existing functionality.
Contact
For further assistance, visit our support page or contact us at astratechno88@gmail.com.