Permalink
Commits on Sep 3, 2008
  1. Bump version to 2.5.0

    committed Sep 3, 2008
Commits on Sep 2, 2008
Commits on Aug 28, 2008
  1. Add Dataset #set_defaults and #set_overrides, used for scoping the va…

    …lues used in insert/update statements
    
    Sequel has long been known for its chainable filters.  Before this
    commit, it was not possible to chain the values used in insert or
    update statements.  This commit adds two methods, with slightly
    different features, to accomplish this.
    
    set_defaults is used to set the default values used in insert or
    update statements, which can be overriden by the values passed to
    insert or update:
    
      DB[:t].set_defaults(:x=>1).insert_sql
      # => INSERT INTO t (x) VALUES (1)
      DB[:t].set_defaults(:x=>1).insert_sql(:x=>2)
      # => INSERT INTO t (x) VALUES (2)
      DB[:t].set_defaults(:x=>1).insert_sql(:y=>2)
      # => INSERT INTO t (x, y) VALUES (1, 2)
    
    set_overrides is used to set default values that override the values
    given to insert or update statements:
    
      DB[:t].set_overrides(:x=>1).insert_sql(:x=>2)
      # => INSERT INTO t (x) VALUES (1)
    
    In addition, chaining calls to set_default and set_overrides operate
    slightly differently:
    
      DB[:t].set_defaults(:x=>1).set_defaults(:x=>2).insert_sql
      # => INSERT INTO t (x) VALUES (2)
      DB[:t].set_overrides(:x=>1).set_overrides(:x=>2).insert_sql
      # => INSERT INTO t (x) VALUES (1)
    
    As show above, with set_default, the last call takes precedence,
    whereas with set_overrides, the first call takes precedence.
    
    Note that set_defaults and set_overrides only are used when insert or
    update is called with a hash.
    
    Dataset#insert had to go through some significant refactoring for this
    to work.  All the specs still pass, so hopefully nothing broke because
    of it.
    committed Aug 28, 2008
  2. Allow Models to use the RETURNING clause when inserting records on Po…

    …stgreSQL
    
    This commit makes model.save! check for an insert_select method on
    the dataset.  If it exists, it calls that method and uses the result
    as the values, instead of inserting and then reloading the values
    from the database. This should be faster as well as less error prone.
    
    It changes a recent commit to the PostgreSQL adapter so that
    insert_sql does not use the RETURNING clause by default. You need to
    call the insert_returning_sql method if you want the RETURNING
    clause.  That is what Dataset#insert now does on PostgreSQL servers
    8.2 and higher.  This caused some issues with prepared statements,
    but this commit takes care of that as well.
    
    This commit also contains a small speedup to Dataset#single_value,
    as well as a missing spec for Database#raise_error.
    committed Aug 28, 2008
Commits on Aug 27, 2008
  1. Raise Sequel::DatabaseError instead of generic Sequel::Error for data…

    …base errors, don't swallow tracebacks
    
    This commit adds a new exception class, Sequel::DatabaseError.  This
    exception class should be used for all errors that come from the
    database, such as invalid syntax in a query or database access rights
    violation.
    
    This commit adds a couple private Database methods, raise_error and
    transaction_error.  raise_error converts the exception to a
    DatabaseError, keeping the previous exception message (prepended
    with the previous exception class) as well as the traceback.  If
    an optional :classes option is passed, it only converts the exception
    if it is one of those classes.  transaction_error calls raise_error
    with the :classes options set to the array of passed classes, unless
    the error is an Error::Rollback.  These DRY up some code in the
    adapters.
    
    This commit also removes the convert_pgerror method for the postgres
    adapter, since it is no longer necessary.
    
    This is a backwards incompatible change for SQLite users, since the
    SQLite adapter previously raised Error::InvalidStatement instead of
    just Error.
    committed Aug 27, 2008
  2. Use INSERT ... RETURNING ... with PostgreSQL 8.2 and higher

    This makes the PostgreSQL adapter use INSERT ... RETURNING ... if it
    is connected to an 8.2.0 or later server.  This should provide a
    performance boost, as it doesn't require extra queries being issued
    to determine the value of the inserted primary key.
    
    This also makes the Database object clear the cache for @primary_keys
    and @primary_key_sequences when drop_table is called.  It adds a
    Database#primary_key public method for determining the primary key
    for a given table. If also adds a Dataset#server_version private
    method to make things more testable.
    committed Aug 27, 2008
  3. Document general but adapter specific return values for fetch_rows, d…

    …elete, insert, and update
    committed Aug 27, 2008
  4. Make insert_sql, delete_sql, and update_sql respect the :sql option

    Before this commit, all of the following would raise errors:
    
      DB["INSERT INTO blah (id) VALUES (1)"].insert_sql
      DB["DELETE FROM blah"].delete_sql
      DB["UPDATE blah SET num = 1"].update_sql
    
    Now, these just return the SQL given.  This implies:
    
      ds = DB["..."]
      ds.update_sql.should == ds.delete_sql
    committed Aug 27, 2008
  5. Default to converting 2 digit years

    Before, Sequel would treat 06/07/08 as being in the year 0008 instead
    of 2008, at least when using the Date and DateTime classes.  This
    commit changes that so that 2 digit years are treated as year + 1900
    if year >= 69 or year + 2000 if year < 69.  To get back the old
    behavior:
    
      Sequel.convert_two_digit_years = false
    
    If you are using ruby 1.9, you should watch out, as the date parsing
    differs from ruby 1.8:
    
      Date.parse('01/02/08', true).to_s # ruby 1.8 => "2008-01-02"
      Date.parse('01/02/08', true).to_s # ruby 1.9 => "2001-02-08"
    committed Aug 27, 2008
Commits on Aug 26, 2008
  1. Make the PostgreSQL adapter with the pg driver use async_exec, so it …

    …doesn't block the entire interpreter
    committed Aug 26, 2008
Commits on Aug 24, 2008
Commits on Aug 22, 2008
  1. Added support for composite primary key, composite foreign key and un…

    …ique constraints to Schema::Generator and Schema::AlterTableGenerator
    jarredholman committed Aug 22, 2008
Commits on Aug 20, 2008
Commits on Aug 19, 2008
  1. Disallow abuse of SQL function syntax for types (use :type=>:varchar,…

    … :size=>255 instead of :type=>:varchar[255])
    
    This commit also refactors type_literal to return the entire literal
    value for the type, instead of just the base type (so it includes
    any length and/or UNSIGNED specifiers).  It also makes type_literal
    private.
    
    In addition, this fixes an issue with renaming or changing the type
    of a varchar column on MySQL, if you wanted the size to be different
    than 255.
    committed Aug 19, 2008
Commits on Aug 18, 2008
  1. Quote index names when creating or dropping indexes

    This also refactors some schema creation methods.  It quotes tables
    and columns as well as indexes in the schema creation methods that
    the MySQL adapter overrides.  It adds a couple new methods,
    drop_index_sql and column_references_sql, which eliminates some
    duplication in the MySQL adapter.
    committed Aug 18, 2008
Commits on Aug 16, 2008
Commits on Aug 13, 2008
  1. Don't have column accessor methods override plugin instance methods

    This commit changes where the column accessor methods are defined.
    Instead of defining them directly in the class, this defines them in
    an anonymous module that is included in the class.  Because columns
    accessors are generally defined when the class is created (before
    the plugin has been added), the plugin instance methods module will
    be included after the column accessor module, so it will take
    precedence.  Because the column accessor methods don't override
    existing instance methods, if a plugin has already been added, using
    set_dataset after a plugin has been added (e.g. in a subclass) won't
    create column accessors that override the plugin's instance methods.
    
    This commit should also have a minor speedup in the general case, by
    recognizing when a dataset is inherited and omitting some redundent
    code in that case.
    
    While here, simplify the code for Sequel::Model().
    committed Aug 13, 2008
  2. Allow validation of multiple attributes at once, with built in suppor…

    …t for uniqueness checking of multiple columns
    
    This commit allows you to support validating multiple attributes at
    once:
    
      validates_each([:column1, :column2]) do |obj, attributes, values|
        # attributes = [:column1, :column2]
        # values = [obj.send(:column1), obj.send(:column2)]
      end
    
    Support was added to validates_uniqueness_of to work on multiple
    values at once:
    
      validates_uniqueness_of([:column1, :column2])
    
    This is quite different from the following code:
    
      validates_uniqueness_of(:column1, :column2)
    
    Which makes sure the each value is unique to its column, instead of
    the combination of values being unique.
    
    This will give a validation error message if an entry already exists
    in the database that has the same value for column1 and column2.  It
    works for any number of columns.
    
    validates_uniqueness_of now supports an :allow_nil option that will
    skip checking if the values of all columns are nil.  Previously, it
    automatically skipped the validation if the value was blank.
    
    There was also a slight memory reduction by reusing the default proc
    if :if is not specified.
    committed Aug 13, 2008
Commits on Aug 12, 2008
  1. In PostgreSQL adapter, fix inserting a row with a primary key value i…

    …nside a transaction
    
    This bug took quite a while to find and fix.  It was compounded by
    the fact that there were multiple bugs in the underlying
    implementation:
    
    1) Errors raised by PostgreSQL weren't getting reraised inside
       insert_result.
    
    2) Determining the sequence names was not done correctly.
    
    This caused weird errors, such as the code raising an error stating
    there was already an error on the transaction, without showing
    an error or even that a query was issued.  To fix this and similar
    issues, have the connection log the SQL it issues to find primary
    keys, sequences, and sequence values, just like the Database object
    logs the SQL.
    
    To make sure that inserting a row with a primary key value works
    inside transactions, figure out the primary key first and see if
    it contained in the values hash.  If not, figure out what the
    sequence is for the table, and get the last sequence value used.
    
    This is done because trying to get the last sequence value first
    if the sequence wasn't yet used on the connection causes PostgreSQL
    to abort the transaction.  It would return an invalid result
    instead of aborting the transaction if the connection had previously
    been used to insert a row into the same table, without an easy way
    to detect things.
    
    Fix the SQL used for finding primary keys and sequences so that
    unnecessary columns aren't returned.
    
    Keep track of sequences at the Database level instead of the
    connection level.
    
    Make insert_result, primary_key_for_table, and
    primary_key_sequence_for_table private methods.
    
    The :table option when inserting is now unquoted (generally a symbol),
    instead of the quoted string used previously.
    committed Aug 12, 2008
Commits on Aug 11, 2008
  1. Allow :join_table association option to have a string value

    Before, using a string value would result in very weird error
    messages, because of the implementation of the many_to_many
    add_/remove_/remove_all_ methods.  Have those methods use
    database.dataset.from(join_table) instead of
    database[join_table], which should work.  The documentation will
    remain the same, and I don't guarantee that using a string will work
    in future versions.  The main reason for this commit is so if you do
    use a string, you won't get an error message that doesn't make sense.
    committed Aug 11, 2008
Commits on Aug 7, 2008
Commits on Aug 6, 2008
  1. Make Dataset#single_value work when graphing, which fixes count and p…

    …aginate on graphed datasets
    committed Aug 6, 2008
  2. Bump version to 2.4.0

    committed Aug 6, 2008
Commits on Aug 5, 2008