Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/2.7.1 #33

Merged
merged 63 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ef05bac
Replace DATABASE_TYPE_POSTGRESQL with DATABASE_TYPE_PGSQL
kamshory Nov 9, 2024
14f7ff3
MagicObject version 2.7
kamshory Nov 10, 2024
f1e4ea5
Update title
kamshory Nov 10, 2024
b4425d3
Update title
kamshory Nov 10, 2024
1ef995e
Update title
kamshory Nov 10, 2024
e32d711
Update example
kamshory Nov 10, 2024
9a78a6a
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
3a595cf
Merge branch 'main' into feature/2.7
kamshory Nov 10, 2024
44d869e
Update PicoDatabaseUtil.php
kamshory Nov 10, 2024
4b04df6
Update database utility
kamshory Nov 10, 2024
cf03b3f
Update configure-import.php
kamshory Nov 10, 2024
cc6de73
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
11a1365
Update PicoDatabase.php
kamshory Nov 10, 2024
3492862
Map MySQL system time zone or abbreviations like 'WIB' to a valid PHP…
kamshory Nov 10, 2024
411ed4e
Update PicoDatabase.php
kamshory Nov 10, 2024
e88d18a
Fix codesmell
kamshory Nov 10, 2024
1ea47e4
Update PicoDataLabels.php
kamshory Nov 10, 2024
d18b51f
Update docblock
kamshory Nov 10, 2024
605394f
Update InputServer.php
kamshory Nov 10, 2024
0f905fe
Update Manual
kamshory Nov 10, 2024
9ba03c7
Update manual
kamshory Nov 10, 2024
d780a15
Update
kamshory Nov 10, 2024
77d1b78
Update manual
kamshory Nov 10, 2024
403232b
Update PicoDatabaseQueryBuilder.php
kamshory Nov 10, 2024
fc8556e
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
bc58250
Update PicoDatabaseQueryBuilder.php
kamshory Nov 10, 2024
86a177e
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
878e0be
Update PicoDatabaseQueryBuilder.php
kamshory Nov 10, 2024
e7df7e3
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
110223c
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
9c556a1
Merge branch 'feature/2.6' into feature/2.7
kamshory Nov 10, 2024
88db545
Add Pagination and Sorting to Native Query
kamshory Nov 11, 2024
51bd14a
Rename method
kamshory Nov 11, 2024
152beb3
Update pagination and sorting
kamshory Nov 11, 2024
e3e60c7
Update MagicObject.php
kamshory Nov 11, 2024
e5e4de7
Refactor `executeNativeQuery`
Nov 11, 2024
fef276b
Update MagicObject.php
Nov 11, 2024
c383172
Refactor `executeNativeQuery`
Nov 11, 2024
74f909c
Update MagicObject.php
Nov 11, 2024
83377fd
Refactor
Nov 11, 2024
32f4cf1
Bug fix
Nov 11, 2024
a06c83e
Update native query debugger
Nov 11, 2024
cc3237c
Update MagicObject.php
Nov 11, 2024
772ca60
Update NativeQueryUtil.php
Nov 11, 2024
c385f01
Update MagicObject.php
kamshory Nov 11, 2024
47cc5a6
Update MagicObject.php
kamshory Nov 11, 2024
a788b5e
Update MagicObject.php
kamshory Nov 11, 2024
d36edbb
Update MagicObject.php
kamshory Nov 11, 2024
df95ab2
Update MagicObject.php
kamshory Nov 11, 2024
bf804ef
Update caller.php
kamshory Nov 11, 2024
6af5118
Update MagicObject.php
Nov 12, 2024
a35dd07
Update MagicObject.php
Nov 12, 2024
3c168e9
Add transactional (start transaction, commit, rollback)
Nov 12, 2024
1a84680
Update CHANGELOG.md
Nov 12, 2024
ee23983
Upade changelog
Nov 12, 2024
6d91d02
Update changelog
Nov 12, 2024
ccc27f6
Refactor MagicObject
kamshory Nov 12, 2024
abeffba
Update MagicObject.php
kamshory Nov 12, 2024
bcfab69
Update SecretObject.php
kamshory Nov 12, 2024
de66d8c
Update SecretObject.php
kamshory Nov 12, 2024
6c77d51
Update PicoDatabase.php
kamshory Nov 13, 2024
a9a0fe2
Fixing database driver
kamshory Nov 13, 2024
33b6012
Update PicoDatabaseUtilSqlite.php
kamshory Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

# MagicObject Version 2

## What's New

**MagicObject Version 2** brings several exciting new features and enhancements aimed at increasing flexibility, improving performance, and providing better control over database interactions. Below are the key updates introduced in this version:

### 1. Native Query Support

**Native SQL Queries** are now supported in **MagicObject**, allowing users to execute raw SQL statements directly within the framework. This enhancement gives developers greater control over complex queries, which may not be easily handled by the ORM layer. You can now execute any SQL command directly, enabling the use of advanced SQL features and custom queries that go beyond the capabilities of the built-in ORM.

### 2. Multiple Database Connection Support

The new version of **MagicObject** introduces the ability to configure and manage **multiple database connections** within a single application. This feature allows developers to easily connect to and manage different databases simultaneously, making it ideal for applications that need to interact with multiple databases or implement multi-database architectures. Whether you're working with multiple MySQL instances, different types of databases (e.g., PostgreSQL, SQLite), or managing different environments (development, production), this feature significantly simplifies database management.

### 3. Entity Cache Control on Joins

**MagicObject Version 2** gives developers greater control over **entity caching** when performing **join operations**. The new feature allows you to enable or disable caching specifically for joins, providing fine-tuned control over your caching strategy. This improves performance by reducing unnecessary database hits while still ensuring fresh data retrieval when needed. You can now optimize caching on a per-query basis, making it easier to manage large data sets efficiently.

### 4. Enhanced Documentation

The documentation for **MagicObject** has been thoroughly updated. In this release, we've made significant improvements to the documentation for **classes**, **properties**, **functions**, and **annotations**. The documentation now includes clearer explanations, improved examples, and comprehensive usage guidelines. These changes are designed to make it easier for developers to understand and fully leverage the power of the framework, reducing the learning curve and streamlining the development process.

### 5. Bug Fixes and Stability Enhancements

Several bugs and issues from previous versions have been addressed in **MagicObject Version 2**. This includes improvements to **performance**, **stability**, and the **correction of minor errors** that may have affected the functionality of the framework. With these fixes, users can expect a more reliable and robust framework that performs well across a variety of use cases.

## Additional Features

- **Improved Error Handling**: We've introduced enhanced mechanisms for detecting and handling errors. The error messages are now more informative, helping developers to troubleshoot and resolve issues faster. This improvement also includes better stack trace information and more specific error types.

- **Performance Optimizations**: Internally, **MagicObject Version 2** has been optimized to improve overall performance. Key database interaction operations have been streamlined, leading to faster query execution times and better resource utilization.

- **Backward Compatibility**: **MagicObject Version 2** maintains **backward compatibility** with **Version 1**, ensuring that existing users can upgrade smoothly without having to make significant changes to their codebase. This allows for an easy transition to the new version while still maintaining compatibility with legacy systems.


## Migration Notes

If you are upgrading from **MagicObject Version 1** to **Version 2**, please review the migration notes carefully. The documentation includes detailed guidelines and best practices for handling any potential breaking changes, as well as adjustments that may be necessary to ensure a smooth transition. By following these guidelines, you can ensure that your upgrade process is as seamless as possible, minimizing disruptions to your development workflow.



# MagicObject Version 2.1

## What's New

**MagicObject 2.1** introduces several powerful new features aimed at improving entity management, database interoperability, and overall ease of use. This version builds on the foundational updates from previous releases, making database handling even more efficient and developer-friendly. Here’s a detailed overview of the new additions:

### 1. Package Annotations for Entity Joins

One of the most notable features in **MagicObject 2.1** is the introduction of **package annotations** for entities. These annotations are essential when joining entities, as they provide the necessary namespace information that is critical for the framework to correctly recognize and associate entity classes.

#### Why Package Annotations?

PHP does not natively provide a way to directly retrieve the namespace of a class, which presented a challenge for earlier versions of **MagicObject** when attempting to perform joins. To work around this, **MagicObject** previously attempted to infer namespaces by reading the PHP script, but this method proved to be both inefficient and prone to errors.

With **MagicObject 2.1**, the introduction of package annotations on each entity allows the framework to safely and efficiently join entities by referencing the class's base name, without needing to manually specify or infer the namespace. This makes the process of joining entities more robust and reliable.

#### Backwards Compatibility

If a package annotation is not present on an entity, **MagicObject 2.1** will gracefully revert to the old method of namespace inference, ensuring backwards compatibility with previous versions. However, it is strongly recommended to utilize the new package annotations for better performance and accuracy when performing entity joins.

### 2. Seamless Database Conversion Between PostgreSQL and MySQL

**MagicObject 2.1** introduces a powerful utility that allows developers to seamlessly convert databases between **PostgreSQL** and **MySQL**. This feature greatly simplifies the process of migrating applications and data between these two popular database systems.

#### Key Features of Database Conversion:

- **Data Type Mapping**: MagicObject handles the conversion of data types between PostgreSQL and MySQL, ensuring that the equivalent types are correctly mapped.
- **Constraints and Structures**: The conversion tool also accounts for database constraints, indexes, and table structures, ensuring that the integrity of the database schema is maintained during migration.
- **Error Reduction**: By automating the conversion process, MagicObject reduces the chances of errors that can occur during manual migration, saving time and effort for developers.

This new functionality provides developers with a simple and efficient way to migrate data between PostgreSQL and MySQL, which is particularly useful for projects that need to switch databases or support multiple database systems.

### 3. Parsing Table Structures from SQL Statements

Another significant enhancement in **MagicObject 2.1** is the ability to **parse table structures directly from SQL statements**. Developers no longer need to first dump the schema into a database before they can interact with it. Instead, MagicObject allows you to read and manipulate the structure of a database directly from SQL.

#### Benefits of Table Structure Parsing:

- **Streamlined Workflow**: This feature eliminates the need for a two-step process (first dumping, then reading the schema) and allows developers to work more directly with SQL code.
- **Integrate with Third-Party Systems**: Developers can now easily parse and manipulate schemas from third-party systems that provide SQL code, without needing to import the data into a database first.
- **Improved Efficiency**: This utility speeds up the process of understanding and working with complex database schemas, making it easier to integrate and maintain SQL-driven projects.

By providing a direct way to parse table structures, **MagicObject 2.1** significantly simplifies database schema management and makes it more accessible, especially for developers working with raw SQL or third-party integrations.

## Summary

**MagicObject 2.1** brings a suite of powerful features designed to enhance database management, simplify entity relationships, and improve the overall development process. Key updates include:

- **Package annotations** for safer and more efficient entity joins.
- A **seamless database conversion tool** between PostgreSQL and MySQL, simplifying migrations.
- **Direct parsing of SQL table structures**, eliminating the need for intermediate steps.

These updates significantly improve the flexibility and efficiency of **MagicObject**, making it even easier for developers to manage databases and integrate with various systems. With **MagicObject 2.1**, developers can focus more on building applications and less on wrestling with database compatibility and entity management.


# 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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ Additionally, MagicObject 2.1 allows users to parse table structures directly fr

These utilities not only enhance efficiency but also provide a robust foundation for database development, allowing users to focus on building applications rather than wrestling with database compatibility issues. With MagicObject 2.1, database management becomes more intuitive and accessible, empowering developers to harness the full potential of their data.


# **PDO Support in MagicObject 2.7**

## **Overview**

With the release of **MagicObject 2.7**, a significant update has been introduced to allow users to leverage **PDO** (PHP Data Objects) for database connections. In previous versions, **MagicObject** required the use of **PicoDatabase**, its custom database handling class. However, recognizing that many developers are accustomed to establishing database connections via traditional PDO, this new version introduces flexibility by allowing PDO connections to be passed directly to the **MagicObject** constructor.

This update aims to bridge the gap between traditional PDO-based database management and the advanced features provided by **MagicObject**, thus enhancing compatibility while retaining all the powerful functionality of the framework.

## **Why PDO Support?**

The decision to support **PDO** was made to accommodate users who have already established database connections in their applications using PDO, instead of relying on **PicoDatabase** from the start. By supporting PDO, **MagicObject** allows users to continue working with their preferred method of connecting to the database while still benefiting from the full range of features and utilities **MagicObject** offers.

While PDO is now an option for initializing **MagicObject**, it is used only in the constructor. Once the object is initialized, **MagicObject** continues to use **PicoDatabase** for all subsequent database interactions, ensuring that users can still benefit from **PicoDatabase**'s advanced features like 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 automatically converted into a **PicoDatabase** instance using the `PicoDatabase::fromPdo()` static method. This ensures that even though PDO is used to establish the initial connection, the object will still operate using **PicoDatabase** for all subsequent database operations. The constructor of **MagicObject** ensures that the database connection is properly initialized and the type of database is correctly detected based on the PDO driver.

# **Pageable and Sortable in Native Query in MagicObject 2.7**

In **MagicObject version 2.7**, support for **pageable** and **sortable** functionality has been added to native queries. Previously, native queries did not support pagination and sorting directly. Instead, users had to manually include `SORT BY` and `LIMIT OFFSET` clauses in their queries, which made them less flexible. This approach was problematic because each Database Management System (DBMS) has its own syntax for writing queries, making it cumbersome to adapt queries for different platforms.

With the introduction of pageable and sortable support in version 2.7, users can now easily pass **pagination** parameters using the `PicoPageable` type and **sorting** parameters using the `PicoSortable` type directly into their native queries. These parameters can be placed anywhere within the query, but it is recommended to position them either at the beginning or the end of the query for optimal readability and organization.

This enhancement makes native queries more flexible and easier to maintain, as the logic for pagination and sorting is handled automatically, without requiring manual intervention for each DBMS. As a result, users can now write cleaner, more efficient, and database-agnostic native queries.



# Tutorial

Tutorial is provided here https://github.com/Planetbiru/MagicObject/blob/main/tutorial.md
Expand Down
24 changes: 23 additions & 1 deletion manual/includes/_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
- **Callbacks**: Support for custom callback functions for query execution and debugging.
- **Unique ID Generation**: Generate unique identifiers for database records.

### Database Support

MagicObject supports the following databases:

1. **MySQL**

One of the most popular open-source relational databases, known for its speed, reliability, and ease of use. MySQL is widely used in web applications and offers strong performance, security features, and support for SQL standards.

2. **MariaDB**

A fork of MySQL, created by the original developers of MySQL after concerns over Oracle’s acquisition of MySQL. MariaDB is designed to maintain compatibility with MySQL while adding new features and optimizations. It is fully open-source and highly regarded for its performance and stability.

3. **PostgreSQL**

A powerful, open-source relational database system known for its robustness, SQL compliance, and extensive feature set, including ACID compliance, JSON support, and advanced indexing mechanisms.

4. **SQLite**

A lightweight, serverless, self-contained SQL database engine that is highly portable. It is often used for embedded systems or small-scale applications due to its minimal setup and resource usage. Despite its simplicity, SQLite supports a wide range of SQL features and is widely used in mobile apps and other local storage scenarios.

MagicObject’s compatibility with these databases enables flexible, scalable, and efficient data management across different platforms and environments.

### Installation

To use the `PicoDatabase` class, ensure you have PHP with PDO support. Include the class file in your project, and you can instantiate it with your database credentials.
Expand Down Expand Up @@ -243,7 +265,7 @@ public function query($sql, $params = null)
- `array|null $params`: Optional parameters for the SQL query.
**Returns**: PDOStatement object or `false` on failure.

##### Fetch a Single Result
#### Fetch a Single Result

```php
public function fetch($sql, $tentativeType = PDO::FETCH_ASSOC, $defaultValue = null, $params = null)
Expand Down
Loading
Loading