Crystal driver for Oracle Databse
This is essentially a wrapper around ODPI similar to cx_Oracle for Python, the oracle crate for Rust, and godror for Go.
-
Add the dependency to your
shard.yml
:dependencies: oracle: github: sourgrasses/crystal-oracle
-
Run
shards install
require "db"
require "oracle"
DB.open "oracle://user:password@host:port/SID" do |db|
db.exec "drop table if exists goodfriends"
db.exec "create table goodfriends (name varchar(30), age int)"
db.exec "insert into goodfriends values (:1, :2)", "Ben Buddy", 28
arg1 = "Sarah Bear"
arg2 = 33
db.exec "insert into contacts values (:1, :2)", arg1, arg2
puts "max age:"
puts db.scalar "select max(age) from contacts" # => 33
puts "contacts:"
db.query "select name, age from contacts order by age desc" do |res|
puts "#{res.column_name(0)} (#{res.column_name(1)})"
# => name (age)
res.each do
puts "#{res.read} (#{res.read})"
# => Sarah Bear (33)
# => Ben Buddy (28)
end
end
end
TODO: Write development instructions here
- Fork it (https://github.com/sourgrasses/crystal-oracle/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Jenn Wheeler - creator and maintainer