Releases: Planetbiru/MagicObject
2.7.4
Full Changelog: 2.7.3...2.7.4
2.7.3
Full Changelog: 2.7.2...2.7.3
2.7.2
Full Changelog: 2.7.1...2.7.2
2.7.1
2.7.0
MagicObject Version 2.7
What's New
MagicObject 2.7 brings a set of powerful updates to improve database interaction, query flexibility, and transaction management. The main highlights of this release include support for PDO connections, enhanced native query capabilities with pagination and sorting, and new transactional methods for improved data management.
1. PDO Support
One of the most significant changes in MagicObject 2.7 is the introduction of support for PDO (PHP Data Objects). In previous versions, MagicObject required the use of its custom database handler, PicoDatabase. However, to accommodate developers who prefer working with PDO connections, this new version allows users to pass a PDO connection directly to the MagicObject constructor.
Why PDO Support?
The decision to include PDO support was driven by the need to make MagicObject more versatile for developers who are already using PDO in their applications. By allowing PDO connections, MagicObject now supports a broader range of use cases and provides users with the flexibility to integrate with existing PDO-based database connections.
While PDO is supported for the initial connection setup, MagicObject continues to use PicoDatabase for all subsequent database operations. This ensures that users still benefit from PicoDatabase's advanced features, such as automatic query building, database abstraction, and optimized query execution.
How PDO Support Works
In MagicObject 2.7, when you pass a PDO connection object to the constructor, it is internally converted into a PicoDatabase instance via the PicoDatabase::fromPdo()
static method. This ensures that although PDO is used for establishing the initial connection, PicoDatabase manages the actual database interactions. Additionally, MagicObject automatically detects the database type based on the PDO driver to ensure smooth operation.
2. Pageable and Sortable in Native Queries
Another important enhancement in MagicObject 2.7 is the introduction of pageable and sortable support in native queries. Prior to this release, native queries lacked direct support for pagination and sorting. Developers had to manually include ORDER BY
and LIMIT OFFSET
clauses in their queries, leading to more cumbersome code that was difficult to maintain and adapt across different database platforms.
With MagicObject 2.7, you can now pass pagination parameters using the PicoPageable
type and sorting parameters using the PicoSortable
type directly into your native queries. These parameters can be placed at any point in the query, though it's recommended to position them either at the beginning or end for optimal readability and organization.
This improvement enhances the flexibility of native queries, as the logic for pagination and sorting is handled automatically, reducing the need for manual intervention. By supporting these features, MagicObject 2.7 allows you to write cleaner, more efficient, and database-agnostic queries. You can now easily handle pagination and sorting logic regardless of the underlying database system.
3. Transaction Management
MagicObject 2.7 introduces enhanced support for transactional database operations, including three new methods: startTransaction()
, commit()
, and rollback()
. These methods provide an easy and efficient way to manage database transactions within MagicObject.
- startTransaction(): Begins a new database transaction.
- commit(): Commits the current transaction, saving all changes made during the transaction to the database.
- rollback(): Rolls back the current transaction, undoing any changes made since the transaction began.
These methods are designed to work seamlessly with an active database connection, allowing developers to handle transactions directly within the context of their application. Whether you're managing financial transactions or ensuring data consistency during batch processing, these functions streamline the management of transaction-based operations.
Full Changelog: 2.6.1...2.7.0
2.6.1
Full Changelog: 2.6.0...2.6.1
2.6.0
2.5.3
Full Changelog: 2.5.2...2.5.3
2.5.2
Full Changelog: 2.5.1...2.5.2
2.5.1
Full Changelog: 2.5.0...2.5.1