Download the PHP package doublemcz/dibi-orm without Composer
On this page you can find all versions of the php package doublemcz/dibi-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download doublemcz/dibi-orm
More information about doublemcz/dibi-orm
Files in doublemcz/dibi-orm
Package dibi-orm
Short Description ORM system based on dibi
License BSD-3-Clause GPL-2.0 GPL-3.0
Informations about the package dibi-orm
Dibi ORM - EXPERIMENTAL
Dibi ORM is lightweight ORM solution based on Dibi. ORM logic comes from Doctrine 2 but is very simplified. Focus is also on performance.
Installation
I recommend you to install via Composer.
If you do not have Composer, download latest version from GitHub and require bootstrap file.
Initialization
Usage in Nette
Put this section into services.neon
It is also possible to pass DibiConnection to parameter 'database'
Data handling
Get an Entity by ID
Find a user with ID = 1
If user has more columns in primary key, you can pass it in order you defined the key at the entity
Find an Entity by propety
We can find an Entity by property e-mail
Get entities in table
Find all users in table 'users'
You can filter and sort by array. We are trying to find Users in role 'admin' ordered by id desc.
Insert entity to database
Update entity
When you load an entity from repository then the entity is automatically managed by Manager. It means that if you make a change and flush changes over Manager a SQL query is automatically executed.
Delete entity
Database Manager knows what have changed
You can flush whenever you want. Manager knows what data have changed and does necessary stuff on flush.
Entity Settings
All settings are defined by PhpDoc. Every entity must have @table tag to specify the source table defined on class PhpDoc. Every class property that has relation to database column must have tag @column.
Defining primary column
Every entity must have primary key. The definition is composed by @primaryKey and @column. If you want set id that was generated from database on create sql query then specify @autoIncrement tag.
Relations
Basic relation are defined by @oneToOne and @oneToMany tag. Both need a join specification tag defined as follow: @join(column="id", referenceColumn="userId"). It says that it is joing column User.id to RelatedTable.userId column.
Real example:
Static join parameter
It is also possible to specify static join parameter to filter table by column. Here you can see static join that defines user.type = 'error'. Static join is possible only on @oneToOne and @oneToMany relations.
Relation @manyToMany
Relation many-to-many is used when your data are connected over relation table.
Events
Manager has event handling based on methods included in the Class. We have Entity events at this moment:
- beforeCreateEvent
- beforeUpdateEvent
Examples of event usage.
There you can see how we can update an entity before create or update sql is executed.