Commits on May 27, 2010
  1. Add an AssociationPks plugin that adds association_pks and associatio…

    …n_pks= methods for *_to_many associations
    These methods allow you to get the primary keys for all associated
    objects, and to modify which objects are associated by passing an
    array of keys to the setter.  The setter will add entries from the
    array that are not already associated, and remove already associated
    entries that are not in the array.
    This is a fairly low level plugin that operates at the dataset
    level and does not instantiate model objects.  This is faster but
    it means that callbacks will not be called.  Also, this only
    works with single primary keys, not composite primary keys.
    committed May 27, 2010
  2. Make Model#checked_transaction private method argument optional, and …

    …use it in the one_to_one setter method
    committed May 27, 2010
Commits on May 26, 2010
  1. Add a UpdatePrimaryKey plugin that allows you to update the primary k…

    …ey of a model object
    This plugin just caches a copy of the primary key values when the
    object is loaded from the database, and uses the cached copy
    until after the object is saved, so that if you modify the primary
    key value, it will use the previous value in the UPDATE WHERE
    clause, and the new value in the SET clause.
    This causes a substantial performance hit when loading model
    objects, though the model load time is is generally small compared
    to time spent in the lower levels of the stack.
    committed May 26, 2010
  2. Only remove primary key values when saving all columns if they have n…

    …ot been modified
    Before, Sequel unconditionally removed primary key columns when
    saving existing objects in all cases.  However, if you pass the
    primary key column directly to save, it makes sense for Sequel
    to include it in the update statement.  Likewise, it makes
    sense for Sequel to include it if you use save_changes and it
    has been changed.
    Sequel used to always use all columns in a regular save, but
    some databases such as MSSQL have problems with that, as they
    don't allow you to modify the value of an identity column,
    even to set it to the value it already has.  That's the reason
    Sequel started removing primary keys from update statements in
    the first place.  Now, Sequel only removes primary key columns
    from the update values if the columns haven't been modified,
    which should fix the issue.
    Note that this does not mean you can update primary key values
    and save objects and have things work correctly.  It's almost
    enough, but to do it properly requires saving existing values
    of the primary keys when loading the object, which slows the
    loading process down by a factor of 3:
    h = {:a=>1}
    puts Benchmark.measure{100000.times{b.load(h)}}
    =>  0.540000   0.030000   0.570000 (  0.574908)
    puts Benchmark.measure{100000.times{c.load(h)}}
    =>  1.650000   0.130000   1.780000 (  1.787350)
    That's definitely an unacceptable slow down, so that will have
    to go into a plugin.
    committed May 26, 2010
Commits on May 25, 2010
  1. Add eager loading via .eager support to the sharding plugin

    This means that when you do:
      Sequel::Model.plugin :sharding
      albums = Album.server(:s1).eager(:artist).all
    It will load the albums and artists from shard :s1 and  save the
    artist on shard :s1.
    committed May 25, 2010
  2. Allow the :eager_loader association proc to accept a single hash inst…

    …ead of 3 arguments
    The previously supported API of using 3 separate arguments is still
    supported.  However, the new API is more flexible, and is required
    to get access to the dataset that is doing the eager loading.  That
    will be used in the future to make sure the sharding plugin works
    for eager loading.
    With the new API, the hash passed to the eager_loader proc is
    populated with the keys :key_hash, :rows, :associations, and
    :self, with the first three keys corresponding to the old
    argument order, and the new :self key being the dataset doing
    the eager loading.
    The Model.eager_loading_dataset method now also accepts an
    options hash as an optional fifth argument, which should be
    backwards compatible.
    committed May 25, 2010
  3. Move to using explicit methods instead of aliases for methods that ca…

    …n be overridden in subclasses
    Aliasing a method in ruby does not create a method that calls
    another method, it creates a method with the same body as another
    method.  Sometimes that is what you want, but in Sequel we often
    want a method that calls the original method, so that if the
    original method is overridden in a subclass, calling the alias
    calls the overridden method instead of the default method.
    This changes Sequel to use explicit methods instead of aliases
    for methods that could be overridden in subclasses.
    committed May 25, 2010
  4. Add a Dataset#order_prepend method that adds to the end of an existin…

    …g order
    This is useful if the dataset is already ordered, and you want to
    modify the order, but still keep the original order as the fallback.
      # Dataset ordered by albums name
      ds = DB[:albums].join(:artists, :id=>:artist_id).
      # You want to order it by artists, but keep the existing
      # order by album for albums by the same artist
    committed May 25, 2010
  5. Add a Sequel::NotImplemented exception class, use instead of NotImple…

    This modifies some default methods that are overwritten in all
    adapters to use a Sequel::NotImplemented exception class.  It
    also adds the tables and indexes method that are implemented by
    many of the adapters to the main Database class, and has them
    raise Sequel::NotImplemented.
    This also modifies the indexes methods in some of the adapters
    to take an options hash, even though they don't use it, for
    consistency with the JDBC adapter and now the default method
    committed May 25, 2010
  6. Correctly handle more than 2 hierarchy levels in the single table inh…

    …eritance plugin
    Previously, Sequel did not handle more than 2 hierarchy levels in
    the single table inheritance plugin.  If you were using more than
    two levels, the documentation told you that you had to set up your
    own custom filter.
    With this change, you can now have as many class hierarchy levels
    as you want, and Sequel will handle things automatically.
    There shouldn't be any backwards compatibility problems, but this
    does switch subclasses to use IN instead of = in their filter. That
    may have performance implications, but any decent database is going
    to treat an IN with one element the same as an =, so there should
    not be any performance regression in the 2 level hierarchy case.
    committed May 25, 2010
  7. Allow using a custom column value<->class mapping to the single_table…

    …_inheritance plugin
    This allows you to configure the mapping used.  The default mapping
    remains the same, where the column value holds the name of the class
    as a string.  However, you can now provide a mapping that allows you
    to use integers, non-class name strings, or pretty much anything, to
    map the column values for strings.
    The most common customization is probably to use integers, which can
    be easily done with a hash:
      Employee.plugin :single_table_inheritance, :type,
        :model_map=>{1=>:Staff, 2=>:Manager}
    You can also use a pair of custom procs:
      Employee.plugin :single_table_inheritance, :type,
        :model_map=>proc{|v| v.reverse},
    Check the new module RDoc for details.
    committed May 25, 2010
  8. Remove cached schema entry when creating table

    This fixes some corner cases, such as using raw SQL to drop a table
    or dropping a table in another process.  However, it's safe as any
    time create_table succeeds, any previous cached schema entry is
    probably invalid.
    committed May 25, 2010
Commits on May 24, 2010
Commits on May 21, 2010
  1. Make sure certain alter table operations clear the schema correctly o…

    …n MySQL (Fixes #301)
    This changes the order of operations so that the schema cache is
    cleared after the alter table operations instead of before.  So if
    any code needs to check the existing schema inside the alter table
    operation, it won't cache a previous schema entry that is then
    invalid after the alter table call.
    committed May 21, 2010
Commits on May 20, 2010
  1. Remove == definitions from some SQL::Expression subclasses

    SQL::Expression itself now defines a method which should work,
    so there is no reason to override it in the subclasses.
    committed May 20, 2010
  2. Nicer error messages if you use a driver that the jdbc adapter doesn'…

    …t recognize and the connection fails
    committed May 20, 2010
  3. Fix leak of JDBC Statement objects when using transactions on JDBC on…

    … databases that support savepoints
    This actually does some significant refactoring.  Instead of dealing
    with a single statement object for the transaction, act like all
    the other adapters and use a connection object, with a new statement
    object created for every BEGIN/ROLLBACK/COMMIT.
    This removes the private transaction_statement_object from the
    JDBC adapter.
    committed May 20, 2010
Commits on May 19, 2010
Commits on May 18, 2010