Open Source RDBMS - Seamless, Scalable, Stable and Free

English | Login |Register

Sequel CUBRID Tutorial


1. In order to install Sequel, you can run the following command:

gem install sequel

2. CUBRID can be installed using the cubrid gem:

gem install cubrid

For more information on installation visit the Ruby Driver Installation page.

3. To connect to a cubrid database, you can use one of the ruby lines below:

# if CUBRID is on localhost with default port
 DB = Sequel.cubrid('database_name')
 
 # A different host/port with username/password
 DB = Sequel.connect('cubrid://user:pass@host:port/database_name')

For some quick Sequel examples, check out the README.rdoc file.

Here is a complete example:

require 'rubygems'
require 'sequel'
require 'cubrid'

DB = Sequel.cubrid('demodb')

DB.create_table :items do
  primary_key :id
  String :name
  Float :price
end

items = DB:items # Create a dataset

# Populate the table
items.insert(:name => 'abc', :price => rand * 100)
items.insert(:name => 'def', :price => rand * 100)
items.insert(:name => 'ghi', :price => rand * 100)

# Print out the number of records
puts "Item count: #{items.count}"

# Print out the average price
puts "The average price is: #{items.avg(:price)}"

Sequel also supports connecting to CUBRID via JDBC if you are using JRuby. The only difference is you need to require the cubrid jar file separately, and you must change the connect line to:

require 'cubrid.jar'
DB = Sequel.connect('jdbc:cubrid:127.0.0.1:33000:sequel_test:::')

comments powered by Disqus
문서 정보
viewed 634 times
번역 en
작성자
posted 작년
CUBRID
공헌자
마지막 수정시간 작년
변경 내역 보기
Share this article