Do I have to use Rails to use a database?

I’ve learned the basics of Ruby, and have been making websites with
xhtml, css, and eruby. I used IO.readlines and text files to store and
access info on menu items (http://partysushi.com/menu.rhtml) but it is
apparent that an SQL database would be a better way to deal with that
sort of thing. I understand the concept and immediate benefits of using
a database (that IO stuff is a rudimentary database isn’t it?) but I
don’t know where to start in learning how to use one.

I see two basic categories of books and help-me things: Programming with
Ruby and Ruby on Rails. I was under the impression that getting a Rails
book would be the quickest way to learn to use a database, but going
through

I don’t think I need a whole framework, and it’s all still over my head.
I don’t like the look of all those generated files and directories. I
just want a database, can’t I just have a database?

On 4/12/07, Jonathan D. [email protected] wrote:

I’ve learned the basics of Ruby, and have been making websites with
xhtml, css, and eruby. I used IO.readlines and text files to store and
access info on menu items (http://partysushi.com/menu.rhtml) but it is
apparent that an SQL database would be a better way to deal with that
sort of thing. I understand the concept and immediate benefits of using
a database (that IO stuff is a rudimentary database isn’t it?) but I
don’t know where to start in learning how to use one.

I don’t think I need a whole framework, and it’s all still over my head.
I don’t like the look of all those generated files and directories. I
just want a database, can’t I just have a database?

Ruby has to my knowledge, 3 primary ways of using a Database.
Rails is famous for using ActiveRecord, but ActiveRecord can be used
independently of Rails. Its well worth learning as it makes database
use very easy indeed.

Another Ruby framework Nitro uses a database layer called Og
(ObjectGraph)
which I presume (not sure) can be used externally to Nitro.

Lastly theres the default, DBI. This is a more conventional database
access
library, where you are kept pretty close to the SQL mechanisms.

I’d say using rails is a bit of overkill, and you seem to have come
to this conclusion as well. i’d also go so far as to say that using
activerecord would be overkill for something simple like your menu.
you most likely would never use the things that make activerecord
beneficial.

if you want something more lightweight than activerecord, check out
DBI, which was suggested previously. as far as the actual database
goes, you might want to take a look at sqlite3 as opposed to something
like mysql/postgresql/etc.

That sounds perfect! Now the question is: How do I learn to use DBI and
SQLite? Any suggestions on books and or tutorials?

Oh, well, I’m using site5 hosting, and it already has MySQL installed.
There’s even a page in the account manager to add MySQL databases.
Since it’s already installed, I guess I’ll use that. But I still have
to find out how to use it.

Chris H. wrote:

I’d say using rails is a bit of overkill, and you seem to have come
to this conclusion as well. i’d also go so far as to say that using
activerecord would be overkill for something simple like your menu.
you most likely would never use the things that make activerecord
beneficial.

if you want something more lightweight than activerecord, check out
DBI, which was suggested previously. as far as the actual database
goes, you might want to take a look at sqlite3 as opposed to something
like mysql/postgresql/etc.

That sounds perfect! Now the question is: How do I learn to use DBI and
SQLite? Any suggestions on books and or tutorials?

Thanks!

dbi:

http://ruby-dbi.rubyforge.org/

sqlite3:

http://www.sqlite.org/

download for ruby-dbi is:

http://rubyforge.org/projects/ruby-dbi/

Chris H. wrote:

see the first link i sent, that has the installation instructions for
ruby-dbi

Yeah. I don’t have much experience with this sort of thing, so I just
wanted to make sure I understood those instructions correctly.

if you are on shared hosting, then your provider may already have dbi
installed. you’d have to talk to them to know for sure (or write a
test script).

Oh, I’ll try that :smiley:

Thanks again

see the first link i sent, that has the installation instructions for
ruby-dbi

http://ruby-dbi.rubyforge.org/

if you are on shared hosting, then your provider may already have dbi
installed. you’d have to talk to them to know for sure (or write a
test script).

Chris H. wrote:

download for ruby-dbi is:

http://rubyforge.org/projects/ruby-dbi/

Thanks!
So, it looks like I should

1)I download download the dbi-0.1.1.tar.gz file, and upload it to my
server. Where should I put it? The cgi-bin directory?

  1. Unpack it using command
    %tar zxf dbi-0.1.1.tar.gz

(chdir to the right directory, then)

  1. input command
    %ruby setup.rb config --with=dbi,dbd_mysql
    to configure it to install dbi and the MySQL drivers (since I’m using
    the already availabe MySQL database)

  2. input %ruby setup.rb setup
    %ruby setup.rb install

and once I do that, Ruby DBI will be all set and ready to use, right?

I don’t think I need a whole framework, and it’s all still over my head.
I don’t like the look of all those generated files and directories. I
just want a database, can’t I just have a database?

Hi Jonathan

Have a look at Sequel. It’s a very simple and efficient database access
and ORM library for Ruby. Docs are here:

http://sequel.rubyforge.org/

Best
Sharon