20
Symfony with MongoDB AND MySQL Yes, but why?!

Symfony with mongo and mysql. Yes, but why?

Embed Size (px)

Citation preview

Page 1: Symfony with mongo and mysql. Yes, but why?

Symfony with MongoDB AND MySQLYes, but why?!

Page 2: Symfony with mongo and mysql. Yes, but why?

wealth management, set free

Page 3: Symfony with mongo and mysql. Yes, but why?
Page 4: Symfony with mongo and mysql. Yes, but why?

Symfony● Stable● Plenty of Resources● Interoperability● Open Source● + Doctrine!

Page 5: Symfony with mongo and mysql. Yes, but why?

Doctrine● Decoupled from Symfony and

optional● DB connections setup in

parameters.yml● Doctrine MongoDB Bundle ● Doctrine Fixtures Bundle

integrated in Symfony standard edition

Page 6: Symfony with mongo and mysql. Yes, but why?

From http://symfony.com/doc/current/book/doctrine.html

Page 7: Symfony with mongo and mysql. Yes, but why?

A tale of two layers

Page 9: Symfony with mongo and mysql. Yes, but why?

A tale of two layersMySQL = presentation

● Relational● Table● Vertical Scaling● Normalization: make tables as small as

possible (ex: user table)● PAS normalizes to MySQL

Mongo = communication

● Non-relational / NoSQL● Key - value pairs (JSON/BSON)● Horizontal scaling● Denormalization: to quickly get all the data● Standardize into mongo ● Do pre-calcs in mongo (bc it’s faster)

“Makes coding life easier, but must know the structure ahead of time”

“We don't know what the data file will look like from custodians”

Page 10: Symfony with mongo and mysql. Yes, but why?
Page 11: Symfony with mongo and mysql. Yes, but why?
Page 12: Symfony with mongo and mysql. Yes, but why?

MongoDBBundle

● Deal only with plain PHP objects

● Persist transparently to and from MongoDB

● Mapping via DocBlock annotations{

"require": { "doctrine/mongodb-odm": "~1.0", "doctrine/mongodb-odm-bundle": "~3.0" },}

Page 13: Symfony with mongo and mysql. Yes, but why?
Page 14: Symfony with mongo and mysql. Yes, but why?
Page 15: Symfony with mongo and mysql. Yes, but why?

Fixtures Bundle

● Fixtures are PHP classes● Load a controlled set of data● Used for testing or could be the

initial data● Shares Objects between

Fixtures● (enable in app/AppKernal.php)

$ composer require --dev doctrine/doctrine-fixtures-bundle

Page 16: Symfony with mongo and mysql. Yes, but why?
Page 17: Symfony with mongo and mysql. Yes, but why?

Exampleswealthbot/src/Wealthbot/FixturesBundle/DataFixtures/ORM/LoadClientData.php

class LoadClientData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface {

private $accounts = array( array( 'consolidator_key' => null, 'group_key' => AccountGroup::GROUP_DEPOSIT_MONEY, 'type_key' => 10, 'financial_institution' => null, 'value' => 20000, 'monthly_contributions' => null, 'monthly_distributions' => null, 'sas_cash' => 1500, ), ...

Page 18: Symfony with mongo and mysql. Yes, but why?

Examples cont.wealthbot/src/Wealthbot/FixturesBundle/DataFixtures/ORM/LoadClientData.php

private function createClientAccounts(ObjectManager $manager, User $clientUser) { foreach ($this->accounts as $index => $item) {

$account = new ClientAccount(); $account->setGroupType($groupType); $account->setClient($clientUser); $account->setMonthlyDistributions($item['monthly_distributions']); $account->setSasCash($item['sas_cash']); $accountOwner = new ClientAccountOwner(); $accountOwner->setAccount($account); $accountOwner->setClient($clientUser); $accountOwner->setOwnerType(ClientAccountOwner::OWNER_TYPE_SELF);

}}

Page 19: Symfony with mongo and mysql. Yes, but why?

Why not just mongo?

● Cleaner code● More predictable = better unit

testing● Faster dashboards● And yet, flexible enough when

working with custodians

Page 20: Symfony with mongo and mysql. Yes, but why?

wealthbot.io

@wealthbot

https://github.com/wealthbot-io/wealthbot

[email protected]