Just ActiveRecord

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

On Tue, Dec 13, 2005 at 04:10:11PM +0100, Andre Parmeggiani wrote:

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

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,

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

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é