ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -


a colleague of mine designing sql queries 1 below produce reports, displayed in excel files through external data query. @ present, reporting processes on db required (no crud operations).

i trying convince him better use ruby orm in order able display data in rails/sinatra app.

despite obvious advantages in displaying data, advantages there him in learning use orm sequel or datamapper?

the sql queries writing quite complex, , being relatively new sql, complains time-consuming , confusing. possible write extremely complex queries orm? , if so, suitable(i have heard sequel legacy dbs)? , advantages of learning ruby , using orm versus sticking plain sql, in making complex database queries?

i'm datamapper maintainer, , think complex reporting should use sql.

while think someday we'll have dsl provides power , conciseness of sql, i've seen far requires write more ruby code sql complex queries. rather maintain 5 line sql query 10-15 lines of ruby code describe same complex operation.

please note complex.. if have simple, use orm's build-in finders. however, believe there line can cross sql becomes simpler. now, apps aren't reporting. may have alot of crud type operations, orm suited , far better doing things hand.

one thing orm provide sort of organization application logic. can group code based around each model in same file. it's there i'll put complex sql query, rather embedding in controller, eg:

class user   include datamapper::resource    property :id,   serial   property :name, string,  :length => 1..100, :required => true   property :age,  integer, :min => 1, :max => 130    def self.some_complex_query     repository.adapter.select <<-sql       select ...         ...        ...        ... more complex stuff here ...     sql   end end 

then can generate report using user.some_complex_query. push sql query view if wanted further cleanup code.

edit: "view" in above sentence meant rdbms view, rather view in mvc context. wanted clear potential confusion.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -