respect / structural
Fluent NoSQL Toolkit
dev-master / 0.1.x-dev
2012-05-05 19:11 UTC
Requires
- php: ^5.6 || ^7.0
- ramsey/uuid: ^3.2
- respect/data: ^0.2
Requires (Dev)
- aws/aws-sdk-php: ^3.15
- fabpot/php-cs-fixer: ^1.11
- mongodb/mongodb: ^1.0.0
- phpmd/phpmd: ^2.3
- phpunit/phpunit: ^5.2
- squizlabs/php_codesniffer: ^2.5
Suggests
- ext-mongo: @stable
- ext-mongodb: @stable
- aws/aws-sdk-php: ^3.15
- mongodb/mongodb: ^1.0.0
This package is auto-updated.
Last update: 2024-11-24 04:47:40 UTC
README
The Near-zero Part
// bootstrap.php require_once __DIR__ . '/vendor/autoload.php'; use Respect\Structural\Mapper; use Respect\Structural\Driver\MongoDb\Style as MongoDbStyle; use Respect\Structural\Driver\MongoDb\Driver as MongoDbDriver; $driver = MongoDbDriver::factory('respect'); $mapper = new Mapper($driver); $mapper->setStyle(new MongoDbStyle());
Persisting
$author = new \stdClass(); $author->firstName = 'Antonio'; $mapper->authors->persist($author); $mapper->flush(); echo "'{$author->firstName}' was created with id({$author->_id})".PHP_EOL;
Updating
$author->lastName = 'Spinelli'; $mapper->authors->persist($author); $mapper->flush(); echo "last name was updated to '{$author->lastName}' from id({$author->_id})".PHP_EOL;
Fetching
$authors = $mapper->authors->fetchAll(); echo "Fetching all authors:" . PHP_EOL; foreach ($authors as $index => $author) { echo "{$index} {$author->firstName} {$author->lastName}" . PHP_EOL; }
Condition
// find author by ID $foundAuthor = $mapper->authors[(string)$author->_id]->fetch(); echo "find by id('{$author->_id}') {$foundAuthor->firstName} {$foundAuthor->lastName}".PHP_EOL;
Removing
$mapper->authors->remove($author); $mapper->flush(); $author = $mapper->authors(['lastName' => 'Spinelli'])->fetch(); echo ($author ? "'Spinelli' was found" : "'Spinelli' removed.");