SlideShare a Scribd company logo
Rails on Oracle
Raimonds Simanovskis


       github.com/rsim




          @rsim
Self-promotion :)   eazybi.com
How to contribute to
  ActiveRecord
 Oracle enhanced
     adapter
Main components
                          Rails 3.x
                          build query
 ActiveRecord                                   Arel
                               SQL
                                        Arel::Visitors::Oracle
               execute
     results




OracleEnhancedAdapter

      ActiveRecord::
   ConnectionAdapters::
     AbstractAdapter
What Oracle Enhanced
      adapter does
  database         metadata       custom CUD
 connection        queries         procedures

                   schema            custom
value quoting
                definition stmts   schema stmts

column type                       context index
                schema dump
  mapping                           creation

results type       structure
                                   AR patches
  mapping            dump
Oracle Data Types
    Ruby            Rails             Oracle
    Fixnum          :integer        NUMBER
     Float             :float        NUMBER
  BigDecimal       :decimal      NUMBER, DECIMAL
     Time         :datetime          DATE
     Time              :time         DATE
     Date              :date         DATE
     String           :string      VARCHAR2
     String            :text         CLOB
     String          :binary         BLOB
True/FalseClass    :boolean     NUMBER(1), CHAR(1)
Latest addition
Ruby     Rails   Oracle
String   :raw    RAW
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, :attribute2
end
class Employee < ActiveRecord::Base
             set_create_method do
               plsql.employees_pkg.create_employee(
                 :p_first_name => first_name,

ActiveRecord     :p_last_name => last_name,
                 :p_employee_id => nil
               )[:p_employee_id]
     with    end
             set_update_method do

   PL/SQL      plsql.employees_pkg.update_employee(
                 :p_employee_id => id,
                 :p_first_name => first_name,
   CRUD        )
                 :p_last_name => last_name


 procedures  end
             set_delete_method do
               plsql.employees_pkg.delete_employee(
                 :p_employee_id => id
               )
             end
           end
Full-text indexes
add_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}")
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”
Currently testing on
ActiveRecord versions
        2.3.x
        3.0.x
      3.1.beta
Currently testing on
 Oracle versions
     10.2.0.4

 11gR2 should be
     OK :)
Currently testing on
  Ruby platforms
          oracle_enhanced adapter




  Ruby 1.8.7        Ruby 1.9.2      JRuby 1.6

ruby-oci8 2.0.4   ruby-oci8 2.0.4   ojdbc6.jar
Reporting issues
Where?

 http://github.com/rsim/oracle-enhanced/issues


http://groups.google.com/group/oracle-enhanced
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
  end
end

class TestCategory < ActiveRecord::Base
end

category = TestCategory.new(:name=>"hl", :category_code=>"hd")
category.id = 1
category.save!

p category
Ideally
Github pull request
Other libraries
ruby-plsql gem
plsql.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
ruby-plsql-spec
                ideal language
                for writing tests

             powerful testing tools
 RSpec       with “readable” syntax

               library for calling
ruby-plsql    PL/SQL procedures
                   from Ruby
http://github.com/rsim/mondrian-olap
More information
         http://blog.rayapps.com


 http://github.com/rsim/oracle-enhanced


http://groups.google.com/group/oracle-enhanced

More Related Content

PDF
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
PDF
Why Every Tester Should Learn Ruby
PDF
Testing Backbone applications with Jasmine
PDF
Using Ruby on Rails with legacy Oracle databases
KEY
Why ruby
KEY
Ruby/Rails
KEY
Backbone js
PDF
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Why Every Tester Should Learn Ruby
Testing Backbone applications with Jasmine
Using Ruby on Rails with legacy Oracle databases
Why ruby
Ruby/Rails
Backbone js
FalsyValues. Dmitry Soshnikov - ECMAScript 6

What's hot (20)

PDF
Scala ActiveRecord
PDF
Rust ⇋ JavaScript
PDF
Scala active record
PDF
Node Boot Camp
KEY
Say Hello To Ecmascript 5
PDF
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
PPTX
AST - the only true tool for building JavaScript
PPTX
5 Tips for Better JavaScript
PPTX
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
PDF
RubyEnRails2007 - Dr Nic Williams - Keynote
PDF
Your code is not a string
PDF
Annotation processing and code gen
PPTX
Mastering Java Bytecode With ASM - 33rd degree, 2012
PDF
JavaScript and the AST
PDF
Http4s, Doobie and Circe: The Functional Web Stack
PDF
Ten useful JavaScript tips & best practices
PDF
G*ワークショップ in 仙台 Grails(とことん)入門
PDF
Xlab #1: Advantages of functional programming in Java 8
PDF
Workshop 5: JavaScript testing
PDF
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Scala ActiveRecord
Rust ⇋ JavaScript
Scala active record
Node Boot Camp
Say Hello To Ecmascript 5
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
AST - the only true tool for building JavaScript
5 Tips for Better JavaScript
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
RubyEnRails2007 - Dr Nic Williams - Keynote
Your code is not a string
Annotation processing and code gen
Mastering Java Bytecode With ASM - 33rd degree, 2012
JavaScript and the AST
Http4s, Doobie and Circe: The Functional Web Stack
Ten useful JavaScript tips & best practices
G*ワークショップ in 仙台 Grails(とことん)入門
Xlab #1: Advantages of functional programming in Java 8
Workshop 5: JavaScript testing
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Ad

Similar to Rails on Oracle 2011 (20)

PDF
Oracle adapters for Ruby ORMs
PDF
Fast Web Applications Development with Ruby on Rails on Oracle
PDF
Extending Oracle E-Business Suite with Ruby on Rails
PDF
Ruby on Rails Oracle adaptera izstrāde
KEY
Rails and Legacy Databases - RailsConf 2009
PDF
PyCon 2010 SQLAlchemy tutorial
PDF
DataMapper
PDF
Old Oracle Versions
PDF
Porting Oracle Applications to PostgreSQL
PDF
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DB
PPTX
Oracle to Postgres Schema Migration Hustle
 
PDF
Advanced O/R Mapping with Glorp
PDF
Advanced database lab oracle structure query language
PDF
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
PDF
Whats new in_postgres_enterprise_db_20130124
 
PDF
PerlApp2Postgresql (2)
PDF
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
DOC
DBMS Practical File
PDF
Rails in the enterprise
PDF
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
Oracle adapters for Ruby ORMs
Fast Web Applications Development with Ruby on Rails on Oracle
Extending Oracle E-Business Suite with Ruby on Rails
Ruby on Rails Oracle adaptera izstrāde
Rails and Legacy Databases - RailsConf 2009
PyCon 2010 SQLAlchemy tutorial
DataMapper
Old Oracle Versions
Porting Oracle Applications to PostgreSQL
Web aplikāciju izstrāde ar Ruby on Rails un Oracle DB
Oracle to Postgres Schema Migration Hustle
 
Advanced O/R Mapping with Glorp
Advanced database lab oracle structure query language
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Whats new in_postgres_enterprise_db_20130124
 
PerlApp2Postgresql (2)
Database & Technology 1 _ Tom Kyte _ Efficient PL SQL - Why and How to Use.pdf
DBMS Practical File
Rails in the enterprise
RubyEnRails2007 - Dr Nic Williams - DIY Syntax
Ad

More from Raimonds Simanovskis (20)

PDF
Profiling Mondrian MDX Requests in a Production Environment
PDF
Improve Mondrian MDX usability with user defined functions
PDF
Analyze and Visualize Git Log for Fun and Profit - DevTernity 2015
PDF
Data Warehouses and Multi-Dimensional Data Analysis
PDF
mondrian-olap JRuby library
PDF
eazyBI Overview - Embedding Mondrian in other applications
PDF
Atvērto datu izmantošanas pieredze Latvijā
PDF
JavaScript Unit Testing with Jasmine
PDF
JRuby - Programmer's Best Friend on JVM
PDF
Agile Operations or How to sleep better at night
PDF
TDD - Why and How?
PDF
Analyze and Visualize Git Log for Fun and Profit
PDF
PL/SQL Unit Testing Can Be Fun
PDF
opendata.lv Case Study - Promote Open Data with Analytics and Visualizations
PDF
RailsWayCon: Multidimensional Data Analysis with JRuby
PDF
Multidimensional Data Analysis with JRuby
PDF
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
PDF
How to Adopt Agile at Your Organization
PDF
Multidimensional Data Analysis with Ruby (sample)
PDF
PL/SQL Unit Testing Can Be Fun!
Profiling Mondrian MDX Requests in a Production Environment
Improve Mondrian MDX usability with user defined functions
Analyze and Visualize Git Log for Fun and Profit - DevTernity 2015
Data Warehouses and Multi-Dimensional Data Analysis
mondrian-olap JRuby library
eazyBI Overview - Embedding Mondrian in other applications
Atvērto datu izmantošanas pieredze Latvijā
JavaScript Unit Testing with Jasmine
JRuby - Programmer's Best Friend on JVM
Agile Operations or How to sleep better at night
TDD - Why and How?
Analyze and Visualize Git Log for Fun and Profit
PL/SQL Unit Testing Can Be Fun
opendata.lv Case Study - Promote Open Data with Analytics and Visualizations
RailsWayCon: Multidimensional Data Analysis with JRuby
Multidimensional Data Analysis with JRuby
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
How to Adopt Agile at Your Organization
Multidimensional Data Analysis with Ruby (sample)
PL/SQL Unit Testing Can Be Fun!

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation theory and applications.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation theory and applications.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm

Rails on Oracle 2011

  • 2. Raimonds Simanovskis github.com/rsim @rsim
  • 3. Self-promotion :) eazybi.com
  • 4. How to contribute to ActiveRecord Oracle enhanced adapter
  • 5. Main components Rails 3.x build query ActiveRecord Arel SQL Arel::Visitors::Oracle execute results OracleEnhancedAdapter ActiveRecord:: ConnectionAdapters:: AbstractAdapter
  • 6. What Oracle Enhanced adapter does database metadata custom CUD connection queries procedures schema custom value quoting definition stmts schema stmts column type context index schema dump mapping creation results type structure AR patches mapping dump
  • 7. Oracle Data Types Ruby Rails Oracle Fixnum :integer NUMBER Float :float NUMBER BigDecimal :decimal NUMBER, DECIMAL Time :datetime DATE Time :time DATE Date :date DATE String :string VARCHAR2 String :text CLOB String :binary BLOB True/FalseClass :boolean NUMBER(1), CHAR(1)
  • 8. Latest addition Ruby Rails Oracle String :raw RAW
  • 9. 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, :attribute2 end
  • 10. class Employee < ActiveRecord::Base set_create_method do plsql.employees_pkg.create_employee( :p_first_name => first_name, ActiveRecord :p_last_name => last_name, :p_employee_id => nil )[:p_employee_id] with end set_update_method do PL/SQL plsql.employees_pkg.update_employee( :p_employee_id => id, :p_first_name => first_name, CRUD ) :p_last_name => last_name procedures end set_delete_method do plsql.employees_pkg.delete_employee( :p_employee_id => id ) end end
  • 11. Full-text indexes add_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}")
  • 12. 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”
  • 13. Currently testing on ActiveRecord versions 2.3.x 3.0.x 3.1.beta
  • 14. Currently testing on Oracle versions 10.2.0.4 11gR2 should be OK :)
  • 15. Currently testing on Ruby platforms oracle_enhanced adapter Ruby 1.8.7 Ruby 1.9.2 JRuby 1.6 ruby-oci8 2.0.4 ruby-oci8 2.0.4 ojdbc6.jar
  • 18. 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 end end class TestCategory < ActiveRecord::Base end category = TestCategory.new(:name=>"hl", :category_code=>"hd") category.id = 1 category.save! p category
  • 21. ruby-plsql gem plsql.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
  • 22. ruby-plsql-spec ideal language for writing tests powerful testing tools RSpec with “readable” syntax library for calling ruby-plsql PL/SQL procedures from Ruby
  • 24. More information http://blog.rayapps.com http://github.com/rsim/oracle-enhanced http://groups.google.com/group/oracle-enhanced