Sinatra Oracle

Sinatra – Oracle

oracle installation for local

http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html

 

Setting up sinatra with oracle database, this has eaten up my time so just thought will give a clear idea of settings.

Gemfile — add these to your gem file

# Database requires
gem ‘ruby-plsql’
gem “sinatra-activerecord”
gem ‘ruby-oci8’
gem “activerecord”
gem ‘activerecord-oracle_enhanced-adapter’

gem ‘standalone_migrations’

———————————————————

database.yml

development:
adapter: oracle_enhanced
database: data_base_name
username: user_name
password: password
host: hostname
port: 1521

Note: oracle database would be by default XE,oracle default user name would be ‘system’, host kindly check for your system listener oracle and use the same(usually it will be your system name)

 

—————————————————————

create a file in config named environment.rb

#The environment variable DATABASE_URL should be in the following format:
# =>database://{user}:{password}@{host}:{port}/path

require ‘active_record’
require ‘activerecord-oracle_enhanced-adapter’
require ‘active_record/connection_adapters/oracle_enhanced_adapter’

configure :development do

DB_CONFIG = YAML::load(File.open(‘config/database.yml’))

db = URI.parse(“jdbc:oracle://#{DB_CONFIG[‘username’]}:#{DB_CONFIG[‘password’]}@#{DB_CONFIG[‘host’]}:#{DB_CONFIG[‘port’]}/#{DB_CONFIG[‘database’]}”)
ActiveRecord::Base.establish_connection(:adapter => “oracle_enhanced”, :database => “//#{DB_CONFIG[‘host’]}/{DB_CONFIG[‘database’]}”, :username => “#{DB_CONFIG[‘username’]}”,:password => “#{DB_CONFIG[‘password’]}”)
end

—————————————————————————

Rakefile – helpful for migrations

add belowlines

require ‘active_record’
require ‘activerecord-oracle_enhanced-adapter’
require ‘sinatra/activerecord’
require ‘sinatra/activerecord/rake

—————————————————————————-

app.rb — add the following

require ‘./config/environments’

—————————————————————————-

create a file for migrations and models

and run the

rake db:migrate

and further learning would be easier to understand go through the reference.

——————————————————————————

References

http://www.oracle.com/technetwork/testcontent/rubyrails-085107.html

https://github.com/rsim/oracle-enhanced#without-rails-and-bundler

 

Leave a comment