SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Fernando Blat
             @ferblape
Tuesday, April 12, 2011
Un poco sobre mí

       •       De Valencia            • unvlog.com
       • 4 años en The Cocktail y     • iwannagothere.com //
               La Coctelera             mimaleta.com

       •       He sido freelance un   • lacoctelera.com //
               tiempo                   partigi.com

       • Ahora trabajo en             • actuable.es
               Vizzuality

Tuesday, April 12, 2011
Sequel!



Tuesday, April 12, 2011
Dataset



Tuesday, April 12, 2011
Representación de un
                 conjunto de filas de una
                      o varias tablas


Tuesday, April 12, 2011
users                              updates
              -           id            -   id
              -           username      -   user_id
              -           email         -   message
              -           created_at    -   created_at




Tuesday, April 12, 2011
DB = Sequel.connect('sqlite://
      ddbb.sqlite3')

      DB.class
      => Sequel::Postgres::Database




Tuesday, April 12, 2011
users = DB[:users]
         => #<Sequel::SQLite::Dataset:
         "SELECT * FROM `users`">




Tuesday, April 12, 2011
users.filter("email = ?", 'ferblape@gmail.com')

   => #<Sequel::SQLite::Dataset: "SELECT * FROM
   `users` WHERE (email = 'ferblape@gmail.com')">




Tuesday, April 12, 2011
users.filter("email = ?", 'ferblape@gmail.com').sql

  => "SELECT * FROM `users` WHERE (email =
  'ferblape@gmail.com')




Tuesday, April 12, 2011
Un Dataset es una
                           representación


Tuesday, April 12, 2011
#first, #last,
                             #count,
                            #all, ...


Tuesday, April 12, 2011
Algunas consultas con
                                 Sequel


Tuesday, April 12, 2011
users[1]

                 users[:username => 'blat']




Tuesday, April 12, 2011
users.filter({:email =>
  ['ferblape@gmail.com','ferblape@vizzuality.co
  m']}).sql

  => "SELECT * FROM `users` WHERE (`email` IN
  ('ferblape@gmail.com',
  'ferblape@vizzuality.com'))"




Tuesday, April 12, 2011
users.filter({:email =>
 ['ferblape@gmail.com','ferblape@vizzuality.co
 m']} & ~{:username => 'blat'}).sql

 => "SELECT * FROM `users` WHERE ((`email` IN
 ('ferblape@gmail.com',
 'ferblape@vizzuality.com')) AND (`username` !
 = 'blat'))"




Tuesday, April 12, 2011
users.filter{created_at > Date.today}.or
   {created_at < Date.today - 60}.order
   (:id).limit(10).sql

   => "SELECT * FROM `users` WHERE
   ((`created_at` > '2011-03-26') OR
   (`created_at` < '2011-01-25')) ORDER BY `id`
   LIMIT 10"




Tuesday, April 12, 2011
Inserciones



Tuesday, April 12, 2011
users.insert(:username => 'blat', :email =>
    'ferblape@gmail.com')
    => 1

    users.insert(:username => 'blatvizz', :email
    => 'ferblape@vizzuality.com')
    => 2




Tuesday, April 12, 2011
Actualizaciones



Tuesday, April 12, 2011
users.update(:id => :id + 1000)
        => 2

        users.all
        =>
        [{:id=>1001, :username=>"blat",
        :email=>"ferblape@gmail.com",
        :created_at=>2011-03-26 00:00:00 +0100},
        {:id=>1002, :username=>"blatvizz",
        :email=>"ferblape@vizzuality.com",
        :created_at=>2011-03-26 00:00:00 +0100}]



Tuesday, April 12, 2011
Resultados de las
                             consultas


Tuesday, April 12, 2011
users.all

       =>
       [{:id=>1, :username=>"blat",
       :email=>"ferblape@gmail.com",
       :created_at=>nil},
       {:id=>2, :username=>"blatvizz",
       :email=>"ferblape@vizzuality.com",
       :created_at=>nil}]




Tuesday, April 12, 2011
users.to_hash(:id,:username)

                 => {1=>"blat", 2=>"blatvizz"}




Tuesday, April 12, 2011
users.select_map(:username)

                 => ["blat", "blatvizz"]




Tuesday, April 12, 2011
Algunos ejemplos más
                           esotéricos


Tuesday, April 12, 2011
users.group_and_count(:id).sql

                 => "SELECT `id`, count(*) AS 'count'
                 FROM `users` GROUP BY `id`"




Tuesday, April 12, 2011
updates.join(users.filter{created_at <
   Date.today}, :id => :user_id).sql

   => "SELECT * FROM `updates` INNER JOIN
   (SELECT * FROM `users` WHERE (`created_at` <
   '2011-03-26')) AS 't1' ON (`t1`.`id` =
   `updates`.`user_id`)"




Tuesday, April 12, 2011
users.select(:username___wadus).sql

                 => "SELECT `username` AS 'wadus' FROM
                 `users`"




Tuesday, April 12, 2011
Modelos



Tuesday, April 12, 2011
Tuesday, April 12, 2011
class Table < Sequel::Model(:user_tables)

                 # Ignore mass-asigment on not allowed columns
                 self.strict_param_setting = false

                 # Allowed columns
                 set_allowed_columns(:name, :privacy, :tags)

                 def before_validation
                   self.privacy ||= :public
                   self.name = set_table_name if self.name.blank?
                   super
                 end

                 ...

            end




Tuesday, April 12, 2011
Más



Tuesday, April 12, 2011
• migraciones estilo             • zonas horarias
               ActiveRecord
                                        • relaciones
       • gestión de múltiples           • dirty attributes
               bbdd: maestro-esclavo,
               maestro-maestro          • serialización JSON
       • sharding de tablas             • compatibilidad con
                                          ActiveModel
       • transacciones
       • paginación                     • extensiones y plugins

Tuesday, April 12, 2011
Tuesday, April 12, 2011
¿Vale la pena utilizarlo
                                 con Rails?


Tuesday, April 12, 2011
Acoplamiento

                     • tareas Rake
                     • migraciones
                     • generadores
                     • config/database.yml

Tuesday, April 12, 2011
sequel-rails



Tuesday, April 12, 2011
Gracias!




Tuesday, April 12, 2011

Contenu connexe

En vedette

Administración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startupAdministración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startup
Fernando Blat
 

En vedette (6)

Administración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startupAdministración ágil de sistemas en el entorno de una startup
Administración ágil de sistemas en el entorno de una startup
 
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
Bigdata for small pockets, by Javier Ramirez from teowaki. RubyC Kiev 2014
 
How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...
How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...
How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...
 
Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...Everything you always wanted to know about Distributed databases, at devoxx l...
Everything you always wanted to know about Distributed databases, at devoxx l...
 
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA LondonBuilding Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
Building Usable REST APIs. By Javier Ramirez, teowaki. FOWA London
 
Highly available distributed databases, how they work, javier ramirez at teowaki
Highly available distributed databases, how they work, javier ramirez at teowakiHighly available distributed databases, how they work, javier ramirez at teowaki
Highly available distributed databases, how they work, javier ramirez at teowaki
 

Similaire à Sequel @ madrid-rb

JS Tooling in Rails 3.1
JS Tooling in Rails 3.1JS Tooling in Rails 3.1
JS Tooling in Rails 3.1
Duda Dornelles
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
ehuard
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
jbellis
 
HootSuite Dev 2
HootSuite Dev 2HootSuite Dev 2
HootSuite Dev 2
ujihisa
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
pablodip
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
smueller_sandsmedia
 

Similaire à Sequel @ madrid-rb (14)

Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
Big and Fat: Using MongoDB with Deep and Diverse Data Sets (MongoATL version)
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
JS Tooling in Rails 3.1
JS Tooling in Rails 3.1JS Tooling in Rails 3.1
JS Tooling in Rails 3.1
 
Web Scraping using Diazo!
Web Scraping using Diazo!Web Scraping using Diazo!
Web Scraping using Diazo!
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
Cassandra 1.0 and the future of big data (Cassandra Tokyo 2011)
 
Changeyrmarkup
ChangeyrmarkupChangeyrmarkup
Changeyrmarkup
 
HootSuite Dev 2
HootSuite Dev 2HootSuite Dev 2
HootSuite Dev 2
 
Doctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 ParisDoctrator Symfony Live 2011 Paris
Doctrator Symfony Live 2011 Paris
 
Solving the "Brooklyn Problem"
Solving the "Brooklyn Problem" Solving the "Brooklyn Problem"
Solving the "Brooklyn Problem"
 
When?, Why? and What? of MongoDB
When?, Why? and What? of MongoDBWhen?, Why? and What? of MongoDB
When?, Why? and What? of MongoDB
 
Ruby on Rails 101
Ruby on Rails 101Ruby on Rails 101
Ruby on Rails 101
 
Online journalism: thinking about platforms
Online journalism: thinking about platformsOnline journalism: thinking about platforms
Online journalism: thinking about platforms
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Sequel @ madrid-rb