user
table (1 line = 1 entity)user_param
table (1 line = 1 entity field)config
table and save back in Memcache and APC
#app/config/yucca.yml
yucca:
#DB connections
connections:
default:
type: doctrine
options:
driver: %database_default_driver%
host: %database_default_host%
port: %database_default_port%
dbname: %database_default_name%
user: %database_default_user%
password: %database_default_password%
charset: UTF8
memcache_general:
type: memcache
options:
prefix: %memcache_general_prefix%
servers:
- {port: %memcache_general_port%, host: %memcache_general_host%}
message_1:
# ...
message_2:
# ...
#app/config/yucca.yml
yucca:
#DB Schema
schema:
user:
sharding_strategy: modulo
shards:
- default
user_params:
sharding_strategy: modulo
shards:
- default
messaages:
sharding_strategy: modulo
shards:
- message_1
- message_2
#app/config/yucca.yml
yucca:
#Sources
sources:
user:
default_params:
fields: { id: 'identifier', created_at: {type: 'datetime'}, updated_at: {type: 'datetime'}, email: ~, password: ~, salt: ~ }
handlers:
-
type: database_single_row
table_name: user
user_params:
default_params:
fields: {id: 'identifier', fbuid: ~, twitteruid: ~}
name_field: param_name
value_field: param_value
mapping: {id: user_id}
handlers:
-
type: database_multiple_row
table_name: user_params
location:
default_params:
fields: { id: {type: 'identifier'}, latitude: ~, longitude: ~, bounds: {type: 'json'}, streetNumber: ~, streetName: ~, cityDistrict: ~, city: ~, zipcode: ~, county: ~, countyCode: ~, region: ~, regionCode: ~, country: ~, countryCode: ~, timezone: ~, createdAt: {type: 'datetime'} }
handlers:
-
type: memcache
connection_name: memcache
-
type: database_single_row
table_name: location
-
type: geocoding
#app/config/yucca.yml
yucca:
#Mapping object / Sources
mapping:
MyProject\Model\User:
mapper_class_name: ~
properties:
state:
field: state_id
company:
field: company_id
sources:
- user
- user_param
$this->get('yucca.entity_manager')->load('YuccaDemo\Model\User', $user_id);
try {
$user->ensureExist();
} catch (\Yucca\Component\Source\Exception\NoDataException $e) {
throw $e;
}
/**
* @var $selector \MyProject\Selector\User
*/
$selector = $this->container->get('yucca.selector_manager')->getSelector('MyProject\Selector\User');
$selector->addEmailCriteria($email);
switch($selector->count()) {
case 1: {
return $this->yuccaEntityManager->load('MyProject\Model\User',$selector->current());
}
case 0: {
throw new \Exception('No user found');
}
default: {
throw new \Exception('Multiple users found');
}
}
<?php
use \Yucca\Component\Selector\SelectorAbstract;
use Yucca\Component\Selector\Source\SelectorSourceInterface;
class User extends SelectorAbstract {
public function __construct(SelectorSourceInterface $source = null){
parent::__construct($source);
$this->options = array(
SelectorSourceInterface::ID_FIELD => array('u.id'),
SelectorSourceInterface::SHARDING_KEY_FIELD => null,
SelectorSourceInterface::TABLE => array(
'user'=>array('alias'=>'u'),
),
SelectorSourceInterface::SELECTOR_NAME => __CLASS__,
);
}
/**
* @param string $criteria
* @return \MyProject\Selector\User
*/
public function addEmailCriteria($criteria){
$this->criterias['u.email'][] = $criteria;
return $this;
}
}
SELECT u.id FROM user AS u WHERE u.email = ?
SELECT u.id FROM user AS u WHERE u.email IN (?, ?)
SELECT * FROM user WHERE id = ?
/** @var $selector \MyProject\Selector\User */
$selector = $this->container->get('yucca.selector_manager')->getSelector('MyProject\Selector\User');
/** @var $iterator \Yucca\Component\Iterator\Iterator | \MyProject\Model\User[] */
$iterator = new \Yucca\Component\Iterator\Iterator(
$selector,
$this->container->get('yucca.entity_manager'),
'\MyProject\Model\User'
);
foreach($iterator as $user) {
var_dump($user->getEmail());
}