ActiveRecord without Rails

BEGIN { puts “hey all” }
hey all

Can anyone point me to a good tutorial for using ActiveRecord without
Rails?
Right now I’m just stealing what information I can from various sources.

Thanks,
aRi
--------------------------------------------|
If you’re not living on the edge,
then you’re just wasting space.

From: Ari B. [mailto:[email protected]]
Sent: Tuesday, July 31, 2007 7:51 PM

Can anyone point me to a good tutorial for using ActiveRecord without
Rails?
Right now I’m just stealing what information I can from various sources.

Corresponding chapters of AWDwR[1] are the best source AFAIK (despite
the
name of entire book).

V.

1: http://www.pragmaticprogrammer.com/title/rails2/index.html

Ari B. wrote:

BEGIN { puts “hey all” }
hey all

Can anyone point me to a good tutorial for using ActiveRecord without
Rails?
Right now I’m just stealing what information I can from various sources.

It’s a few years old… but here:

Good luck!

Robby

On Wed, Aug 01, 2007, Ari B. wrote:

Can anyone point me to a good tutorial for using ActiveRecord without
Rails?
Right now I’m just stealing what information I can from various sources.

What do you need to know? You can (more or less) just install
activerecord, require it, and go to town. You still have to define your
“models” just as you would in Rails, but they don’t need to be in
magically named files or anything fancy like that.

You do need to establish the connection by hand, but that’s usually as
easy as:

ActiveRecord::Base.establish_connection({
:adapter => ‘sqlite3’,
:dbfile => ‘/home/ben/.sqlite/counts.sqlite’
})

of course, whatever would normally go in the database section of your
configuration goes into that little hash.

I use AR outside of Rails every day and haven’t had much trouble. If
you’re having specific problems, let us know… but for the most part,
there’s nothing scary about doing it, just go for it :slight_smile:

Ben

2007/7/31, Ari B. [email protected]:

Can anyone point me to a good tutorial for using ActiveRecord without
Rails?
Right now I’m just stealing what information I can from various sources.

Here’s a console app using it

in case you’re not limiting yourself to ActiveRecord…
see Og

rthompso@jhereg: ~$ cat simpleSqlite3.rb
require ‘rubygems’
require ‘sqlite3’
require ‘og’

class SimpleTest
property :name, String
property :ts, String

property :oid, Integer

set_table :simpletest

end

$DBG=true
og_sqlite = {
:destroy_tables => false,
:store => :sqlite,
:user => ‘rthompso’,
:password => ‘rthompso’,
:name => ‘test’
}

db = Og.setup(og_sqlite)

store = db.get_store

st = SimpleTest.new
st.name = ‘Test entry’
st.ts = Time.now.to_s
st.save

rthompso@jhereg: ~$ ruby simpleSqlite3.rb
INFO: Og uses the Sqlite store.
DEBUG: Og manageable classes: [SimpleTest]
DEBUG: CREATE TABLE ogsimpletest (name text, ts text, oid integer
PRIMARY KEY)
INFO: Created table ‘ogsimpletest’.
DEBUG: SELECT * FROM ogsimpletest LIMIT 1
DEBUG: SELECT * FROM ogsimpletest LIMIT 1
DEBUG: INSERT INTO ogsimpletest (oid, name, ts) VALUES (NULL, ‘Test
entry’, ‘Tue Jul 31 15:28:10 -0400 2007’)
DEBUG: SELECT last_insert_rowid()

rthompso@jhereg: ~$ sqlite3 ./test.db “select * from ogsimpletest”
Test entry|Tue Jul 31 15:28:10 -0400 2007|1