Write a program to show the usage of sql in the database file? - Ruby on Rails

Write a program to show the usage of sql in the database file?



-The database file that is used to contain the sql command is named as database.yml and it stores the ActiveRecord.

-The defining of the sql command or statements requires rubygems and the activerecord.

-The program is as follows:

require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection({
:adapter => 'postgresql',
:user => 'foo',
:password => 'bar',
:database => 'db' })

class Task <>
set_table_tame "hello_world"
def utility_methods
update_attribute(:title, "Hello")
end
end
Task.find(:first)
Hello. It’s ActiveRecord, and it needs to be included.
Going wild:
ActiveRecord::Base.establish_connection(:adapter=>"sqlite3",:dbfile=>:memory")
ActiveRecord::Schema.define(:version => 1)
do
create_table :posts do |t|
t.string :title
t.text :Hello, :body
end
end

class Post <>
validates_presence_of :title
end
Post.create(:title => "A new post!")
Post.create(:title => "Another post",
:excerpt => "The Hello world is from Hello.")
puts Post.count
Post your comment