Squeak Smalltalk and Databases

I've been working in Smallalk and Seaside for quite a while now, but something I haven't quite gotten around to yet is trying to hook Squeak up to a database in a manner that I think could actually scale for a professional project. Now, I mean directly hook it up, so far, professionally, I've been using it against web services written in .Net against Microsoft SQL Server, which scales just fine, but leaves me still working in .Net, and I'd much rather work in pure Smalltalk.

Object Databases

I've tried several object databases, GOODS, Magma, and OmniBase, and while interesting experiences, I find them not quite acceptable for various reasons. OmniBase is file based, and has odd semantics that make hooking it up to multiple images and programming web apps against it difficult.

GOODS is very low level and bare bones, it works great, but you have to pre-index all your data, it has no query capabilities beyond what you provide in your object model, which can make performance quite horrible unless you know exactly what you're doing and make very strict choices about how your data is stored. GOODS is also a one man show, so I'm not thrilled by the support I'd have available, were I trying to do something serious with it, though it works great for hobby and prototype programming.

Magma has queries, and is very similar to GOODS as far as ease of use goes but like GOODS, it's a one man show, and I just wouldn't feel comfortable doing anything truly serious on a one man show kind of database. This, for Squeak at least, seems to rule out object databases, for me anyway, though I hear Gemstone is going to support Seaside. I'm hopeful, for Gemstone is truly an enterprise ready object database, it's just vaporware at this point, nothing production ready.

All of them seem rather slow when it comes to bulk inserts, and there are various solutions and workarounds depending on which version of Squeak you're running, but a guy can only jump through so many hoops before he says "fuck it". I've hit that point more than a few times when working with larger datasets and trying to do bulk inserts or queries.

Now, don't get me wrong, Goods, Magma, and OmniBase are great products, and I'm sure have their uses, they're just not something I'd throw up to my boss and say "hey, let's use this for this big upcoming project", because it's hard enough throwing Squeak at them and having to support that decision over something like .Net which everyone already knows how to use, let alone taking away their familiar relational databases. I'd actually prefer something like Gemstone, time will tell if that preference pans out.

Relational Databases

So, on to relational databases. Squeak has ODBC support, but it's single threaded and blocks the VM when querying, so while it works for demos and low traffic apps against pretty much any database, I wouldn't try anything too big with it; it just can't scale. Blocking the whole VM, every time you run a query, just leaves me feeling a bit dirty and not too proud of whatever I just wrote.

Squeak basically supports two popular relational databases that I know of, natively, MySQL and PostgreSQL. Now, I use MySql for this blog, so I have some experience managing it, and I'm just not a big fan, compared to Microsoft SQL Server, which I work with professionally daily, MySQL just sucks, but PostgreSQL is a different story, I'm quite impressed with the latest release, which looks and runs very nice on Windows servers and has a nice admin tool.

MySQL is IMHO not much better than Microsoft Access, it's not an enterprise database. PostgreSQL, I think is much more comparable to SqlServer and Oracle and could be used for any size app. I have much more faith in its abilities and it has some cool features like table inheritance, which to an object bigot like myself, just makes me think relational databases aren't totally void of innovation.

Now if I can just talk my DBA into giving up Sql Server, ummm... yea, not gonna happen, but I've got a side project coming up that'll be totally green field development, no legacy database to worry about, hence my renewed interest in PostgreSQL, my new database of choice with Squeak.

Getting Started

So I installed the latest PostgreSQL, installed the PostgreSQL Client for Squeak from SqueakMap, then the GLORP port from SqueakMap, and gave it a shot.

I was immediately confronted with a nasty error that reminded me why I gave up last time I tried PostgreSQL. Something about the PostgreSQL driver's state machine not being valid, luckily enough time had passed that a few minutes Googling turned up a simple answer this time, unlike the last.

PostgreSQL installs with MD5 connection encryption turned on, which Squeak doesn't support out of the box. There are two fixes, either install the Cryptography package from SqueakMap, or turn encryption in PostgreSQL to "password" with a simple configuration change to the pg_hba.conf. I chose the latter, as its default install only accepts local connections anyway I'm not too concerned with encryption.

PostgreSQL fires up and runs without a problem, GLORP tests all run fine, so now I just have to learn GLORP and how to map my objects into PostgreSQL, but that, is going to have to be another story. I'm going to map the simple blog in Seaside into a PostgreSQL database to learn GLORP, and I'll post that code once I figure it out. I've done a bit already, and so far, I'm quite happy with GLORP.

Comments (automatically disabled after 1 year)

Brian Brown 6396 days ago

I came to a similar conclusion quite a while ago, but have been using ROE instead of glorp for my data access. I'll be interested to see how things go for you in this!

Ramon Leon 6396 days ago

I've felt this way for a while, just now getting around to writing about it though, due to my recent need for GLORP. I'm curious how your ROE experience is going, that's also on my to do list, I just haven't gotten around to it yet.

 6396 days ago

Have you found any good PostgreS tools? I'm not really happy with pgAdmin III.

Ramon Leon 6396 days ago

No, I'm just getting to know PostgreSQL myself, so far, pgAdmin III seems OK with me, what is it you don't like?

 6396 days ago

It doesn't even know SQL. It can just highlight keywords. No pretty printing, no folding, no indenting, nothing. Don't even think about tab completion. Error reporting is just a joke. And it core dumps from time to time. Opening a new window for a query is annoying.

It doesn't give out any sort of helpful feedback. It can not tell you why stuff is slow and what you can do against it. Why it does a nested loop on a join although you have an index on the attributes and so on. Yes you can run ANALYZE but mapping that back to your query is like doing source mapping (mapping bytecode to source code).

The list goes on. At least the 1.4 version can now save passwords. The 1.2 had a checkbox to save them but didn't actually save it. And they had the habit of fucking up your X11 session.

Ramon Leon 6396 days ago

Ah, gotcha, you want a sql development environment, I just want a decent admin tool. I'll let GLORP or ROE write the SQL for me, I'll stick to Smalltalk for my development environment. I keep the real programming, out of the database and in the application layer where I feel it belongs, so I don't do a lot of hairy SQL development. Databases are just persistence for me.

Alan Capewell 6395 days ago


slightly off topic but just wanted to let you know how useful your site is. I'm an old Smalltalk hack been doing Java for 10 years though. 2 weeks ago I stumbled across seaside and was blown away! This stuff is just awesome and your site is the one place I keep returning to for practical insights.

I also downloaded your image. It looks very professional and for the first time I'm not embarassed to demo squeak to my Java colleagues!

[...] Ramon Leon fait le point sur l’état du support des bases de données avec Squeak. Deux approches sont possibles : les bases de données objets (SGBDO), les bases de données relationnelles (SGBR). Ils passent en revue trois outils de type SGBDO : Magma, Omnibase et GOODS. Même si ce sont des outils intéressants, aucun n’est satisfaisant à ces yeux pour un projet professionnel. Ce sont de plus des outils supportés par un seul dévelopeur, ce qui poser des problèmes de perennité. [...] ]]>

Ramon Leon 6395 days ago

Thanks Alan, glad you like the site, send all those Java colleagues over here as well, show em a real web framework.

 6394 days ago

Yeah, if your model is somewhat sane and your database is not that big you can do this.

But if your model is designed by a manager for a customer who wants everything and your database is 2 GB then you have to hand tune your queries (more than 200 LOC queries).

Ramon Leon 6394 days ago

Or find better work.

Bernard Notarianni 6393 days ago

Agree with Ramon. If your are in a context where your model is designed by somebody else, and that person accept everything from the client before asking you to do it, Seaside/PostresSQL cannot do much for you, and Java/Oracle neither actually ;-)

[...] First he talks about selecting a database. He chooses PostgreSQL, and talks about his experience in setting it up. He chooses Glorp for object-relational mapping (ORM). Next, he shows how to take his Build-a-blog-in-15-minutes example and instead of using an OrderedCollection to store posts and comments, as was shown in the first demo, he shows how to set up Glorp to interface the blog to tables in PostgreSQL. He also compares/contrasts Glorp with Ruby on Rails’s ActiveRecord framework. Very interesting reading. No screencast this time, but it looks like he posted the necessary code. [...] ]]>

[...] Squeak Smalltalk and Databases [...]

Esteban A. Maringolo 6010 days ago

Are you still using Squeak's GLORP against a local PostgreSQL Server? What is your experience summary/conclusion?

Best regards.

Ramon Leon 6009 days ago

I was until recently, if you want a relational db, GLORP and PostgreSQL are the way to go for sure. I'm just finding that the projects I tend to work on are small private applications that don't justify the complexity introduced by mapping, so I prefer simpler solutions like object db's or image persistence, or just using serialization to disk. When you're just replacing word and excel files for a small group of users, the bar isn't that high, you don't need ACID level persistence or industrial strength db's.

Leon Smith 5984 days ago

Are there any decent tutorials about using MySQL with Squeak ? I've looked at everything Goggle comes up with. I'm using the latest Squeak on the latest Ubuntu with the latest MySQL and have upgraded to the latest MySQL driver and Cryptography, but cannot connect using the simplest example. I keep getting timeout errors.

I stongly disagree that MySQL "is not much better than Access" or that it is not an Enterprise DB. So I'd like to give it a shot with Squeak. Am I missing something obvious ?

Ramon Leon 5983 days ago

I couldn't tell you, I don't really use it with Smalltalk. MySql is a perfectly good database for many purposes, don't let me dissuade you from using it. I just feel PostgreSQL is much better written from the ground up.

about me|good books|popular posts|atom|rss