Dear all, Is it possible to have ActiveRecord functionality using just a Ruby script rather than generating a full RoR application? I''m looking for sth without interface nor control; a single ruby script to connect, read table1, write table2 and disconnect. I''ve started declaring a class Test < ActiveRecord::Base end Any thoughts ? Many thanks, Andre -- Posted via http://www.ruby-forum.com/.
require ''rubygems'' require_gem ''activerecord'' ActiveRecord::Base.establish_connection( :adapter => ''mysql'', :host => ''localhost'', :database => ''my_database'', :username => ''myuser'', :password => ''mypassword'' ) class MyModel < ActiveRecord::Base end Then do any ussual AR activity. Andre Parmeggiani wrote:>Dear all, > >Is it possible to have ActiveRecord functionality >using just a Ruby script rather than generating a >full RoR application? > >I''m looking for sth without interface nor control; >a single ruby script to connect, read table1, >write table2 and disconnect. > >I''ve started declaring a > >class Test < ActiveRecord::Base > >end > >
Andre, Have a look here: http://blog.dangdev.com/articles/2005/11/22/using-active-record-to-test-a-sql-server-legacy-db-connection This guy, I think, did what you are asking about. HTH Mel On 12/13/05, Andre Parmeggiani <aap-KSrkq06vtGZfJ/NunPodnw@public.gmane.org> wrote:> > > Dear all, > > Is it possible to have ActiveRecord functionality > using just a Ruby script rather than generating a > full RoR application? > > I''m looking for sth without interface nor control; > a single ruby script to connect, read table1, > write table2 and disconnect. > > I''ve started declaring a > > class Test < ActiveRecord::Base > > end > > > Any thoughts ? > > Many thanks, > Andre > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, Dec 13, 2005 at 04:10:11PM +0100, Andre Parmeggiani wrote:> Is it possible to have ActiveRecord functionality > using just a Ruby script rather than generating a > full RoR application? > > I''m looking for sth without interface nor control; > a single ruby script to connect, read table1, > write table2 and disconnect. > > I''ve started declaring a > > class Test < ActiveRecord::Base > > end > > Any thoughts ?Sure. require ''rubygems'' # Or require the library directly without RubyGems require ''activerecord'' ActiveRecord::Base.establish_connection( :adapter => ''...'', # Indicate your desired adapter :database => ''...'' ) class Foo < ActiveRecord::Base end That''s it. marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>
Yep, absolutely sweet ! I''ve just add :socket => "/var/run/mysql/mysql.sock" to the parameters and bingo! Also, from Mel''s link, i''ve got this one: http://www.intertwingly.net/blog/2005/08/09/Rails-Confidence-Builder Many thanks again André -- Posted via http://www.ruby-forum.com/.