Download the PHP package genesis/persistence without Composer
On this page you can find all versions of the php package genesis/persistence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package persistence
Genesis Persistence
Introduction
This package allows for super fast model implementation that can port over the database model straight into your database manager.
Usage
To use the mapperService, please create a model (you can call it whatever you want) that extends the BaseModel. Your model does not need to implement any getters and setters, these will be provided out of the box by the BaseModel. You will have to declare all your model properties as protected.
Creating a model
In the above example your model defines how the database is setup and will be communicated with. Each property will define what type and constraints it should have. Please note that the id property is inherited by the BaseModel
and will be included in all tables as a must.
Using a model with the mapper
The mapper provides a simple yet powerful layer of abstraction for you. It understands how your model needs to be saved and retrieved from the database.
Instantiation
The library only supports a few databases at the moment and is only tested so far with sqlite. Please use the config below to connect with appropriate drivers.
For clarity and to avoid confusion, please define all of the above config for your project. For any info on what they mean please visit the relevant PHP manual pages for the PDO construct.
Saving and retrieving data.
The mapper exposes the databaseService which allows you to perform more complex queries while still binding objects back to the original models. Consider the following example
Retrieving an associated model object
Have you noticed that the MyItemModel
has a userId
property, this property would, in an ideal world link to another record in the database in the User
table. If you have modeled this User
in your app, you can use the getAssociated call provided by the mapper to get this record out. Consider the example below.
Deleting records
The mapper allows you to delete records in two ways. Consider the examples below.
Feel free to explore other calls provided by the mapperService. The mapper also allows you to create tables based on a model.
Console
This packages comes with 2 console scripts
- db-setup.php {model-directory} # Setup your database based on your model class definitions.
- db-migrate.php {model-directory} # Any changes you've made to the model class definitions will be detected.
Find these in the bin folder.