Sha256: b170d8710b4c569a2b61368df61a9acdbf7151f14281121e52e9d820bf3776e7
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
SAXMapper is a database persistence extension to SAXMachine. It uses DataObjects/MySQL going in, and DataMapper coming back out. SAXual Replication supports getting multiple instances of an object without an explicit wrapper class, just by specifying the wrapper tag, using parse_multiple. You can also set a column as a remote primary key, and it will overwrite rather than add records where that key is a duplicate (you need to separately set the column to be have a unique index, since it uses ON DUPLICATE KEY UPDATE) You can specify a batch size to save in, and whether to wrap the save in a transaction. Finally, you can mark fields as required, and it will raise an expection if the XML is missing that field. Many thanks to Paul Dix, who helped me integrate this with SAXMachine, and Dan Kubb, who helped me with DataObjects and gave hints on memory footprint. All bugs and memory leaks are mine, though! Example: require 'sax-mapper' class Person include SaxMapper element :sourced_id, :required => true element :given, :as => :given_name, :required => true element :family, :as => :family_name, :required => true element :email, :required => true table "people" tag :person key_column :sourced_id end Person.parse_multiple(xml) will return an array of Person objects, found inside <person></person> tags. You can save them to the DB with Person.save(array) Person.save(array, :batch_size => 3000, :transaction => true) will try to save them in batches of 3000, and roll everything back if any save fails. Multiple values with the same sourced_id will replace each other in the DB. gem install MikeSofaer-sax-mapper Enjoy! SAXMapper is written by Michael Sofaer, July 2009, and MIT licenced.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
MikeSofaer-sax-mapper-0.0.2 | README |