Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sequel @ madrid-rb

1,352 views

Published on

My talk about Sequel @ Madrid Ruby user group

Published in: Technology
  • Be the first to comment

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

×