[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ActiveRecord without Rails

Ari Brown

7/31/2007 4:51:00 PM

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.



5 Answers

Robby Russell

7/31/2007 4:58:00 PM

0

Ari Brown 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:

* http://intertwingly.net/blog/2005/08/09/Rails-Confiden...

Good luck!

Robby

--
Robby Russell
http://www.robbyo... # my blog
http://www.plane... # my business
http://www.programmin... # my book


Thomas Wieczorek

7/31/2007 5:01:00 PM

0

2007/7/31, Ari Brown <ari@aribrown.com>:
>
> 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
http://www.oreillynet.com/pub/a/ruby/2007/06/21/how-to-build-simple-console-apps-with-ruby-and-activer...

Ben Bleything

7/31/2007 5:10:00 PM

0

On Wed, Aug 01, 2007, Ari Brown 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 :)

Ben

R. Mark Volkmann

7/31/2007 5:11:00 PM

0



Reid Thompson

7/31/2007 7:31:00 PM

0

in case you're not limiting yourself to ActiveRecord...
see Og

http://www.nitroproject.org/docs/rdoc/...


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