Download the PHP package libertyphp/datamapper without Composer
On this page you can find all versions of the php package libertyphp/datamapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download libertyphp/datamapper
More information about libertyphp/datamapper
Files in libertyphp/datamapper
Package datamapper
Short Description The LibertyPHP Datamapper. Simple and powerful datamapper for MySQL and PostgreSQL.
License MIT
Informations about the package datamapper
Liberty PHP Datamapper
Simple and powerful datamapper for MySQL and PostgreSQL.
Philosophy of the project
- Active record is anti-pattern. It violates SOLID principles of object-oriented programming. Moreover, the models of active record pattern are often too heavy, so this leads to a loss of performance.
- Repository pattern is not the best solution for working with relational databases. This pattern is too abstracted. This leads to complexity of the code and also to the loss of performance.
- Query builder is not the best solution for making SQL queries. This solution creates additional abstraction, so we lose advantages when using the specific features of the SQL of various databases.
- Abstraction must help reduce programming complexity and effort, but at the same time it must preserve the advantages of each database.
- Describing relationships in models is bad. This is an unnecessary abstraction and additional restrictions that lead to a loss in performance.
- Never write complex SQL queries especially using table joins with Query Builder
Working with library
There are two ways to work with the database:
- Raw SQL queries
- "Row" layer
- "Model" layer
Working with "Row" layer
You need to make table class, for example:
You need to make your database instance, for example:
Now you can make SQL queries to the database, for example:
You can make more complex SQL queries, for example:
The following trick is suggested for fetching related data in another table:
You need only write raw SQL with database class if you want to make SQL with JOIN!
Working with "Model" layer
You need to create model class, for example:
You need to create mapper class, for example:
You need to add new methods in your UserTable class, for example:
Now you can make queries to the table in the same way as on the "row" layer, but using "getModels" methods instead of "getRows":
Copyright
Copyright (c) 2021 Vladimir Lila. See LICENSE for details.
All versions of datamapper with dependencies
ext-pdo Version *
ext-pgsql Version *