Forum: Ruby ActiveRecord without Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
425cab08658a06567879717de154552c?d=identicon&s=25 Ari Brown (Guest)
on 2007-07-31 18:52
(Received via mailing list)
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.
2c7c807a1df0c76a8fc823c709b501a9?d=identicon&s=25 Victor "Zverok" Shepelev (Guest)
on 2007-07-31 18:59
(Received via mailing list)
From: Ari Brown [mailto:ari@aribrown.com]
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
B84d42a3a5c343f8fc6ab7d7f47fd3f5?d=identicon&s=25 Robby Russell (Guest)
on 2007-07-31 19:00
(Received via mailing list)
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-Conf...

Good luck!

Robby
88de1beaaacae26b839f2e6aebf857b6?d=identicon&s=25 Thomas Wieczorek (Guest)
on 2007-07-31 19:04
(Received via mailing list)
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/ho...
90a73d9875462aaa9fab2feffafbffe7?d=identicon&s=25 Ben Bleything (Guest)
on 2007-07-31 19:11
(Received via mailing list)
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
91e1fb8bd265b7629491ab64c42f0906?d=identicon&s=25 Reid Thompson (Guest)
on 2007-07-31 21:31
(Received via mailing list)
in case you're not limiting yourself to ActiveRecord...
see Og

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


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
This topic is locked and can not be replied to.