Rafael S. Suguiura
2010-May-10 17:38 UTC
Creating a database view in a Rails way without ActiveCouch?
Is it possible to create a database view in a Rails way without ActiveCouch? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rafael S. Suguiura
2010-May-10 18:23 UTC
Re: Creating a database view in a Rails way without ActiveCouch?
Hey guys, good news! I''ve just found out a way to do the job (in a not so clean way) by creating a new migration and executing a raw sql. For instance, I''m going to use a *Session* which has a *start* and *end*datetime as attributes and *duration* as a derived attribute. So, I created an empty migration: script/generate migration create_sessions_view and filled it as follows: class CreateSessionsView < ActiveRecord::Migration def self.up create_view_sql = "CREATE VIEW sessions_view AS SELECT *, strftime(''%s'',end) - strftime(''%s'',start) AS duration FROM sessions" execute(create_view_sql) end def self.down drop_view_sql = "DROP VIEW sessions_view" execute(drop_view_sql) end end And to finish it up: rake db:migrate I hope it helps those who are willing to create a view in the future. (I think it would be better if ActiveRecord::Migration had a create_view method, but as it doesn''t have for now, I think this is the simplest work around =) Cheers, Rafael On 10 May 2010 17:38, Rafael S. Suguiura <rafael.suguiura-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is it possible to create a database view in a Rails way without > ActiveCouch?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-10 18:56 UTC
Re: Creating a database view in a Rails way without ActiveCouch?
Rafael S. Suguiura wrote:> Is it possible to create a database view in a Rails way without > ActiveCouch?rails_sql_views plugin, I believe. Or did you mean a CouchDB view? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rafael S. Suguiura
2010-May-10 23:11 UTC
Re: Re: Creating a database view in a Rails way without ActiveCouch?
On 10 May 2010 15:56, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rafael S. Suguiura wrote: > > Is it possible to create a database view in a Rails way without > > ActiveCouch? > > rails_sql_views plugin, I believe. Or did you mean a CouchDB view? >It''s not the CouchDB view (it would be too overpower to my app...), but the plugin seems to do the job. I''ll try it later! :) Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.