Raven: A Scripting Language for MySQL
I've been using a home grown scripting language called Raven for a couple of years now. I think it is a good tool for working with MySQL, particularly when one needs to crank out a quick script on the fly using simple and readable code. Currently it spends a lot of time talking to my cluster. Here are the basics... Connect to the Database:
'mysql://user:password@localhost/test' open as $mysql
Select some records:
'SELECT * FROM mytable' $mysql query as $result
Get the number of selected records:
$result selected as $num_rows
Iterate over the result set and output a CSV:
$result each as $record $record ',' join print "\n" print
Insert a record and return the last AUTO_INCREMENT value generated:
'INSERT INTO mytable (first_name, last_name) VALUES ("Sean", "Pringle")' $mysql query inserted as $record_id
Retrieve a single record into local variables:
'SELECT first_name, last_name FROM mytable WHERE id = 10' $mysql query fetch values into $first_name , $last_name
Update some records:
'UPDATE mytable SET field_1 = 10 WHERE field_2 < 100' $mysql query as $result
Get the number of records affected by the update:
$result affected as $num_rows
The astute among you may have recognised Raven uses Postfix Notation, and although it isn't very obvious here, Raven also uses whitespace to define code blocks (a la Python). The core library is made up of short functions using only English words and because I only care about talking to MySQL I can use:
Ahhh, the luxury of simplicity... The Raven engine is written in C and compiles to a very small (for a scripting language! ~100K) standalone binary on Linux. Postfix Notation and significant whitespace are not everyone's cup of tea, but I think the result here is quite elegant, particularly in combination with SQL which tries very hard to emulate natural langauge. And at the end of the day, I figure there are already plenty of people following the herd and using the well known scripting languages, so I might as well go have fun some place nobody else is :-) |