Re: Mixing OO and DB
Date: Thu, 28 Feb 2008 10:03:06 -0800 (PST)
> 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
> 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.
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 .
//frebe Received on Thu Feb 28 2008 - 19:03:06 CET