Last active
January 13, 2016 16:24
-
-
Save wowkin2/f01e0dbbec8962dc3d2d to your computer and use it in GitHub Desktop.
Python/Django vs. PHP/Symfony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ### PHP / Symfony2 / ORM ###/ | |
// create new document | |
$product = new Product(); | |
$product->setName('A Foo Bar'); | |
$product->setPrice('19.99'); | |
$product->setDescription('Lorem ipsum dolor'); | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($product); | |
$em->flush(); | |
// query for one product matching by name and price | |
$product = $repository->findOneBy( | |
array('name' => 'foo', 'price' => 19.99) | |
); | |
// query for all products matching the name, ordered by price | |
$products = $repository->findBy( | |
array('name' => 'foo'), | |
array('price' => 'ASC') | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Python / Django / MongoEngine ### | |
// create new document (mongoengine) | |
product = Product() | |
product.name = 'A Foo Bar' | |
product.price = 19.99 | |
product.description = 'Lorem ipsum dolor' | |
product.save() | |
// or | |
product = Product( | |
name='A Foo Bar', | |
price=19.99, | |
description='Lorem ipsum dolor', | |
).save() | |
// query for one product matching by name and price | |
product = Product.objects( | |
name='foo', price=19.99 | |
).first() | |
// query for all products matching the name, ordered by price | |
products = Product.objects( | |
name='foo' | |
).sort('price') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment