Download the PHP package byjg/micro-orm without Composer
On this page you can find all versions of the php package byjg/micro-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download byjg/micro-orm
More information about byjg/micro-orm
Files in byjg/micro-orm
Package micro-orm
Short Description A micro framework for create a very simple decoupled ORM (sqlite, mysql, postgres, sqlserver)
License MIT
Informations about the package micro-orm
MicroOrm for PHP
A micro framework for create a very simple decoupled ORM. This library intended to be very small and very simple to use;
Key Features:
- Can be used with any DTO, Entity, Model or whatever class with public properties or with getter and setter
- The repository support a variety of datasources: MySql, Sqlite, Postgres, MySQL, Oracle (see byjg/anydataset)
- A class Mapper is used for mapping the Entity and the repository
- Small and simple to use
Architecture
These are the key components:
- Model is a get/set class to retrieve or save the data into the database
- Mapper will create the definitions to map the Model into the Database.
- Query will use the Mapper to prepare the query to the database based on DbDriverInterface
- DbDriverIntarce is the implementation to the Database connection.
- Repository put all this together
Getting Started
Table Structure
We have the following table structure in the database for this example:
We want to be able to interact with this table using the ORM.
Defining the Model
A Model in our context is a class that symbolizes the data you wish to store or fetch from the database. This Model class can be as simple as a class with public properties. Alternatively, it can be a class equipped with getter and setter methods for more controlled access and manipulation of the data.
To map the database fields, you can add attributes to the Model class. Each property in the Model class represents a field in the database.
Let's look at an example:
In this example, we have a class MyModel
with three properties: id
, name
, and companyId
.
The id
property is marked as a primary key. The name
property is a simple field.
The companyId
property is a field with a different name in the database company_id
.
The TableAttribute
is used to define the table name in the database.
Connecting the repository
After defining the Model, you can connect the Model with the repository.
Querying the database
You can query the database using the repository.
or
or, the same example above:
Basics
- Defining the Model
- Querying the Database
- Updating the database
- Using the Mapper Object
Advanced Topics
- Active Record
- The Literal Object
- Soft Delete
- Caching the Results
- Observing the Database
- Controlling the data queried/updated
- Using FieldAlias
- Tables without auto increments fields
- Using With Recursive SQL Command
Install
Just type: