bravo3 / orm
NoSQL ORM for databases such as Redis
Installs: 8 979
Dependents: 2
Suggesters: 1
Security: 0
Stars: 61
Watchers: 10
Forks: 4
Open Issues: 1
Requires
- php: >=5.5.0
- doctrine/annotations: ^1.2
- doctrine/inflector: ^1.0
- eloquent/enumeration: ^5.1
- ocramius/proxy-manager: ^1.0
- psr/log: ~1.0
- symfony/event-dispatcher: >=2.7
Requires (Dev)
- bravo3/properties: ~1.0
- incenteev/composer-parameter-handler: ~2.0
- phpunit/phpunit: ^5.0
- predis/predis: ~1.0
Suggests
- predis/predis: For Redis support
- dev-master / 1.0.x-dev
- 0.6.0.x-dev
- 0.5.13
- 0.5.12
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.6
- 0.4.5-beta
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.14
- 0.3.13
- 0.3.12
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.25
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/filter-results-by-value-ranges
- dev-fix/test-new-indices
- dev-feature/sort-conditions
- dev-feature/serialised-objects
This package is not auto-updated.
Last update: 2024-12-21 18:45:17 UTC
README
Purpose
The purpose of this library is to blend ORM and ODM fundamentals with NoSQL database platforms, allowing you to use NoSQL databases with pseudo-relationships through means of a traditional entity manager.
Table of Contents
- Drivers
- Entity Mapping Definitions
- Events
- PubSub
- Important Notes
- Index Types
- Key Schemes
- Project Structure
- Queries
- Race Conditions
- Serialisers
- Mappers - Yaml
Further Examples
Advanced/Internals
Example
If you intend to use Redis, please include Predis in your composer.json
:
"require": {
"predis/predis": "~1.0"
}
Creating an entity manager for a Redis database with annotation mappings:
$em = new EntityManager(
new RedisDriver(['host' => 'example.com']),
new AnnotationMapper()
);
Persisting a simple relationship:
$address = new Address();
$address->setId(1)->setStreet("123 Example St");
$user = new User();
$user->setId(1)->setName("Harry")->setAddress($address);
$em->persist($user)->persist($address)->flush();
Retrieving a relationship with lazy-loading:
$user = $em->retrieve('User', 1); // Only user entity retrieved
$address = $user->getAddress(); // DB call to get address made here
Example entity files:
User.php
<?php
use Bravo3\Orm\Annotations as Orm;
/**
* @Orm\Entity(table="users")
*/
class User
{
/**
* @var int
* @Orm\Id
* @Orm\Column(type="int")
*/
protected $id;
/**
* @var string
* @Orm\Column(type="string")
*/
protected $name;
/**
* @var Address
* @Orm\ManyToOne(target="Address", inversed_by="users")
*/
protected $address;
// Other getters and setters here
/**
* Get Address
*
* @return Address
*/
public function getAddress()
{
return $this->address;
}
/**
* Set Address
*
* @param Address $address
* @return $this
*/
public function setAddress(Address $address)
{
$this->address = $address;
return $this;
}
}
Address.php
<?php
use Bravo3\Orm\Annotations as Orm;
/**
* @Orm\Entity
*/
class Address
{
/**
* @var int
* @Orm\Id
* @Orm\Column(type="int")
*/
protected $id;
/**
* @var string
* @Orm\Column(type="string")
*/
protected $street;
/**
* @var User[]
* @Orm\OneToMany(target="User", inversed_by="address")
*/
protected $users;
// Other getters and setters here
/**
* Get users
*
* @return User[]
*/
public function getUsers()
{
return $this->users;
}
/**
* Set users
*
* @param User[] $users
* @return $this
*/
public function setUsers(array $users)
{
$this->users = $users;
return $this;
}
/**
* Add a user
*
* @param User $user
* @return $this
*/
public function addUser(User $user)
{
$this->users[] = $user;
return $this;
}
}
Bundled Strategies
Databases
- Redis
- Native filesystem
- Tar or zip archives
See drivers for more info on database implementations.
Serialisation
- JSON
Entity Metadata Mappers
- Annotation
- YAML
Key Schemes
- Standard scheme: configurable delimiter, defaulting to Redis-style
- Filesystem path scheme
Major Planned Additions
- Validation service
Change Log
0.5.6
- Added a YAML mapper
- Added map portation to easily convert between mapping types
0.5.5
- Add a chained mapper, allowing you to examine multiple forms of entity mapping in a single project
0.5.0
- Removed 'entity hydration errors as events' due to its dangerous nature
- Added a filesystem driver - designed for backup purposes but could also serve has a mini internal database
0.4.3
- Added the ability to perform sorted, conditional queries on all items in a table
- Added the ability to name sorted queries, allowing different configurations of conditions on the same column
0.3.13
- Changed logic for retrieving entities. If nothing found (during writing) it will generate a new instance of the entity with the correct id
- Retrieving an entity with missing relatives will now return blank new instances of the relatives
0.3.0
- Added ref tables to maintain non-reciprocated relationships
- Added restrictions to table names and entity ID values
- Changed sort index key names to include the relationship name (WARNING: will break existing data)
- Multiple relationships with the same sort-by columns would conflict
- Use the Maintenance#rebuild() function to repair sort indices
0.2.0
- Added EntityManager::refresh()
- The entity manager will now remember previously retrieved entities and return them instead of querying the database
- Added $use_cache parameter to all
retrieve*()
and*Query()
functions on the entity manager