Sequel: The Database Toolkit for Ruby
- Thread safety, connection pooling and a concise DSL for constructing SQL queries and table schemas.
- Comprehensive ORM layer for mapping records to Ruby objects and handling associated records.
- Advanced database features such as prepared statements, bound variables, stored procedures, savepoints, two-phase commit, transaction isolation, primary/replica configurations, and database sharding.
- With adapters for ADO, Amalgalite, IBM_DB, JDBC, MySQL, Mysql2, ODBC, Oracle, PostgreSQL, SQLAnywhere, SQLite3, TinyTDS, and Trilogy.
require "sequel"
DB = Sequel.sqlite
DB.create_table :items do
primary_key :id
String :name, unique: true, null: false
Float :price, null: false
end
items = DB[:items]
items.insert(name: 'abc', price: rand * 100)
items.insert(name: 'def', price: rand * 100)
items.insert(name: 'ghi', price: rand * 100)
puts "Item count: #{items.count}"
puts "The average price is: #{items.avg(:price)}"