This document summarizes Rails on Oracle and the Oracle enhanced ActiveRecord adapter. It discusses the main components, how the adapter maps data types between Ruby/Rails and Oracle, and how it handles legacy schemas, PL/SQL CRUD procedures, and full-text indexes. It also provides information on testing, contributing, reporting issues and related libraries.
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)
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}")
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