One of the sites i keep an eye on is greepit.com to know about some of the latest and coolest tools in web development. I came across this new Database Library or wrapper called Crystal database wrapper. The library really looks promising and in fact appears to be minimalistic as they claim. They also have a data validation module and manipulation module which is all you need to create basic to intermediate apps. From the user guide i looked at some of the examples of CRUD and i just felt it’s Active Record from Codeigniter. As i did a lot of Codeigniter sites so far, it just looked so comfortable to me. Just for an example.
// Produces SELECT `products`, `clients` FROM `table` - Available in Crystal 0.3
$db->select('very_long_column_name :as column, products')->from('table')
// Produces SELECT `very_long_column_name` AS `column, `products` FROM `table` -- Available in Crystal 0.3
// Produces SELECT `products`, `clients` FROM `table`
// You can use string if you need single column
// Produces SELECT `products` FROM `table`
// OR if you need complex columns selection, you can skip Crystal's default parameter filtering
$db->select('products, MAX(price), MIN(payment)', FALSE)
// Produces SELECT products, MAX(price), MIN(payment)
This is almost like the Active Record library of Codeigniter. Actually even if we want to make a newer one, we’d have to use similar type of syntax because it’s intuitive. So NO HARM being similar to other libraries syntax 😉 . If you have done much of Active Record in Codeigniter, you can see all those examples are pretty familiar. The db validation sections looks cool too.
It’d will be very nice for projects which are not written using any framework. There were lot of projects i wish i had a better db wrapper like this when i didn’t want to use bulky adodb library. So for projects of that sort can be rescued with this library. And of course anyone can hook it into any Framework with a bit of more study.
The one statement on the site i have problem with is “Crystal was designed to replace framework specific database layers like Zend_Db and Codeigniter’s active record library and complex ORM’s like Doctrine“. I would kinda disagree to think like that because may be it can replace Active Record in Codeigniter or Zend_db in Zend Framework but tough to replace an ORM like Doctrine. I’ve been doing Doctrine with Zend recently and a fan of it seeing the power of it and flexibility. To make something better than Doctrine with all the things it is capable of, it could take years. And Crystal is not an ORM yet. But as an independent library, i pretty like the way it’s laid out.
So use it as it fits your need.