Welcome to the adventure

db4o

Saturday March 18, 2006

While working on a new .net project, I went hankering off for the best way, currently, to serialize objects to a database and query for them back. I’m not writing SQL code by hand, I’m not annotating all of my classes, and I’d like to avoid writing huge XML map files for all my dang objects. So I was looking at NHibernate, looks good, very popular. Then someone in #mono writes 4 letters, just 4 letters, to my question “Is NHibernate what I should be using?” and my world of data access objects was rocked. Completely.

Check out this gem: db4objects. Written natively for both .net and java, and they even have explicit mono support. The usage model and API are simply amazing. Here’s a piece from the tutorial on the mono wiki:


        ObjectContainer objectContainer = Db4o.OpenFile("myDatabaseFile.db");
        objectContainer.Set(new Pilot("Rubens Barrichello", 101));
        objectContainer.Commit();

        // Note the awesome query by example --
        ObjectSet objectSet = objectContainer.Get(new Pilot(null, 101));
        foreach (object element in objectSet) {
            Console.WriteLine(element);
        }
        objectContainer.Close();

Geeze. Completely out of hand. And it’s apparently much faster than Hibernate with MySql. The whole package is a 400KB dll/jar you deploy with your app.

No Comments »

No comments yet.

Leave a comment