Sequel @  madrid-rb
Upcoming SlideShare
Loading in...5
×
 

Sequel @ madrid-rb

on

  • 1,307 views

My talk about Sequel @ Madrid Ruby user group

My talk about Sequel @ Madrid Ruby user group

Statistics

Views

Total Views
1,307
Views on SlideShare
1,307
Embed Views
0

Actions

Likes
0
Downloads
7
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Sequel @  madrid-rb Sequel @ madrid-rb Presentation Transcript

  • Fernando Blat @ferblapeTuesday, 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 VizzualityTuesday, April 12, 2011
  • 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 - user_id - email - message - created_at - created_atTuesday, April 12, 2011
  • 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 = 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ó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 (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
  • InsercionesTuesday, April 12, 2011
  • users.insert(:username => blat, :email => ferblape@gmail.com) => 1 users.insert(:username => blatvizz, :email => ferblape@vizzuality.com) => 2Tuesday, April 12, 2011
  • ActualizacionesTuesday, 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 consultasTuesday, 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éricosTuesday, 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
  • ModelosTuesday, 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 ... endTuesday, April 12, 2011
  • MásTuesday, 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 pluginsTuesday, April 12, 2011
  • Tuesday, April 12, 2011
  • ¿Vale la pena utilizarlo con Rails?Tuesday, April 12, 2011
  • Acoplamiento • tareas Rake • migraciones • generadores • config/database.ymlTuesday, April 12, 2011
  • sequel-railsTuesday, April 12, 2011
  • Gracias!Tuesday, April 12, 2011