Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Commits on Apr 21, 2010
Commits on Apr 17, 2010
Commits on Apr 15, 2010
Commits on Apr 9, 2010
  1. Add instance_filters plugin, for adding arbitrary filters when updati…

    …ng/destroying the instance
    This plugin is designed for cases where you would normally have to
    drop down to the dataset level to get the necessary control, because
    you only want to delete or update the rows in certain cases based on
    the current status of the row in the database.
Commits on Apr 8, 2010
  1. Remove sequel_cascading from the list of external plugins, since asso…

    …ciation_dependencies can fulfill its need
Commits on Mar 29, 2010
  1. Add an rcte_tree plugin, which uses recursive common table expression…

    …s for loading trees stored as adjacency lists
    See the plugin module's RDoc for details.
Commits on Mar 14, 2010
Commits on Mar 8, 2010
  1. Add composition plugin, simlar to ActiveRecord's composed_of

    The composition plugin allows you to easily define getter and setter
    instance methods for a class where the backing data is composed of
    other getters and decomposed to other setters.
    A simple example of this is when you have a database table with
    separate columns for year, month, and day, but where you want to deal
    with Date objects in your ruby code.  This can be handled with:
      Model.composition :date, :mapping=>[:year, :month, :day]
    The :mapping option is optional, but you can define custom
    composition and decomposition procs via the :composer and :decomposer
    Note that when using the composition object, you should not modify the
    underlying columns if you are also instantiating the composition, as
    otherwise the composition object values will override any underlying
    columns when the object is saved
Commits on Feb 15, 2010
Commits on Feb 7, 2010
Commits on Feb 5, 2010
Commits on Dec 15, 2009
Commits on Oct 28, 2009
Commits on Oct 19, 2009
  1. adding sequel version to documentation

    Daniel Bretoi authored
Commits on Sep 29, 2009
  1. Add class_table_inheritance plugin, supporting inheritance in the dat…

    …abase using a table-per-model-class approach
    The class_table_inheritance plugin allows you to model inheritance
    in the database using a table per model class in the hierarchy, with
    only columns unique to that model class (or subclass hierarchy) being
    stored in the related table.  For example, with this hierarchy:
                          /        \
                       Staff     Manager
    the following database schema may be used (table - columns):
    * employees - id, name, kind
    * staff - id, manager_id
    * managers - id, num_staff
    * executives - id, num_managers
    The class_table_inheritance plugin assumes that the main table
    (e.g. employees) has a primary key field (usually autoincrementing),
    and all other tables have a foreign key of the same name that points
    to the same key in their superclass's table.  For example:
    *  - primary key, autoincrementing
    * - foreign key referencing employees(id)
    * - foreign key referencing employees(id)
    * - foreign key referencing managers(id)
    When using the class_table_inheritance plugin, subclasses use joined
      Employee.dataset.sql  # SELECT * FROM employees
      Manager.dataset.sql   # SELECT * FROM employees
                            # INNER JOIN managers USING (id)
      Executive.dataset.sql # SELECT * FROM employees
                            # INNER JOIN managers USING (id)
                            # INNER JOIN executives USING (id)
    This allows Executive.all to return instances with all attributes
    loaded.  The plugin overrides the deleting, inserting, and updating
    in the model to work with multiple tables, by handling each table
    This plugin allows the use of a :key option when loading to mark
    a column holding a class name.  This allows methods on the
    superclass to return instances of specific subclasses.
    This plugin also requires the lazy_attributes plugin and uses it to
    return subclass specific attributes that would not be loaded
    when calling superclass methods (since those wouldn't join
    to the subclass tables).  For example:
      a = Employee.all # [<#Staff>, <#Manager>, <#Executive>]
      a.first.values # {:id=>1, name=>'S', :kind=>'Staff'}
      a.first.manager_id # Loads the manager_id attribute from the
                         # database
    This plugin is not supported on H2 or MSSQL, because neither
    support JOIN table USING (column).  H2 support is possible in
    the future using a NATURAL JOIN, and while MSSQL support is
    theoretically possible using a JOIN ON, the resulting model
    wouldn't be very usable because primary key lookups would
    need to be qualified, which Sequel doesn't do.
    Note that this plugin isn't fully functional on SQLite due to
    a bug I discovered in their JOIN USING implementation (see
Commits on Sep 21, 2009
  1. Add the forced_encoding plugin for forcing encoding of strings for mo…

    …dels (requires ruby 1.9)
    The ForceEncoding plugin allows you force specific encodings for all
    strings that are used by the model.  When model instances are loaded
    from the database, all values in the hash that are strings are
    forced to the given encoding.  Whenever you update a model column
    attribute, the resulting value is forced to a given encoding if the
    value is a string.  There are two ways to specify the encoding.  You
    can either do so in the plugin call itself, or via the
    forced_encoding class accessor:
      class Album < Sequel::Model
        plugin :force_encoding, 'UTF-8'
        # or
        plugin :force_encoding
        self.forced_encoding = 'UTF-8'
Commits on Sep 17, 2009
Commits on Sep 11, 2009
  1. Add touch plugin, which adds Model#touch for updating an instance's t…

    …imestamp, as well as touching associations when an instance is updated or destroyed
    The touch plugin adds a touch method to model instances, which saves
    the object with a modified timestamp.  By default, it uses the
    :updated_at column, but you can set which column to use.
    It also supports touching of associations, so that when the current
    model object is updated or destroyed, the associated rows in the
    database can have their modified timestamp updated to the current
    Since the instance touch method works on model instances,
    it uses for the timestamp.  The association touching works
    on datasets, so it updates all related rows in a single query, using
    the SQL standard CURRENT_TIMESTAMP.  Both of these can be overridden
    easily if necessary.
Commits on Sep 10, 2009
  1. Add sql_expr extension, which adds the sql_expr to all objects, givin…

    …g them easy access to Sequel's DSL
    The sql_expr extension adds the sql_expr method to every object, which
    returns an object that works nicely with Sequel's DSL.  This is
    best shown by example:
      1.sql_expr < :a     # 1 < a
      false.sql_expr & :a # FALSE AND a
      true.sql_expr | :a  # TRUE OR a
      ~nil.sql_expr       # NOT NULL
      "a".sql_expr + "b"  # 'a' || 'b'
    This isn't possible to do in Sequel by default.  I generally refrain
    from modifying the core classes unless necessary, which is why this
    is an extension instead of being included in Sequel itself.
    This extension also allows you to do:
      o =
      o.sql_expr < :a
    Of course, for this to work, you'll need to add your own extension
    which literalizes the object properly.  You'll need to modify
    Dataset#literal_other to recognize the object and literalize it
    I'm generally against parametized specs, but I did use them in a
    couple instances here, since the specs are small and the behavior
    is identical.
Commits on Sep 8, 2009
  1. Add association_dependencies plugin, for deleting, destroying, or nul…

    …lifying associated objects when destroying a model object
    The AssociationDependencies plugin allows you do easily set up before
    and/or after destroy hooks for destroying, deleting, or nullifying
    associated model objects.  The following association types support the
    following dependency actions:
    * :many_to_many - :nullify (removes all related entries in join table)
    * :many_to_one - :delete, :destroy
    * :one_to_many - :delete, :destroy, :nullify (sets foreign key to
      NULL for all associated objects)
    This plugin works directly with the association datasets and does not
    use any cached association values.  The :delete action will delete all
    associated objects from the database in a single SQL call.
    The :destroy action will load each associated object from the database
    and call the destroy method on it.
    To set up an association dependency, you must provide a hash with
    association name symbols and dependency action values.  You can
    provide the hash to the plugin call itself or to the
    add_association_dependencies method:
      Business.plugin :association_dependencies, :address=>delete
      # or:
      Artist.plugin :association_dependencies
      Artist.add_association_dependencies :albums=>:destroy, :reviews=>:delete, :tags=>:nullif
Commits on Sep 7, 2009
  1. Add subclasses plugin, for recording all of a models subclasses and d…

    …escendent classes
    The Subclasses plugin keeps track of all subclasses of the
    current model class.  Direct subclasses are available via the
    subclasses method, and all descendent classes are available via the
    descendents method.
      c =
      c.plugin :subclasses
      sc1 =
      sc2 =
      ssc1 =
      c.subclasses    # [sc1, sc2]
      sc1.subclasses  # [ssc1]
      sc2.subclasses  # []
      ssc1.subclasses # []
      c.descendents   # [sc1, ssc1, sc2]
  2. Add looser_typecasting extension, for using .to_f and .to_i instead o…

    …f Kernel.Float and Kernel.Integer when typecasting floats and integers
    The LooserTypecasting extension changes the float and integer typecasting to
    use the looser .to_f and .to_i instead of the more strict Kernel.Float and
    Kernel.Integer.  To use it, you should extend the database with the
    Sequel::LooserTypecasting module after loading the extension:
      Sequel.extension :looser_typecasting
Commits on Aug 31, 2009
Commits on Aug 27, 2009
Commits on Aug 26, 2009
  1. Add a nested_attributes plugin for modifying associated objects direc…

    …tly through a model object
    The nested_attributes plugin allows you to update attributes for
    associated objects directly through the parent object, similar to
    ActiveRecord's Nested Attributes feature.
    Nested attributes are created using the nested_attributes method:
      Artist.one_to_many :albums
      Artist.nested_attributes :albums
      a =>'YJM',
       :albums_attributes=>[{:name=>'RF'}, {:name=>'MO'}])
      # No database activity yet
  # Saves artist and both albums{|x|} # ['RF', 'MO']
    nested_attributes takes the following options:
    * :destroy - Allow destruction of nested records.
    * :limit - For *_to_many associations, a limit on the number of
      records that will be processed, to prevent denial of service
    * :remove - Allow disassociation of nested records (can remove the
      associated object from the parent object, but not destroy the
      associated object).
    * :strict - Set to false to not raise an error message if a primary
      key is provided in a record, but it doesn't match an existing
      associated object.
    If a block is provided, it is passed each nested attribute hash.  If
    the hash should be ignored, the block should return anything except
    false or nil.
    While hear, change the add_* method for many_to_many associations to
    save the passed associated object if that object is new.  I think this
    makes sense and is better than raising an error, since it now operates
    more similarly to a one_to_many association.
    To ease implementation, add a Model#modified? method.  This is called
    by save_changes, instead of assuming that the only possible object
    modifications are through the columns.
Commits on Aug 23, 2009
Commits on Aug 21, 2009
  1. Add a boolean_readers plugin for creating attribute? methods for bool…

    …ean columns
    The BooleaReaders plugin allows for the creation of attribute?
    methods for boolean columns, which provide a nicer API.  By default,
    the accessors are created for all columns of type :boolean.  However,
    you can provide a block to the plugin to change the criteria used to
    determine if a column is boolean:
      Sequel::Model.plugin(:boolean_readers) do |c|
        db_schema[c][:db_type] =~ /\Atinyint/
    This may be useful if you are using MySQL and have some tinyint
    columns that represent booleans and others that represent integers.
    You can turn the convert_tinyint_to_bool setting off and use the
    attribute methods for the integer value and the attribute? methods
    for the boolean value.
Commits on Aug 20, 2009
Commits on Aug 13, 2009
Commits on Aug 4, 2009
  1. Add a timestamps plugin for automatically creating hooks for create a…

    …nd update timestamps
    I was planning on merging one of the existing timestamping plugins,
    but I couldn't find an existing implementation that I liked.  So I
    wrote this myself.  It's more configurable than the other plugins,
    and it's written in modern Sequel plugin style (using instance
    level hooks with super).
    The following options are supported (default):
    * :create - The field to hold the create timestamp (:created_at)
    * :force - Whether to overwrite an existing create timestamp (false)
    * :update - The field to hold the update timestamp (:updated_at)
    * :update_on_create - Whether to set the update timestamp to the
      create timestamp when creating (false)
Commits on Aug 3, 2009
Commits on Jul 28, 2009
Something went wrong with that request. Please try again.