Presentation introducing DataMapper given at the RubyArgentina Meetup, 13 May 2011. (Based on a presentation by Dirkjan Bussink given at RubyEnRails Amsterdam 2009).
Person.get(1) => #<Person @id=1 @name="Piotr" @age=20> end repository(:repo2) do p Person.get(1) => #<Person @id=1 @name="José" @age=12> end Sonntag, 1. April 12
< AbstractAdapter def create(resources) end def read(query) end def update(attributes, collection) end def delete(collection) end end end end Sonntag, 1. April 12
SELECT "people"."id", "people"."name", "people"."age" FROM "people" INNER JOIN "addresses" ON "people"."id" = "addresses"."person_id" WHERE "addresses"."street" LIKE '%street%' GROUP BY "people"."id", "people"."name", "people"."age" ORDER BY "people"."id" Sonntag, 1. April 12
property :age, Integer has n, :addresses def self.named_like_me all(:name.like => "%me%") end def self.older_than_me all(:age.gt => 27) end end Person.named_like_me.older_than_me ~ SELECT "id", "name", "age" FROM "people" WHERE ("name" LIKE '%me%' AND "age" > 27) ORDER BY "id" Encadenamiento de términos de búsqueda Sonntag, 1. April 12
property :age, Integer has n, :addresses def self.named_like_me all(:name.like => "%me%") end def self.older_than_me all(:age.gt => 27) end end Person.named_like_me.older_than_me ~ SELECT "id", "name", "age" FROM "people" WHERE ("name" LIKE '%me%' AND "age" > 27) ORDER BY "id" Encadenamiento de términos de búsqueda Alcances nominales en simple Ruby Sonntag, 1. April 12
"street", "person_id" FROM "addresses" WHERE ( "person_id" IN (SELECT "id" FROM "people" WHERE "name" LIKE '%me%') AND "street" IS NOT NULL ) ORDER BY "id" Sonntag, 1. April 12
:nullable => false end CREATE TABLE "people" ("id" SERIAL NOT NULL, "name" VARCHAR(50) NOT NULL, "age" INTEGER, PRIMARY KEY("id")) Sonntag, 1. April 12
=> :destroy! end ALTER TABLE addresses ADD CONSTRAINT addresses_person_id_fk FOREIGN KEY (person_id) REFERENCES people ON DELETE CASCADE ON UPDATE CASCADE Sonntag, 1. April 12
< DataMapper::Type primitive String length 16 def self.load(value, property) IPAddr.new(value) end def self.dump(value, property) value.to_s end def self.typecast(value, property) value.kind_of?(IPAddr) ? value : load(value, property) end end end end class NetworkNode ... property :ipaddress, IPAddress end Tipos personalizables Sonntag, 1. April 12
bugs • Arreglar problemas con uniones (joins) complejas • Soporte para validaciones i18n • Encontrar un método conveniente para detectar (typecasting) valores en blanco para nils en dm- rails • Finalizar el soporte para propiedades binarias (que deberían mapear a BLOB, BYTEA, etc.) Sonntag, 1. April 12