Re: Mixing OO and DB

From: frebe <frebe73_at_gmail.com>
Date: Thu, 28 Feb 2008 10:03:06 -0800 (PST)
Message-ID: <7f5a0e8b-94a3-4f86-871f-1c7ce2d6f441_at_x41g2000hsb.googlegroups.com>


> So, for instance, if we must fetch an employee record frequently in
> various parts of our application it is better to use a function like
> this:
>
>   Employee e = Employee.find("Bob"):
>
> Than it is to use raw SQL like this all through our app.
>
>   DataRow e = exec("Select * from EmployeeTable where name = 'Bob';");

Why is the first line better than the last line? One obvious disadvantage with the first line is that you need an implementation of Employee.find.

> Of course we can implement other kinds of 'find' methods.  
> find_by_date, find_by_salary, etc, etc.  Every different query we use
> on a regular basis, we can create a verb for in our DSL.  That verb is
> a function call of some kind.

And for queries we don't use on a regular basis? We can use "raw" SQL, or?

> So we have not lost the power of the flexible query language.

If you still allow "raw" SQL for queries not used on a regular basis, the power is not lost. But if you must have a find_by_xxx, for every possible select statement, the power is lost.

> We still have it, and we still use it.  But we also hide it from the bulk of the
> application.

What is the benefit with hiding SQL from the bulk of the application?

> That allows us to create a polymorphic API below which we can swap out
> different database implementations, or even stubs and dummies .

If you have a lot of find_by_xxx methods, swapping would still be quite difficult.

//frebe Received on Thu Feb 28 2008 - 19:03:06 CET

Original text of this message