From: Sharon Rosner Date: 2007-07-10T14:33:23+09:00 Subject: ANN: Sequel 0.1.8 Released Sequel version 0.1.8 has just been released. This release is focused on substantial refactoring of the Dataset class, mainly in order to simplify individual adapter implementations. Also included in this release are several bug fixes and some new features. Important: I did my best to ensure that all adapters will work correctly, but I can only test two on my setup: sqlite and postgres. So if you use other adapters please let me know if you run into trouble. Worst case just remove version 0.1.8 and install version 0.1.7. Following is a discussion of the main changes: Support for polymorphic models ============================== Datasets can now provide support for polymorphic models by instantiating model instances based on a value in a specific column. For example: addresses = DB[:addresses] addresses.set_model(:kind, 1 => User, 2 => Company) This is pretty much self-explanatory. The dataset will lookup the value of the :kind column for each row and instantiate the respective model class. You can also specify a default model class: address.set_model(:kind, 1 => User, 2 => Company, nil => Addressable) In order to specify a single model to use, just call the #set_model method with a single class: addresses = DB[:addresses] addresses.set_model(Address) Retrieving the columns in a dataset =================================== The Dataset class includes a new #columns method which lets you retrieve the column names in the result set in the correct order: DB[:items].columns #=> [:id, :name, :price] The Dataset#print method has also been updated to automatically use this method to determine the order of columns in the printed table. SQLite Pragmas ============== The SQLite adapter includes several methods to dynamically control database behavior. You can programatically set the auto_vacuum, synchronous and temp_store pragmas, e.g.: DB.auto_vacuum = :full # one of :none, :full, :incremental DB.synchronous = :off # one of :off, :normal, :full DB.temp_store = :memory # one of :default, :file, :memory You can also set and retrieve other pragma values: DB.pragma_get(:encoding) DB.pragma_set(:encoding, 'UTF-8') Postgresql EXPLAIN ANALYZE ========================== The postgres adapter now includes a Postgres::Dataset#analyze method to further analyze query performance. Here's some sample output: Session.producers.sql #=> "SELECT * FROM sessions WHERE NOT (mount_path IS NULL)" puts Session.producers.analyze # output Seq Scan on sessions (cost=0.00..617.76 rows=18483 width=152) (actual time=34.454..34.454 rows=0 loops=1) Filter: (NOT (mount_path IS NULL)) Total runtime: 34.551 ms Also, Postgres::Dataset#explain was broken and is now fixed. Simplified and standardized Dataset adapter interface ===================================================== Writing a Sequel adapter is now much easier. A Dataset implementation should only override 4 methods: fetch_rows, insert, update and delete. More specs ========== Sequel is now at 95% code coverage on the specs. There is also a new sqlite adapter spec. Adapter specs can be tested by running rake spec_all. Miscellaneous ============= * Fixed Postgres::Dataset#explain. * Renamed Dataset#hash_column to Dataset#to_hash. * Various code tweaks. ====================== Sequel documentation: Join the Sequel-talk group: Install the gem: sudo gem install sequel Or check out the source and install manually: svn co http://ruby-sequel.googlecode.com/svn/trunk sequel cd sequel rake install