Fernando Blat             @ferblapeTuesday, April 12, 2011
Un poco sobre mí       •       De Valencia            • unvlog.com       • 4 años en The Cocktail y     • iwannagothere.co...
Sequel!Tuesday, April 12, 2011
DatasetTuesday, April 12, 2011
Representación de un                 conjunto de filas de una                      o varias tablasTuesday, April 12, 2011
users                              updates              -           id            -   id              -           username...
DB = Sequel.connect(sqlite://      ddbb.sqlite3)      DB.class      => Sequel::Postgres::DatabaseTuesday, 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 = ferb...
users.filter("email = ?", ferblape@gmail.com).sql  => "SELECT * FROM `users` WHERE (email =  ferblape@gmail.com)Tuesday, A...
Un Dataset es una                           representaciónTuesday, April 12, 2011
#first, #last,                             #count,                            #all, ...Tuesday, April 12, 2011
Algunas consultas con                                 SequelTuesday, 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...
users.filter({:email => [ferblape@gmail.com,ferblape@vizzuality.co m]} & ~{:username => blat}).sql => "SELECT * FROM `user...
users.filter{created_at > Date.today}.or   {created_at < Date.today - 60}.order   (:id).limit(10).sql   => "SELECT * FROM ...
InsercionesTuesday, April 12, 2011
users.insert(:username => blat, :email =>    ferblape@gmail.com)    => 1    users.insert(:username => blatvizz, :email    ...
ActualizacionesTuesday, April 12, 2011
users.update(:id => :id + 1000)        => 2        users.all        =>        [{:id=>1001, :username=>"blat",        :emai...
Resultados de las                             consultasTuesday, April 12, 2011
users.all       =>       [{:id=>1, :username=>"blat",       :email=>"ferblape@gmail.com",       :created_at=>nil},       {...
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éricosTuesday, April 12, 2011
users.group_and_count(:id).sql                 => "SELECT `id`, count(*) AS count                 FROM `users` GROUP BY `i...
updates.join(users.filter{created_at <   Date.today}, :id => :user_id).sql   => "SELECT * FROM `updates` INNER JOIN   (SEL...
users.select(:username___wadus).sql                 => "SELECT `username` AS wadus FROM                 `users`"Tuesday, A...
ModelosTuesday, April 12, 2011
Tuesday, April 12, 2011
class Table < Sequel::Model(:user_tables)                 # Ignore mass-asigment on not allowed columns                 se...
MásTuesday, April 12, 2011
• migraciones estilo             • zonas horarias               ActiveRecord                                        • rela...
Tuesday, April 12, 2011
¿Vale la pena utilizarlo                                 con Rails?Tuesday, April 12, 2011
Acoplamiento                     • tareas Rake                     • migraciones                     • generadores        ...
sequel-railsTuesday, April 12, 2011
Gracias!Tuesday, April 12, 2011
Upcoming SlideShare
Loading in …5
×

Sequel @ madrid-rb

1,168 views
1,093 views

Published on

My talk about Sequel @ Madrid Ruby user group

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,168
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sequel @ madrid-rb

  1. 1. Fernando Blat @ferblapeTuesday, April 12, 2011
  2. 2. 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 VizzualityTuesday, April 12, 2011
  3. 3. Sequel!Tuesday, April 12, 2011
  4. 4. DatasetTuesday, April 12, 2011
  5. 5. Representación de un conjunto de filas de una o varias tablasTuesday, April 12, 2011
  6. 6. users updates - id - id - username - user_id - email - message - created_at - created_atTuesday, April 12, 2011
  7. 7. DB = Sequel.connect(sqlite:// ddbb.sqlite3) DB.class => Sequel::Postgres::DatabaseTuesday, April 12, 2011
  8. 8. users = DB[:users] => #<Sequel::SQLite::Dataset: "SELECT * FROM `users`">Tuesday, April 12, 2011
  9. 9. users.filter("email = ?", ferblape@gmail.com) => #<Sequel::SQLite::Dataset: "SELECT * FROM `users` WHERE (email = ferblape@gmail.com)">Tuesday, April 12, 2011
  10. 10. users.filter("email = ?", ferblape@gmail.com).sql => "SELECT * FROM `users` WHERE (email = ferblape@gmail.com)Tuesday, April 12, 2011
  11. 11. Un Dataset es una representaciónTuesday, April 12, 2011
  12. 12. #first, #last, #count, #all, ...Tuesday, April 12, 2011
  13. 13. Algunas consultas con SequelTuesday, April 12, 2011
  14. 14. users[1] users[:username => blat]Tuesday, April 12, 2011
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. InsercionesTuesday, April 12, 2011
  19. 19. users.insert(:username => blat, :email => ferblape@gmail.com) => 1 users.insert(:username => blatvizz, :email => ferblape@vizzuality.com) => 2Tuesday, April 12, 2011
  20. 20. ActualizacionesTuesday, April 12, 2011
  21. 21. 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
  22. 22. Resultados de las consultasTuesday, April 12, 2011
  23. 23. 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
  24. 24. users.to_hash(:id,:username) => {1=>"blat", 2=>"blatvizz"}Tuesday, April 12, 2011
  25. 25. users.select_map(:username) => ["blat", "blatvizz"]Tuesday, April 12, 2011
  26. 26. Algunos ejemplos más esotéricosTuesday, April 12, 2011
  27. 27. users.group_and_count(:id).sql => "SELECT `id`, count(*) AS count FROM `users` GROUP BY `id`"Tuesday, April 12, 2011
  28. 28. 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
  29. 29. users.select(:username___wadus).sql => "SELECT `username` AS wadus FROM `users`"Tuesday, April 12, 2011
  30. 30. ModelosTuesday, April 12, 2011
  31. 31. Tuesday, April 12, 2011
  32. 32. 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 ... endTuesday, April 12, 2011
  33. 33. MásTuesday, April 12, 2011
  34. 34. • 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 pluginsTuesday, April 12, 2011
  35. 35. Tuesday, April 12, 2011
  36. 36. ¿Vale la pena utilizarlo con Rails?Tuesday, April 12, 2011
  37. 37. Acoplamiento • tareas Rake • migraciones • generadores • config/database.ymlTuesday, April 12, 2011
  38. 38. sequel-railsTuesday, April 12, 2011
  39. 39. Gracias!Tuesday, April 12, 2011

×