Download the PHP package hawkbit/database without Composer
On this page you can find all versions of the php package hawkbit/database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hawkbit/database
More information about hawkbit/database
Files in hawkbit/database
Package database
Short Description Object orientated database handling
License MIT
Homepage https://github.com/HawkBitPhP
Informations about the package database
Hawkbit Database
Object orientated database handling with POPO's, unit of work, identity map and data mapper.
Install
Using Composer
Hawkbit Database is available on Packagist and can be installed using Composer. This can be done by running the following command or by updating your composer.json
file.
composer.json
Be sure to also include your Composer autoload file in your project:
Downloading .zip file
This project is also available for download as a .zip
file on GitHub. Visit the releases page, select the version you want, and click the "Source code (zip)" download button.
Requirements
The following versions of PHP are supported by this version.
- PHP 5.5
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM
Usage
Connect and go!
- Register a connection
- Register a Mapper if you need to work with Unit of Work and Mappers
- Have fun!
Examples
We also provide Examples for following documentation.
Connections
Shared Connections
In huge applications, you need to be able to access connections at many points. Simply share your connection
You may want to save time or lines of code and add connection directly
and access connection at another point of your application
Multiple connections
In some cases you need two ore more connections. Therefore connections could have a name, the default name is default
(Hawkbit\Database\ConnectionManager::DEFAULT_CONNECTION
).
Prefixing
On a shared database it is use full to to prefix tables with a specific name, e.g. application abbreviation. You need to set the prefix on your connection. The system is prefixing all table names automatically.
Add PHP 7.1 support
As you can see you (as do mapper) pass the tablename and internally the tablename will be prefixed.
Migration
Easy schema setup with SQL
Advanced Migration with phinx
Schema migration is not provided by this Package. We recommend packages like Phinx for advanced migration.
Gateway
The gateway mediates between database and mapper. It is able to execute table or view specific operations and provides CRUD queries.
Create a new gateway from connection
Create
Create a new entry
Read (select)
Fetch entries as array (refer to \PDO::FETCH_ASSOC
). Entries do have following array representation
You could also use doctrines expression builder combined with QueryBuilder::createPositionalParameter
and
QueryBuilder::createNamedParameter
for more complex queries!
Update
Update an entry
Delete
Delete an entry
Mapper
Data mapper
The data mapper is mapping data to entities and extracting data from entities. The mapper is also aware of database table configuration and converts data types into both directions - PHP and database. It utilizes an [Identity Map]() which ensures that an object is only load once.
Example mapper configuration
It is recommended to extend the mapper with custom logic for accessing associated data or other specific data sets. Data association / Data relation are not supported at this point!
The combination of mapper and entities may have the flavor of Table-Data-Gateway with passive records.
Entities
Entities represent a single entry (row) of a database table or view. It is a set of Setters and Getters, without any logic - passive record. Entities are Plain Old PHP Objects (POPO)
Example entity
Prepare and load mappers
Register mapper to mapper locator to preload configuration and ensure access. An Exception is thrown when locator is unable to find a mapper.
Locate a registered mapper
Locate a registered mapper by entity
Create entity from mapper, if you don't want to create a new instance of entity
Modify data
The mapper is able determine entity state and save (create or update) data. The mapper is modifying the same entity instance. All changes which have been made in database are also stored into the entity at the same time.
Create
Create an entry
Update
Update an entry
Save
The mapper is also able to detect a new or existing entity and choose to create or update an related entry in database.
Delete
Delete an entry
Fetching data
Find
Find entry by primary key or compound key and return a single entity result or false
Custom select
Fetch entries as a list of entities. Entries do have following representation
A select is taking all valid kinds of callable to modify the query.
Fetch only one entry will return an entity instead of an entity list
Transactions (Unit of Work)
For data consistency you want to use transactions. Basically all queries are wrapped with a transaction and automatically committed if auto-commit option is enabled. You could also create, update and delete a huge set of data and commit them a once.
Build-in doctrine transaction
To use a unit of work, you need to register a mapper. In some cases, like prototyping you want use gateway for quick access. Therefore you should use build-in transaction.
Unit of Work - Transaction with mappers
Transactions need registered mappers to work correctly.
Modify you data in any order, unit of work is sorting the execution of create, update and delete for you. If all
modifications are done, you need to execute UnitOfWork::commit
Please refer to the following example of unit of work:
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.