rails on oracle 2011
DESCRIPTION
RailsConf 2011 BoF session "Rails on Oracle" slidesTRANSCRIPT
![Page 1: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/1.jpg)
Rails on Oracle
![Page 2: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/2.jpg)
Raimonds Simanovskis
github.com/rsim
@rsim
![Page 3: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/3.jpg)
Self-promotion :) eazybi.com
![Page 4: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/4.jpg)
How to contribute to ActiveRecord
Oracle enhancedadapter
![Page 5: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/5.jpg)
Main componentsRails 3.x
ActiveRecord Arel
Arel::Visitors::OracleSQL
ActiveRecord::ConnectionAdapters::
AbstractAdapter
OracleEnhancedAdapter
execute
results
build query
![Page 6: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/6.jpg)
What Oracle Enhanced adapter does
database connection
value quoting
column type mapping
results type mapping
schema definition stmts
schema dump
structure dump
metadata queries
custom CUD procedures
custom schema stmts
context index creation
AR patches
![Page 7: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/7.jpg)
Oracle Data TypesRuby Rails Oracle
Fixnum :integer NUMBERFloat :float NUMBER
BigDecimal :decimal NUMBER, DECIMALTime :datetime DATETime :time DATEDate :date DATEString :string VARCHAR2String :text CLOBString :binary BLOB
True/FalseClass :boolean NUMBER(1), CHAR(1)
![Page 8: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/8.jpg)
Latest additionRuby Rails OracleString :raw RAW
![Page 9: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/9.jpg)
Legacy schemas
class Employee < ActiveRecord::Base set_table_name "hr_employees" set_primary_key "employee_id" set_sequence_name "hr_employee_s"
set_date_columns :hired_on, :birth_date_on set_datetime_columns :last_login_time
set_boolean_columns :manager, :active
ignore_table_columns :attribute1, :attribute2end
![Page 10: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/10.jpg)
ActiveRecordwith
PL/SQLCRUD
procedures
class Employee < ActiveRecord::Base set_create_method do plsql.employees_pkg.create_employee( :p_first_name => first_name, :p_last_name => last_name, :p_employee_id => nil )[:p_employee_id] end set_update_method do plsql.employees_pkg.update_employee( :p_employee_id => id, :p_first_name => first_name, :p_last_name => last_name ) end set_delete_method do plsql.employees_pkg.delete_employee( :p_employee_id => id ) endend
![Page 11: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/11.jpg)
Full-text indexesadd_context_index :posts, [:title, :body, # specify aliases always with AS keyword "SELECT comments.author AS comment_author, " + "comments.body AS comment_body " + "FROM comments WHERE comments.post_id = :id" ], :name => 'post_and_comments_index', :index_column => :all_text, :index_column_trigger_on => [:updated_at, :comments_count], :sync => 'ON COMMIT'
Post.contains(:all_text, "hello")Post.contains(:all_text, "{first} within title")Post.contains(:all_text, "{first} AND {post}")
![Page 12: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/12.jpg)
Gemfile
gem “ruby-oci8”, “~>2.0.4”gem “activerecord-oracle_enhanced-adapter”, “~>1.3.2”
gem “activerecord-oracle_enhanced-adapter”,:git=> “git://github.com/rsim/oracle-enhanced.git”
![Page 13: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/13.jpg)
Currently testing on ActiveRecord versions
2.3.x3.0.x
3.1.beta
![Page 14: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/14.jpg)
Currently testing on Oracle versions
10.2.0.4
11gR2 should be OK :)
![Page 15: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/15.jpg)
Currently testing on Ruby platforms
Ruby 1.8.7 Ruby 1.9.2 JRuby 1.6
ruby-oci8 2.0.4 ruby-oci8 2.0.4 ojdbc6.jar
oracle_enhanced adapter
![Page 16: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/16.jpg)
Reporting issues
![Page 17: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/17.jpg)
Where?
http://groups.google.com/group/oracle-enhanced
http://github.com/rsim/oracle-enhanced/issues
![Page 18: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/18.jpg)
How?Provide full example
require "rubygems"gem "activerecord", "3.0.5"gem "activerecord-oracle_enhanced-adapter", "1.3.2"require "active_record"
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "orcl", :username => "hr", :password => "hr")
ActiveRecord::Base.connection.instance_eval do drop_table :test_categories rescue nil create_table :test_categories, :force => true do |t| t.string :name t.string :category_code endend
class TestCategory < ActiveRecord::Baseend
category = TestCategory.new(:name=>"hl", :category_code=>"hd")category.id = 1category.save!
p category
![Page 19: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/19.jpg)
IdeallyGithub pull request
![Page 20: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/20.jpg)
Other libraries
![Page 21: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/21.jpg)
ruby-plsql gemplsql.connect! "hr","hr","xe"
plsql.test_uppercase('xxx') # => "XXX"plsql.test_uppercase(:p_string => 'xxx') # => "XXX"plsql.test_copy("abc", nil, nil) # => { :p_to => "abc", # :p_to_double => "abcabc" }plsql.test_copy(:p_from => "abc", :p_to => nil, :p_to_double => nil) # => { :p_to => "abc", # :p_to_double => "abcabc" }plsql.hr.test_uppercase('xxx') # => "XXX"plsql.test_package.test_uppercase('xxx') # => 'XXX'plsql.hr.test_package.test_uppercase('xxx') # => 'XXX'
plsql.logoff
![Page 22: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/22.jpg)
ruby-plsql-specideal languagefor writing tests
powerful testing toolswith “readable” syntax
library for callingPL/SQL procedures
from Ruby
RSpec
ruby-plsql
![Page 23: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/23.jpg)
http://github.com/rsim/mondrian-olap
![Page 24: Rails on Oracle 2011](https://reader036.vdocument.in/reader036/viewer/2022062703/554f49c3b4c905b9508b47bf/html5/thumbnails/24.jpg)
More information
http://blog.rayapps.com
http://github.com/rsim/oracle-enhanced
http://groups.google.com/group/oracle-enhanced