Download the PHP package dottwatson/fpdo without Composer
On this page you can find all versions of the php package dottwatson/fpdo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fpdo
What is fpdo?
Fpdo is a versatile tool that allows you to cross-reference data from different sources simply by using the SQL queries you use daily for your MySQL database. Each source is handled as a classic SQL table, described with the blueprints used by Laravel. The package is based on a modified version of https://github.com/vimeo/php-mysql-engine, the core engine of the entire tool.
Installation
composer require dottwatson/fpdo
for the configuration go to section configuration
Creating a Database
First, let's create a connection in Laravel's database configuration file:
config/database.php
In this way, we define the database in the classic Laravel manner, except that the actual database will be defined through a dedicated class. In this example, I create a folder in the system that will host our database definition in app\FpdoDatabases.
app --
|--FpdoDatabases
|--TestFpdo
|--Database.php
|--Tables
|--Categories.php
|--Products.php
Source of app/FpdoDatabases/TestFpdo/Database.php:
Now let's define a database table. In this example, we use a JSON file in our storage: app/FpdoDatabases/TestFpdo/Tables/Products.php
In this example, reader is executed to read the data and must return an array of key-value pairs of all data records. writer is responsible for writing data wherever needed (in this example, it rewrites the same JSON file). However, if you don’t need to write data, writer can remain empty but must always be present (due to the abstract class model).
Notes: To optimize resources, all data from the tables will be loaded only when needed. This means that if you configure 20 tables, but only query 2, the data from the tables concerned will be loaded. This is called lazy loading.
That's it! Everything else remains the same for your application, such as models, relationships, direct queries, and so on.
Limitations
Basic limitations are described in https://github.com/vimeo/php-mysql-engine. However, the following features have been implemented:
BOOLEAN COLUMN - Boolean column alias of tinyint
JSON COLUMN - The JSON column, of course!
JSON FUNCTIONS - The full set of JSON functions as described in https://dev.mysql.com/doc/refman/8.4/en/json-function-reference.html, except for JSON_TABLE, JSON_VALUE, MEMBER_OF.
Note: JSON functions do not support the ** selector.
Additionally, two functions have been implemented for direct query interaction with PHP:
PHP_CALL: Accepts at least one parameter representing the function name, or a JSON array with the class and method names. All other parameters will be passed to the callable.
or
PHP_EVAL: Executes PHP code.
Custom SQL Functions
You can extend fpdo with custom functions to use in your queries as if they were native functions.
Creating a function evaluator:
adding it in the config/fpdo.php
and its usage
Configuration
To have the configuration file in the config folder of your application:
Below is a table describing the parameters:
| Parameter | Value Type | Explanation |
|---|---|---|
| default_charset | string | The default charset used for tables (and databases) where it is not otherwise defined. |
| default_collation | string | The default collation used for tables (and databases) where it is not otherwise defined. |
| slow_query_log | boolean | The slow query log consists of SQL statements that take more than long_query_time seconds to execute. |
| long_query_time | int | Expressed in seconds. Set to -1 to log every query and its execution time. |
| log_channel | string | According to your logging configuration, select your logging channel. |
| slow_read_log | boolean | The slow read log consists of data retrieval from table::read() that takes more than long_read_time seconds to execute. |
| long_read_time | int | Expressed in seconds. Set to -1 to log each read operation's time to populate tables. |
| write_on_end | boolean | The writing logic is a special setting that makes the system faster by avoiding long write processes. When a record is inserted, updated, or deleted, the table needs to be saved to the original source, which takes time if done for each modified record. With this parameter set to true, modifications stay in memory and are written at the end of execution. If enabled, any fatal error during execution will result in all in-memory data being lost! |
| slow_write_log | boolean | The slow write log consists of data writes from table::write() that take more than long_write_time seconds to execute. |
| long_write_time | int | Expressed in seconds. Set to -1 to log each write operation's time to save tables. |
| extensions | array | Extend fpdo with your custom function set. Use class names. |
That's it!
If you like this package, consider to buy me a ☕coffee