Download the PHP package ray/query-module without Composer
On this page you can find all versions of the php package ray/query-module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ray/query-module
More information about ray/query-module
Files in ray/query-module
Package query-module
Short Description An external media access framework
License MIT
Homepage https://github.com/koriym/Koriym.PhpSkeleton
Informations about the package query-module
Ray.QueryModule
Japanese
Overview
Ray.QueryModule makes a query to an external media such as a database or Web API with a function object to be injected.
SqlQueryModuleis for DB. Convert the SQL file to a simple function object that executes that SQL.WebQueryModuleis for the Web API. Convert the URI and method set into a simple function object that Web requests to that URI.PhpQueryModuleis a generic module. It provides storage access which can not be provided by static conversion by PHP function object.
Motivation
- You can have a clear boundary between domain layer (usage code) and infrastructure layer (injected function) in code.
- Execution objects are generated automatically so you do not need to write procedural code for execution.
- Since usage codes are indifferent to the actual state of external media, storage can be changed later. Easy parallel development and stabbing.
Installation
Composer install
$ composer require ray/query-module
Module install
SQL files
$sqlDir/todo_insert.sql
$sqlDir/todo_item_by_id.sql
Convert SQL to SQL invocation object
A callable object injected into the constructor. Those object was made in specified sql with @Named binding.
Row or RowList
You can specify expected return value type is either Row or RowList with RowInterface or RowListInterface.
RowInterface is handy to specify SQL which return single row.
Override the method with callable object
Entire method invocation can be override with callable object in specified with @Query.
When parameter name is different method arguments and Query object arguments, uri_template style expression can solve it.
Specify type='row' when single row result is expected to return.
If there is no SELECT result, it returns 404 Not Found.
Convert URI to Web request object
With WebQueryModule, it converts the URI bound in the configuration into an invocation object for web access and injects it.
In the following example, an invocation object of $createTodo which makesPOST request to https://httpbin.org/todo is injected as $createTodo.
The usage code is the same as for SqlQueryModule.
The usage code of @Query does not change either.
Bind to PHP class
If other dependencies are needed, we bind to PHP class and use dependency as a service.
Bind to callable.
The usage codes are the same. The usage code of @Query does not change either.
ISO8601 DateTime Module
Convert the specified column name value to the ISO8601 format. In PHP, it is a format defined by constants of DateTime::ATOM.
Install date column names as an array and pass it as an argument to Iso8601FormatModule.
SQL file name log
The SQL file name can be appended to the SQL statement as a comment. This is useful for query logging.
`
Execute SQL
`
Demo
BEAR.Sunday example
All versions of query-module with dependencies
ext-json Version *
ext-pdo Version *
aura/sql Version ^5.0.3 | ^6.0
bear/resource Version ^1.15
guzzlehttp/guzzle Version ^6.3 || ^7.0
koriym/query-locator Version ^1.4
nikic/php-parser Version ^v4.13
ray/aop Version ^2.10.3
ray/aura-sql-module Version ^1.10.0
ray/di Version ^2.20