Recommend this page to a friend! |
Classes of Victor Bolshov | Tiny PHP ORM Framework | README.md | Download |
|
DownloadtinyormVery minimalistic ORM & DB tools for PHP Why yet another library?I know quite a lot of similar projects but they all don't satisfy me. Therefore, I made a list of requirements that my perfect ORM library should meet.
While there are tools that conform to some of the requirements, I failed to find a library that has it all. Show me the code!Select usage:
You can set fetch modes for Select:
Working with multiple DB connections:
This way, if anything goes wrong with the first or the second INSERT, transactions in both connection will be rolled back, no rows will be inserted. On the other hand, if everything goes fine, transactions in both connection will be commited. Transaction manager supports nested transactions, and the tinyorm\Db class also supports them. The approachI used an approach similar to that of Zend Framework 2 ( http://framework.zend.com/manual/current/en/user-guide/database-and-models.html ). The entity classes are just simple data containers that do not have DB connection/persistence logic. However, in the end, tinyorm entities do have minimal "knowledge" about their relationship to a storage layer. First, they have _getSourceName()_ method which essentially is meant to return a storage table/collection name. Second, there are _getPK()_ and _setPK()_ methods to access primary key. The name primary key column is stored in protected _pkName_ property. And finally, entities have _getSequenceName()_. I made all this for the sake of simplicity, in order not to have to introduce more classes. tinyorm only supports _AUTO_INCREMENT_'ed primary keys. In contracts to Zend Framework 2, all the stuff related to persistence is just a few classes/interfaces:
Persistence driver operates on Entities. In case of ZF2, we can talk about their _Table Gateway_ as a persistence driver. See the link above for reference. In tinyorm, things are way more simple. You just create a persistence driver instance and call its' _save()_, _insert()_, _update()_, _delete()_ methods providing an Entity as an argument. For a query object, I took a look at Phalcon framework ( https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Query_Builder.html ). However, I modified the interface a little, so I find it a little bit better. I also implemented a database transaction manager capable of handling multiple DB connections. CreditsThanks RasmiKanta Moharana (https://github.com/rashmi8105) for early feedback & spotting bugs in the example app! |