SlideShare a Scribd company logo
Sequel
pure Ruby DB Toolkit
http://sequel.rubyforge.org/
Ruby Toolbox

• Database Abstraction - Adapters
• DSL - Ruby
• ORM - Models
Adapters

• SQLite
• MySQL (2)
• PostgreSQL
• DBI
gem install sequel
     gem install sqlite3
     gem install mysql2
Connect to DB


• DB = Sequel.sqlite   (in-memory)
Connect to DB


• DB = Sequel.sqlite (in-memory)
• DB = Sequel.connect (‘sqlite://test.db’)
Connect to DB

• DB = Sequel.sqlite (in-memory)
• DB = Sequel.connect (‘sqlite://test.db’)
• DB = Sequel.connect (‘mysql://...’)
• DB = Sequel.connect (‘postgres://...’)
Ruby Toolbox


sequel -E sqlite://test.db
Database Object
DB - Database Object

• DB.tables
• DB.table_exists?(:items)
• DB.schema(:items)
• DB.add_index :items, :name
SQL QUIZ !


Rename table
SQL QUIZ !


DB.rename_table
 :items , :mono
SQL QUIZ !


ALTER TABLE `items`
RENAME TO `mono`
Sequel
DB.run(‘ALTER TABLE ’)




   DB.rename_table
Dataset Object
Unique for Sequel
Dataset object

SQL Query
      as
  Object
DB[:items]
Immutable

   Dataset
       Return


Dataset (copy)
Chainable

DB[:Items]




             SELECT * FROM `items`
Chainable

DB[:Items]    where(‘price > 10’)




             SELECT * FROM `items`
              WHERE (price > 100)
Chainable

DB[:Items]     where(‘price > 10’)   order(:name)   limit(10)




              SELECT * FROM `items`
               WHERE (price > 100)
             ORDER BY `name` LIMIT 10
Two type of returns
 Dataset   return   Dataset’


                    id   name
 Dataset   return
                    1     a
                    2     b


DB[:items].limit(10).all
require ‘sequel_core’
Model
require ‘sequel’
class Item < Sequel::Model
          Dataset
end
Associations
class Item < Sequel::Model
   many_to_one :users
end

class User < Sequel::Model
   one_to_many :items
end
Associations
   ActiveRecord            Sequel

     belongs_to         many_to_one

     has_many           one_to_many

has_and_belongs_to...   many_to_many

      has_one            one_to_one
Other features

• Model validations - validate_*
• Model hooks - before, after
• Migrations
• Transactions
Questions?

More Related Content

PDF
Hive jdbc
Bennie Schut
 
PPTX
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
PPTX
Getting Started with Datatsax .Net Driver
DataStax Academy
 
PPTX
Learn PHP Lacture2
ADARSH BHATT
 
PDF
NoSQL Infrastructure - Late 2013
Server Density
 
PDF
Adventures in Multithreaded Core Data
Inferis
 
PDF
Core Data with multiple managed object contexts
Matthew Morey
 
PPTX
Discover the Power of the NoSQL + SQL with MySQL
Dave Stokes
 
Hive jdbc
Bennie Schut
 
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Getting Started with Datatsax .Net Driver
DataStax Academy
 
Learn PHP Lacture2
ADARSH BHATT
 
NoSQL Infrastructure - Late 2013
Server Density
 
Adventures in Multithreaded Core Data
Inferis
 
Core Data with multiple managed object contexts
Matthew Morey
 
Discover the Power of the NoSQL + SQL with MySQL
Dave Stokes
 

What's hot (20)

PDF
High Performance Core Data
Matthew Morey
 
PPTX
harry presentation
thembhani mapengo
 
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
PDF
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
PPTX
MongoDB-SESSION03
Jainul Musani
 
PDF
jQuery in 15 minutes
Simon Willison
 
PPTX
MongoDB: tips, trick and hacks
Scott Hernandez
 
PDF
History of jQuery
jeresig
 
PDF
Hujs 总结
yiming he
 
PDF
【Unity】Scriptable object 入門と活用例
Unity Technologies Japan K.K.
 
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
PPTX
MongoDB Shell Tips & Tricks
MongoDB
 
KEY
C# Development (Sam Corder)
MongoSF
 
PPTX
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
PDF
Bonjour, iCloud
Chris Adamson
 
PDF
Latinoware
kchodorow
 
PDF
Better Selenium Tests with Geb - Selenium Conf 2014
Naresha K
 
PDF
Getting Started with MongoDB
Michael Redlich
 
PDF
HTML::Mason by example
Chris Vertonghen
 
High Performance Core Data
Matthew Morey
 
harry presentation
thembhani mapengo
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
NoSQL and JavaScript: a Love Story
Alexandre Morgaut
 
MongoDB-SESSION03
Jainul Musani
 
jQuery in 15 minutes
Simon Willison
 
MongoDB: tips, trick and hacks
Scott Hernandez
 
History of jQuery
jeresig
 
Hujs 总结
yiming he
 
【Unity】Scriptable object 入門と活用例
Unity Technologies Japan K.K.
 
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
MongoDB Shell Tips & Tricks
MongoDB
 
C# Development (Sam Corder)
MongoSF
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Bonjour, iCloud
Chris Adamson
 
Latinoware
kchodorow
 
Better Selenium Tests with Geb - Selenium Conf 2014
Naresha K
 
Getting Started with MongoDB
Michael Redlich
 
HTML::Mason by example
Chris Vertonghen
 
Ad

Similar to Sequel (20)

PDF
Sequel
LittleBIGRuby
 
PDF
ActiveRecord Query Interface (2), Season 2
RORLAB
 
PDF
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
PDF
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
KEY
Active Record Query Interface (1), Season 2
RORLAB
 
PDF
Ruby meetup ROM
Nikita Shilnikov
 
PDF
DataMapper @ RubyEnRails2009
Dirkjan Bussink
 
PDF
ActiveRecord Query Interface (1), Season 1
RORLAB
 
KEY
Active Record Query Interface (2), Season 1
RORLAB
 
PDF
rails-migrations_1
brecke
 
PDF
Squeak at NetStyle
ESUG
 
PDF
«Работа с базами данных с использованием Sequel»
Olga Lavrentieva
 
PDF
Oracle adapters for Ruby ORMs
Raimonds Simanovskis
 
ZIP
Ruby on Rails: Tasty Burgers
Aaron Patterson
 
PDF
Where's My SQL? Designing Databases with ActiveRecord Migrations
Eleanor McHugh
 
PDF
DataMapper
Yehuda Katz
 
PDF
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
PDF
Database Tools by Skype
elliando dias
 
KEY
Datamapper @ Railsconf2010
Dirkjan Bussink
 
KEY
Rails Model Basics
James Gray
 
ActiveRecord Query Interface (2), Season 2
RORLAB
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Active Record Query Interface (1), Season 2
RORLAB
 
Ruby meetup ROM
Nikita Shilnikov
 
DataMapper @ RubyEnRails2009
Dirkjan Bussink
 
ActiveRecord Query Interface (1), Season 1
RORLAB
 
Active Record Query Interface (2), Season 1
RORLAB
 
rails-migrations_1
brecke
 
Squeak at NetStyle
ESUG
 
«Работа с базами данных с использованием Sequel»
Olga Lavrentieva
 
Oracle adapters for Ruby ORMs
Raimonds Simanovskis
 
Ruby on Rails: Tasty Burgers
Aaron Patterson
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Eleanor McHugh
 
DataMapper
Yehuda Katz
 
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
Database Tools by Skype
elliando dias
 
Datamapper @ Railsconf2010
Dirkjan Bussink
 
Rails Model Basics
James Gray
 
Ad

More from Stoyan Zhekov (18)

PDF
Multirotors
Stoyan Zhekov
 
KEY
ZeroMQ
Stoyan Zhekov
 
PDF
Padrino - the Godfather of Sinatra
Stoyan Zhekov
 
KEY
Deployment on Heroku
Stoyan Zhekov
 
KEY
Push the web with HTML5
Stoyan Zhekov
 
KEY
Foreman - Process manager for applications with multiple components
Stoyan Zhekov
 
KEY
Social Network for spare parts
Stoyan Zhekov
 
KEY
Using XMPP Presence stanzas for real-time parking information
Stoyan Zhekov
 
PDF
Ruby cooking
Stoyan Zhekov
 
KEY
Websockets with ruby
Stoyan Zhekov
 
KEY
EventMachine
Stoyan Zhekov
 
PDF
Webhooks - glue for the web (japanese)
Stoyan Zhekov
 
PDF
Webhooks - glue for the web
Stoyan Zhekov
 
PDF
Microblogging via XMPP (japanese)
Stoyan Zhekov
 
PDF
Microblogging via XMPP
Stoyan Zhekov
 
PDF
Ruby off Rails (english)
Stoyan Zhekov
 
PDF
Ruby off Rails (japanese)
Stoyan Zhekov
 
PDF
Rails Deployment with NginX
Stoyan Zhekov
 
Multirotors
Stoyan Zhekov
 
Padrino - the Godfather of Sinatra
Stoyan Zhekov
 
Deployment on Heroku
Stoyan Zhekov
 
Push the web with HTML5
Stoyan Zhekov
 
Foreman - Process manager for applications with multiple components
Stoyan Zhekov
 
Social Network for spare parts
Stoyan Zhekov
 
Using XMPP Presence stanzas for real-time parking information
Stoyan Zhekov
 
Ruby cooking
Stoyan Zhekov
 
Websockets with ruby
Stoyan Zhekov
 
EventMachine
Stoyan Zhekov
 
Webhooks - glue for the web (japanese)
Stoyan Zhekov
 
Webhooks - glue for the web
Stoyan Zhekov
 
Microblogging via XMPP (japanese)
Stoyan Zhekov
 
Microblogging via XMPP
Stoyan Zhekov
 
Ruby off Rails (english)
Stoyan Zhekov
 
Ruby off Rails (japanese)
Stoyan Zhekov
 
Rails Deployment with NginX
Stoyan Zhekov
 

Recently uploaded (20)

PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Doc9.....................................
SofiaCollazos
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
The Future of Artificial Intelligence (AI)
Mukul
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 

Sequel

Editor's Notes