Loading the MySQL drivers into GNU Smalltalk
Friday, November 14th, 2008It’s an unfortunate fact that many Open Source projects have documentation that is sadly lacking. A case in point is GNU Smalltalk.
Smalltalk is one of my favourite languages but a decent Smalltalk implementation that fits with your native window manager is hard to find. The point of GNU Smalltalk is that it works “headlessly” (Smalltalk invented the graphical user-interface and the integrated development environment so this is quite a departure), so I can still use my favourite text editor and run stuff from the command line. Just like Ruby!
However, it’s taken me a couple of hours to figure out how to simply connect to a database. But now I have, here it is:
- Install GNU Smalltalk (in my case using MacPorts):
sudo port install gst - Start GNU Smalltalk and create a working image:
cd /Users/rahoulb/source/st
gst
st> ObjectMemory snapshot: 'work.im'. - Ctrl-D to exit Smalltalk and then restart using your new image:
gst -I work.im - Load the DBI database driver:
st> PackageLoader fileInPackage: 'DBI'.
Load the MySQL driver:
st> PackageLoader fileInPackage: 'DBD-MySQL'.
Save your image so you don’t need to reload these packages again:
st> ObjectMemory snapshot. -
Open a connection to your database:
st>con:= DBI.Connection connect: 'dbi:MySQL:dbname=mydatabase' user: 'myuser' password: 'mypassword'.
Grab some data:
st>results:= con select: 'select name from customers limit 10;' - Bask in the glory of your data