30 Oct 2008 19:48
TAGS: database dev doctrine orm php
A few days ago, I found Doctrine Project which is an object-relational mapping (ORM) solution for PHP. It seems really powerful and actually very similar to Wikidot DB Layer (especially one in Wikidot 2).
Doctrine is a really cool project and has features of:
- Wikidot DB
- Zend Framework DB
- Hibernate (ORM for Java)
- Ruby on Rails DB
Let's start from the beginning of the list.
Doctrine is most similar to Wikidot DB, because both:
- are ORM implementations for PHP
- use abstract (non-PHP, non-SQL) data definition language
- for Wikidot it's XML-based format
- for Doctrine it's YAML-based one
It's similar to Zend Framework DB, because of:
- using magic PHP methods for accessing objects properties
Hibernate and Doctrine shares:
- completeness of the DB layer
- higher abstraction than other DB layers
Ruby On Rails concepts in Doctrine:
- using YAML as a model definition language
- independence of database engine
Example of model definition:
User:
columns:
id:
type: integer
primary: true
autoincrement: true
login:
type: string(64)
unique: true
notnull: true
realname:
type: string
password:
type: string(64)
notnull: true
im:
type: string(64)
token_active:
type: string
token_created:
type: timestamp
Bet:
columns:
id:
type: integer
primary: true
autoincrement: true
brand:
type: string(100)
notnull: true
qty:
type: integer
default: 1
notnull: true
unit:
type: string(100)
notnull: true
BetUser:
columns:
bet_id:
type: integer
primary: true
user_id:
type: integer
primary: true
wins_if:
type: string
notnull: true
detect_relations: true
Doctrine comes with a CLI tool, that offers the following things:
Doctrine Command Line Interface
./doctrine.php create-tables
./doctrine.php rebuild-db
./doctrine.php generate-models-db
./doctrine.php generate-models-yaml
./doctrine.php generate-yaml-db
./doctrine.php load-data
./doctrine.php build-all-load
./doctrine.php generate-migrations-models
./doctrine.php build-all
./doctrine.php create-db
./doctrine.php migrate
./doctrine.php generate-yaml-models
./doctrine.php dump-data
./doctrine.php dql
./doctrine.php generate-migrations-db
./doctrine.php compile
./doctrine.php generate-sql
./doctrine.php drop-db
./doctrine.php generate-migration
./doctrine.php build-all-reload
The tool can be used to generate PHP files from YAML files, generate SQL files (for given DB engine), drop and create the database and more.
The dql seems to be an interesting option. Doctrine supplies its own backend-independent SQL-like language for querying and updating the DB. These operations can be done with the dql option. Although I haven't tested it yet, it seems perfect for some cronjobs or other automatic tasks that don't need to be coded in PHP.
<OFF-TOPIC>
Now, I'm converting my nuclear project — opiwo.com (bet a beer in Polish) to Doctrine ORM (from Zend Framework's one) to see how it works in reality. The project uses also other nice technologies like JSON-RPC.
I'm willing to minimize the work needed to launch it soon, by using bleeding edge technologies and web service programming concepts. The whole user interface part is programmed in JavaScript, jQuery (with many plugins) and static HTML files. Only pure data is fetched from server (with JSON-RPC). This gives more power to the server and user more responsive interface to the user. On the other side, the website may be more CPU-intensive (I hope not too much).
</OFF-TOPIC>
Please forgive me I'm now quite excited about the Doctrine. It's just how I react to some really cool (well-designed) things. I hope it's really that cool :).
Indeed this is very similar to what we have done in Wikidot v2. I can still see where Wikidot v2 is better, but Doctrine has one very serious advantage: it is released and available ;-)
Michał Frąckowiak @ Wikidot Inc.
Visit my blog at michalf.me
Post preview:
Close preview